Skip to content

Commit

Permalink
[ci-visibility] Fix cucumber parallel mode (#3156)
Browse files Browse the repository at this point in the history
  • Loading branch information
juan-fernandez authored and uurien committed Jun 2, 2023
1 parent 3a62211 commit 0a48ca7
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
28 changes: 28 additions & 0 deletions integration-tests/cucumber/cucumber.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,34 @@ versions.forEach(version => {
})
const reportMethods = ['agentless', 'evp proxy']

it('does not crash with parallel mode', (done) => {
let testOutput
childProcess = exec(
`./node_modules/.bin/cucumber-js ci-visibility/features/farewell.feature --parallel 2 --publish-quiet`,
{
cwd,
env: {
...getCiVisAgentlessConfig(receiver.port),
DD_TRACE_DEBUG: 1,
DD_TRACE_LOG_LEVEL: 'warn'
},
stdio: 'inherit'
}
)
childProcess.stdout.on('data', (chunk) => {
testOutput += chunk.toString()
})
childProcess.stderr.on('data', (chunk) => {
testOutput += chunk.toString()
})
childProcess.on('exit', (code) => {
assert.notInclude(testOutput, 'TypeError')
assert.include(testOutput, 'Unable to initialize CI Visibility because Cucumber is running in parallel mode.')
assert.equal(code, 0)
done()
})
})

reportMethods.forEach((reportMethod) => {
context(`reporting via ${reportMethod}`, () => {
let envVars, isAgentless
Expand Down
13 changes: 13 additions & 0 deletions packages/datadog-instrumentations/src/cucumber.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const { createCoverageMap } = require('istanbul-lib-coverage')

const { addHook, channel, AsyncResource } = require('./helpers/instrument')
const shimmer = require('../../datadog-shimmer')
const log = require('../../dd-trace/src/log')

const testStartCh = channel('ci:cucumber:test:start')
const testFinishCh = channel('ci:cucumber:test:finish') // used for test steps too
Expand Down Expand Up @@ -175,6 +176,12 @@ function wrapRun (pl, isLatestVersion) {
}

function pickleHook (PickleRunner) {
if (process.env.CUCUMBER_WORKER_ID) {
// Parallel mode is not supported
log.warn('Unable to initialize CI Visibility because Cucumber is running in parallel mode.')
return PickleRunner
}

const pl = PickleRunner.default

wrapRun(pl, false)
Expand All @@ -183,6 +190,12 @@ function pickleHook (PickleRunner) {
}

function testCaseHook (TestCaseRunner) {
if (process.env.CUCUMBER_WORKER_ID) {
// Parallel mode is not supported
log.warn('Unable to initialize CI Visibility because Cucumber is running in parallel mode.')
return TestCaseRunner
}

const pl = TestCaseRunner.default

wrapRun(pl, true)
Expand Down

0 comments on commit 0a48ca7

Please sign in to comment.