Socket
Socket
Sign inDemoInstall

logiload

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

logiload - npm Package Compare versions

Comparing version 0.0.3 to 0.0.4

1

bin/run.js

@@ -45,3 +45,4 @@ #!/usr/bin/env node

log[ e ? "error" : "info" ]("Complete in [%ss], with ", (Date.now() - starttime ) / 1000, e || "SUCCESS");
log.info("stats:\n", macro.stats);
if (macro.stats.errored) log.warn("Counted total of [%s] errors", macro.stats.errored);
})

@@ -55,2 +55,6 @@ var path = require('path')

}
, bail :
{ describe : "breaks execution on first error of first agent"
, type : "boolean"
}
}

@@ -57,0 +61,0 @@ ).epilog(

8

lib/runner.js

@@ -91,3 +91,3 @@ var async = require('async')

, errored : "Err in sample" //macro.sample.errored
, resTime : "Req dur" //macro.sample.avg
, resTime : "Req dur" //macro.stats.avg
, users_conc : "conc. users" //macro.stats.expected ==>> macro.stats.started - macro.stats.finished

@@ -124,6 +124,5 @@ , reqcount : "conc. requests" //macro.stats.fired - macro.stats.returned

csvReq.write( rslt );
if (rslt.error) {
log.error("error", rslt);
//TODO - bail on unexpected errors
//OR - just count
macro.sample.errored++;

@@ -133,3 +132,2 @@ macro.stats.errored++;

csvReq.write( rslt );
}

@@ -136,0 +134,0 @@

@@ -13,4 +13,6 @@ var LOG = require('log4js').getLogger('lib/steps/req')

, macro = ctx.macro
, request = ctx.request || REQUEST
, log = ctx.log || LOG
, aid = agent.id

@@ -31,2 +33,3 @@ , rid = 1

var reqStats = reqInfo.stats
, rid = reqInfo.id
, url = parameterize(agent.params, reqInfo.get).replace(/,/g,"%2C")

@@ -43,3 +46,3 @@ , rslt =

log.info("[a#%s] - firing: ", aid, url );
log.info("[a#%s/r#%s] - firing: ", aid, rid, url );

@@ -50,10 +53,13 @@ request(

, headers:
{ "user-agent" : "stress tester"
//TODO - let user-code pass headers
{ "user-agent" : "logiload stress tester"
}
}
, function(e,r) {
rslt.endtime = Date.now();
var dur = rslt.dur = rslt.endtime - rslt.starttime
, rej
var dur =
rslt.dur =
(rslt.endtime = Date.now()) - rslt.starttime
, expectedCode
;
log.debug("[a#%s/r#%s] - response arrived in [%sms]", aid, reqInfo.id, rslt.dur)

@@ -64,45 +70,54 @@ reqStats.gather(dur);

if (e) {
log.warn("request errored", e.message, reqInfo);
rslt.error = e.message;
rslt.statusCode = null;
}else{
} else {
rslt.error = false;
rslt.statusCode = r.statusCode;
//TODO: allow hook for applicative errors
}
if ( reqInfo.expect && reqInfo.expect.code
&& r.statusCode != reqInfo.expectCode
) {
expectedCode = reqInfo.expect && reqInfo.expect.code || 200 ;
if (r && r.statusCode != expectedCode) {
e =
{ message: "Wrong Status Code"
, expect : reqInfo.expect.code
{ message: "Unexpected HTTP Response-Code"
, expect : expectedCode
, found : r.statusCode
}
}
//hook for user-code, which may:
// - extract state from response body to be used in next steps
// - set error from applicative level
if ('function' == typeof reqInfo.onResponse) {
log.debug("[a#%s/r#%s] - runnig onResponse hook:", aid, rid, e ? e.message : "successfull request");
log.info("[a#%s] - response [r#%s] arrived in [%sms] - ", aid, reqInfo.id, rslt.dur, e || r.statusCode);
log.info("req stats [r#%s]: %s", reqInfo.id, reqStats);
//exception safety + gather error when caught exception
log.debug("[a#%s/r#%s] - with", aid, rid, r ? r.body || "no body" : e);
if ('function' == typeof reqInfo.onResponse) {
log.info("[a#%s] - runnig onResponse hook:", aid, e ? e.message : "successfull request");
//TODO - exception safety + gather error when caught exception
//TODO - move to event emittion
log.debug("[a#%s] - with", r ? r.body || "no body" : e);
try {
//TODO - move to event emittion??
reqInfo.onResponse.apply(ctx, [e, r, rslt]);
} catch (ex) {
e = ex;
e.reqInfo = reqInfo;
}
if (rslt.error && !e)
e = { message: "Custom Assertion failed" };
if (e) {
e.reqUrl = url;
e.responseBody = (r || e).body;
e.httpCode = (r || e).statusCode;
log.error("req.onResponse",e);
e.rslt = rslt
e.reqInfo = reqInfo;
}
}
//TODO - move to event emittion?
macro.onResult( rslt );
if (e)
log[reqInfo.bail ? "error" : "warn" ]("[a#%s/r#%s] - request errored:\n", aid, rid, e );
log.debug("[a#%s/r#%s] - request done\nresult : %j\nreqStats : %j", aid, rid, rslt, reqStats);
next(reqInfo.bail ? e : null);

@@ -115,6 +130,3 @@ }

, function(e) {
if (!e) {
log.info("[a#%s] - exiting step: %s", aid, step.name);
log.info("step stats [%s] : %s", step.name, step.stats);
}
log.debug("[a#%s] - exiting step: %s\n%j", aid, step.name, step.stats, e || "OK");
done(e)

@@ -121,0 +133,0 @@ }

@@ -12,12 +12,17 @@ var LOG = require('log4js').getLogger('lib/steps/wait')

, aid = agent.id
, sleep = (step.wait || step.sleep) * rnd()
, sleep = step.wait || step.sleep
, sleepRnd
;
log.info("[a#%s] - sleeping %ss", aid, step.wait || step.sleep);
if ('function' == typeof sleep) sleep = sleep();
sleepRnd *= rnd();
log.info("[a#%s] - sleeping %ss", aid, sleep);
setTimeout( function() {
log.debug("[a#%s] - woke up!", aid);
done()
}, sleep * 1000 );
}, sleepRnd * 1000 );
}
function rnd() { return (Math.random() + Math.random() + Math.random()) / 1.5 }
{
"name": "logiload",
"version": "0.0.3",
"version": "0.0.4",
"description": "",

@@ -5,0 +5,0 @@ "main": "lib",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc