Skip to content

Commit

Permalink
Chore: try to improve tests for --race
Browse files Browse the repository at this point in the history
  • Loading branch information
mysticatea committed Jul 23, 2016
1 parent 0c22372 commit 2e5663a
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 14 deletions.
1 change: 1 addition & 0 deletions test-workspace/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"test-task:append:b": "node tasks/append2.js b",
"test-task:append1": "node tasks/append1.js",
"test-task:append2": "node tasks/append2.js",
"test-task:append2wa": "node tasks/append2-wa.js",
"test-task:error": "node tasks/error.js",
"test-task:stdout": "node tasks/stdout.js > test.txt",
"test-task:stderr": "node tasks/stderr.js 2> test.txt",
Expand Down
1 change: 1 addition & 0 deletions test-workspace/tasks/append1.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
var appendResult = require("./lib/util").appendResult

appendResult(process.argv[2])
process.exit(0)
17 changes: 17 additions & 0 deletions test-workspace/tasks/append2-wa.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"use strict"

var util = require("./lib/util")

util.appendResult(process.argv[2])
setTimeout(function() {
util.appendResult(process.argv[2])
process.exit(0)
}, 10000)

// SIGINT/SIGTERM Handling.
process.on("SIGINT", function() {
process.exit(0)
})
process.on("SIGTERM", function() {
process.exit(0)
})
13 changes: 4 additions & 9 deletions test-workspace/tasks/append2.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,11 @@

var appendResult = require("./lib/util").appendResult

/**
* Append a given text into `test.txt`.
* @returns {void}
*/
function append() {
appendResult(process.argv[2])
setTimeout(function() {
appendResult(process.argv[2])
}

append()
setTimeout(append, 3000)
process.exit(0)
}, 3000)

// SIGINT/SIGTERM Handling.
process.on("SIGINT", function() {
Expand Down
17 changes: 12 additions & 5 deletions test/parallel.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,38 +262,45 @@ describe("[parallel]", () => {

describe("should abort other tasks when a task finished, when --race option was specified:", () => {
it("Node API", () =>
nodeApi(["test-task:append1 a", "test-task:append2 b"], {parallel: true, race: true})
nodeApi(["test-task:append1 a", "test-task:append2wa b"], {parallel: true, race: true})
.then(() => {
assert(result() === "a" || result() === "ab" || result() === "ba")
})
)

it("npm-run-all command (--race)", () =>
runAll(["--race", "--parallel", "test-task:append1 a", "test-task:append2 b"])
runAll(["--race", "--parallel", "test-task:append1 a", "test-task:append2wa b"])
.then(() => {
assert(result() === "a" || result() === "ab" || result() === "ba")
})
)

it("npm-run-all command (-r)", () =>
runAll(["-rp", "test-task:append1 a", "test-task:append2 b"])
runAll(["-rp", "test-task:append1 a", "test-task:append2wa b"])
.then(() => {
assert(result() === "a" || result() === "ab" || result() === "ba")
})
)

it("run-p command (--race)", () =>
runPar(["--race", "test-task:append1 a", "test-task:append2 b"])
runPar(["--race", "test-task:append1 a", "test-task:append2wa b"])
.then(() => {
assert(result() === "a" || result() === "ab" || result() === "ba")
})
)

it("run-p command (-r)", () =>
runPar(["-r", "test-task:append1 a", "test-task:append2 b"])
runPar(["-r", "test-task:append1 a", "test-task:append2wa b"])
.then(() => {
assert(result() === "a" || result() === "ab" || result() === "ba")
})
)

it("run-p command (no -r)", () =>
runPar(["test-task:append1 a", "test-task:append2wa b"])
.then(() => {
assert(result() === "abb" || result() === "bab")
})
)
})
})

0 comments on commit 2e5663a

Please sign in to comment.