Skip to content
Browse files

failing test for spinning up multiple background processes

  • Loading branch information...
1 parent f7e5c87 commit c0726e18feabdf2b17c69f865caebcb607d15df5 @substack committed
Showing with 42 additions and 2 deletions.
  1. +1 −1 example/sh.js
  2. +41 −1 test/jobs.js
View
2 example/sh.js
@@ -11,7 +11,7 @@ var sh = bash({
});
sh.on('done', function (index, job) {
console.log(
- '[' + index + '] '
+ '[' + index + '] Done '
+ job.command + ' '
+ job.arguments.join(' ')
);
View
42 test/jobs.js
@@ -3,7 +3,7 @@ var bash = require('../');
var through = require('through');
var concat = require('concat-stream');
-test('jobs', function (t) {
+test('1 job', function (t) {
t.plan(1);
var sh = bash({ spawn: run, env: { 'PS1': '' } });
@@ -16,6 +16,22 @@ test('jobs', function (t) {
s.end();
});
+test('3 jobs', function (t) {
+ t.plan(1);
+
+ var sh = bash({ spawn: run, env: { 'PS1': '' } });
+
+ var s = sh.createStream();
+ s.pipe(concat(function (src) {
+ t.equal(src + '', '[0] one\n[1] two\n[2] three\nTHREE!\nTWO!\nONE!\n');
+ }));
+ s.write('one &\n');
+ s.write('two &\n');
+ s.write('three &\n');
+ s.write('jobs\n');
+ s.end();
+});
+
function run (cmd, args) {
if (cmd === 'beep') {
var tr = through();
@@ -25,4 +41,28 @@ function run (cmd, args) {
}, 100);
return tr;
}
+ else if (cmd === 'one') {
+ var tr = through();
+ setTimeout(function () {
+ tr.queue('ONE!\n');
+ tr.queue(null);
+ }, 300);
+ return tr;
+ }
+ else if (cmd === 'two') {
+ var tr = through();
+ setTimeout(function () {
+ tr.queue('TWO!\n');
+ tr.queue(null);
+ }, 200);
+ return tr;
+ }
+ else if (cmd === 'three') {
+ var tr = through();
+ setTimeout(function () {
+ tr.queue('THREE!\n');
+ tr.queue(null);
+ }, 100);
+ return tr;
+ }
}

0 comments on commit c0726e1

Please sign in to comment.
Something went wrong with that request. Please try again.