Skip to content

Commit

Permalink
Allow runners to specify spawn options
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Oct 14, 2019
1 parent b5f5221 commit 08496ab
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 21 deletions.
6 changes: 4 additions & 2 deletions src/debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ const runIteration = async function({
taskPath,
taskId,
variationId,
commandValue,
commandSpawn,
commandSpawnOptions,
commandOpt,
opts: { cwd },
}) {
Expand All @@ -33,7 +34,8 @@ const runIteration = async function({
}

await executeChild({
commandValue,
commandSpawn,
commandSpawnOptions,
input,
cwd,
taskId,
Expand Down
11 changes: 7 additions & 4 deletions src/iterations/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { validateIds } from './validate.js'
export const getCommandIterations = async function({
taskPath,
command,
command: { commandValue, commandOpt },
command: { commandSpawn, commandSpawnOptions, commandOpt },
duration,
cwd,
debug,
Expand All @@ -17,7 +17,8 @@ export const getCommandIterations = async function({
const input = { type: 'load', taskPath, opts: commandOpt }
const type = debug ? 'loadDebug' : 'run'
const { iterations } = await executeChild({
commandValue,
commandSpawn,
commandSpawnOptions,
input,
duration,
cwd,
Expand Down Expand Up @@ -46,7 +47,8 @@ const normalizeIteration = function(
commandId,
commandTitle,
commandDescription,
commandValue,
commandSpawn,
commandSpawnOptions,
commandOpt,
},
{ taskPath, system: { id: systemId, title: systemTitle } },
Expand All @@ -65,7 +67,8 @@ const normalizeIteration = function(
commandId,
commandTitle,
commandDescription,
commandValue,
commandSpawn,
commandSpawnOptions,
commandOpt,
systemId,
systemTitle,
Expand Down
23 changes: 19 additions & 4 deletions src/processes/execute.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import { forwardChildError } from './error.js'
// - whether `run` or `debug` is used
// - whether this is the initial load
export const executeChild = async function({
commandValue: [file, ...args],
commandSpawn: [file, ...args],
commandSpawnOptions,
input,
input: { taskPath },
duration,
Expand All @@ -27,7 +28,12 @@ export const executeChild = async function({

const { stdio, outputFd, errorFds } = FDS[type]

const spawnOptions = getSpawnOptions({ stdio, cwd, duration })
const spawnOptions = getSpawnOptions({
stdio,
cwd,
duration,
commandSpawnOptions,
})
const child = execa(file, [...args, inputA], spawnOptions)

// Wait for child process successful exit, failed exit, spawning error,
Expand Down Expand Up @@ -61,14 +67,23 @@ export const executeChild = async function({
return outputA
}

const getSpawnOptions = function({ stdio, cwd, duration }) {
// Commands cannot override the spawn options we set with one exception:
// `preferLocal` since that option can create issues with some runners, such as
// `node` runner `versions` option.
const getSpawnOptions = function({
stdio,
cwd,
duration,
commandSpawnOptions,
}) {
const timeout = getTimeout(duration)
return {
preferLocal: true,
...commandSpawnOptions,
stdio,
cwd,
timeout,
buffer: false,
reject: false,
preferLocal: true,
}
}
7 changes: 5 additions & 2 deletions src/processes/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { getStats } from '../stats/compute.js'
import { runChildren } from './run.js'

// Start several child processes benchmarking the same task.
// eslint-disable-next-line max-lines-per-function
export const runProcesses = async function({
name,
columnName,
Expand All @@ -17,7 +18,8 @@ export const runProcesses = async function({
commandId,
commandTitle,
commandDescription,
commandValue,
commandSpawn,
commandSpawnOptions,
commandOpt,
systemId,
systemTitle,
Expand All @@ -34,7 +36,8 @@ export const runProcesses = async function({
taskPath,
taskId,
variationId,
commandValue,
commandSpawn,
commandSpawnOptions,
commandOpt,
duration,
runEnd,
Expand Down
6 changes: 4 additions & 2 deletions src/processes/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ export const runChildren = async function({
taskPath,
taskId,
variationId,
commandValue,
commandSpawn,
commandSpawnOptions,
commandOpt,
duration,
runEnd,
Expand All @@ -43,7 +44,8 @@ export const runChildren = async function({
do {
// eslint-disable-next-line no-await-in-loop
const { times, count } = await executeChild({
commandValue,
commandSpawn,
commandSpawnOptions,
input,
duration,
cwd,
Expand Down
19 changes: 15 additions & 4 deletions src/run/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,17 @@ export const getCommands = function({
commands,
}) {
return Promise.all(
commands.map(({ id, title, value, versions }) =>
getCommand({ runnerId, runnerTitle, runOpt, id, title, value, versions }),
commands.map(({ id, title, spawn, spawnOptions, versions }) =>
getCommand({
runnerId,
runnerTitle,
runOpt,
id,
title,
spawn,
spawnOptions,
versions,
}),
),
)
}
Expand All @@ -20,7 +29,8 @@ const getCommand = async function({
runOpt,
id,
title,
value,
spawn,
spawnOptions = {},
versions,
}) {
const commandId = id === undefined ? runnerId : `${runnerId}_${id}`
Expand All @@ -36,7 +46,8 @@ const getCommand = async function({
commandId,
commandTitle,
commandDescription,
commandValue: value,
commandSpawn: spawn,
commandSpawnOptions: spawnOptions,
commandOpt: runOpt,
}
}
2 changes: 1 addition & 1 deletion src/run/runners/cli/main.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const START_PATH = `${__dirname}/start.js`

const commands = function() {
return [{ value: ['node', START_PATH], versions: [] }]
return [{ spawn: ['node', START_PATH], versions: [] }]
}

export const cli = {
Expand Down
4 changes: 2 additions & 2 deletions src/run/runners/node/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const commands = async function(runOpts) {
if (versions === undefined) {
return [
{
value: ['node', START_PATH],
spawn: ['node', START_PATH],
versions: [{ value: ['node', '--version'] }],
},
]
Expand All @@ -27,7 +27,7 @@ const getNodeCommand = function({ nodePath, version, fullVersion }) {
return {
id: version,
title: version,
value: [nodePath, START_PATH],
spawn: [nodePath, START_PATH],
versions,
}
}

0 comments on commit 08496ab

Please sign in to comment.