Skip to content

Commit

Permalink
allow for 1 stray pid on shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
mceachen committed Mar 2, 2022
1 parent 204bd1a commit 7222f1a
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions src/BatchCluster.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {
setFailratePct,
setIgnoreExit,
setNewline,
sortNumeric,
testPids,
times,
unhandledRejections,
Expand All @@ -28,6 +27,23 @@ import {
const isCI = process.env.CI === "1"
const tk = require("timekeeper")

function arrayEqualish<T>(a: T[], b: T[], maxAcceptableDiffs: number) {
const common = a.filter((ea) => b.includes(ea))
const minLength = Math.min(a.length, b.length)
if (common.length < minLength - maxAcceptableDiffs) {
expect(a).to.eql(
b,
"too many diffs: " +
JSON.stringify({
actualDiffs: minLength - maxAcceptableDiffs,
maxAcceptableDiffs,
minLength,
common_length: common.length,
})
)
}
}

describe("BatchCluster", function () {
const ErrorPrefix = "ERROR: "

Expand Down Expand Up @@ -379,10 +395,12 @@ describe("BatchCluster", function () {
maxProcs,
(iterations + maxProcs) * 3 // because flaky
)
const pids = sortNumeric(testPids())
const pids = testPids()
expect(pids.length).to.be.gte(maxProcs)
expect(sortNumeric(events.startedPids)).to.eql(pids)
expect(sortNumeric(events.exitedPids)).to.eql(pids)
// it's ok to miss a pid due to startup flakiness or cancelled
// end tasks.
arrayEqualish(events.startedPids, pids, 1)
arrayEqualish(events.exitedPids, pids, 1)
expect(events.events).to.eql(expectedEndEvents)
postAssertions()
})
Expand Down

0 comments on commit 7222f1a

Please sign in to comment.