Skip to content

Instantly share code, notes, and snippets.

@hassy
Last active January 9, 2016 13:16
Show Gist options
  • Save hassy/d5e3c9bb4ed151166abe to your computer and use it in GitHub Desktop.
Save hassy/d5e3c9bb4ed151166abe to your computer and use it in GitHub Desktop.
Example for using minigun-core
var minigun = require('minigun-core').runner;
var script = require('./my-test-script.json');
var ee = minigun(script);
ee.on('phaseStarted', function(spec) {}); // fired when a phase begins; spec is the phase definition (from the script)
ee.on('phaseCompleted', function(spec) {}); // fired when a phase completes; spec is as above
ee.on('stats', function(stats) {}); // fired every 10s; stats is a JSON object with stats for the previous 10s
ee.on('done', function(report) {}); // fired when the test completes, report is a JSON object with all stats
ee.run();
@mark-r-m
Copy link

mark-r-m commented Jan 8, 2016

Very useful, thanks!

@mark-r-m
Copy link

mark-r-m commented Jan 8, 2016

Do the phaseStarted and phaseCompleted events tell me which phase?

@hassy
Copy link
Author

hassy commented Jan 8, 2016

@mark-r-m - yes, I've updated the gist.

@mark-r-m
Copy link

mark-r-m commented Jan 8, 2016

Super. I'm having trouble running that in a docker container -

Get into my container

Boot2Docker version 1.9.0, build master : 16e4a2a - Tue Nov 3 19:49:22 UTC 2015 Docker version 1.9.0, build 76d6bc9
`docker@CitizenId:~$ docker exec -it cip-stub-gds-handler /bin/bash

Execute the script

root@cip-stub-gds-handler:/src# node self-test/minigun-stub-gds-handler-system-status.js /src/node_modules/minigun/node_modules/minigun-core/lib/runner.js:3
const EventEmitter = require('events').EventEmitter; ^^^^^
SyntaxError: Use of const in strict mode. at Module._compile (module.js:439:25)
at Object.Module._extensions..js (module.js:474:10) at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12) at Module.require (module.js:364:17)
at require (module.js:380:17) at Object. (/src/node_modules/minigun/node_modules/minigun-core/index.js:1:80)
at Module._compile (module.js:456:26) at Object.Module._extensions..js (module.js:474:10)
`at Module.load (module.js:356:32)```

Run the script

`root@cip-stub-gds-handler:/src# cat self-test/minigun-stub-gds-handler-system-status.js

Here's the script I'm running

var minigun = require('/src/node_modules/minigun/node_modules/minigun-core').runner; var script = require('/src/self-test/data/minigun-stub-gds-handler-system-status.json');
var ee = minigun(script);
// fired when a phase begins ee.on('phaseStarted', function() {
console.log('--phase started--'); });
// fired when a phase completes
ee.on('phaseCompleted', function() { console.log('--phase completed--');
});
// fired every 10s; stats is a JSON object with stats for the previous 10s ee.on('stats', function(stats) {
console.log('--stats--'); console.dir(stats);
});
// fired when the test completes, report is a JSON object with all stats ee.on('done', function(report) {
console.log('--complete--'); console.dir(report);
});
`ee.run();

@hassy
Copy link
Author

hassy commented Jan 8, 2016

Is this Node 4 or 5? Minigun requires Node 4 or greater.

@hassy
Copy link
Author

hassy commented Jan 9, 2016

@mark-r-m if you have any more questions, feel free to ping me on https://gitter.im/shoreditch-ops/minigun

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment