Skip to content

Commit

Permalink
validate maxProcs actually exercises all child pids
Browse files Browse the repository at this point in the history
  • Loading branch information
mceachen committed Mar 11, 2019
1 parent 097d75a commit a0ffd6a
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 4 deletions.
41 changes: 40 additions & 1 deletion src/BatchCluster.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { delay } from "./Async"
import { BatchCluster } from "./BatchCluster"
import { BatchClusterOptions } from "./BatchClusterOptions"
import { logger } from "./Logger"
import { map } from "./Object"
import { map, orElse } from "./Object"
import { toS } from "./String"
import { Task } from "./Task"

Expand Down Expand Up @@ -321,6 +321,45 @@ describe("BatchCluster", function() {
)
)

describe("maxProcs", function() {
this.timeout(10000)
let bc: BatchCluster
afterEach(() => bc.end())
it("runs tasks in parallel", async () => {
setFailrate(0)
const maxProcs = 10
const iters = 30
const opts = {
...defaultOpts,
taskTimeoutMillis: 1000,
maxProcs,
processFactory
}
bc = listen(new BatchCluster(opts))
const tasks = await Promise.all(
times(iters, async i => {
const start = Date.now()
const task = new Task("sleep 250", parser)
const result = JSON.parse(await bc.enqueueTask(task))
const end = Date.now()
return { i, start, end, ...result }
})
)
const pid2count = new Map<number, number>()
tasks.forEach(ea => {
const pid = ea.pid
const count = orElse(pid2count.get(pid), 0)
pid2count.set(pid, count + 1)
})
console.log(pid2count)
expect(pid2count.size).to.eql(maxProcs)
for(const [, count] of pid2count.entries()) {
expect(count).to.be.within(2, (iters/maxProcs) + 2)
}
expect(pid2count.size).to.eql(maxProcs)
})
})

describe("maxProcAgeMillis", function() {
this.timeout(10000)

Expand Down
2 changes: 1 addition & 1 deletion src/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ async function onLine(line: string): Promise<void> {
case "sleep":
const millis = parseInt(tokens[0])
await delay(millis)
write("slept " + millis)
write(JSON.stringify({ slept: millis, pid: _p.pid }))
write("PASS")
break

Expand Down
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"compilerOptions": {
/* Basic Options */
"target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', or 'ESNEXT'. */
"target": "es2016", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'commonjs', 'amd', 'system', 'umd' or 'es2015'. */
"lib": [ "es2015" ], /* Specify library files to be included in the compilation: */
"lib": [ "es2016" ], /* Specify library files to be included in the compilation: */
"skipLibCheck": true,
// "allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */
Expand Down

0 comments on commit a0ffd6a

Please sign in to comment.