Error: EBADF: bad file descriptor, write
See original GitHub issueRunning version 0.3.9 of this plugin, my setup is as follows (all running in jenkins): running using docker-compose I have 1 selenium hub instance, 2 chrome nodes, 1 instance of the frontend application.
once that is running, I’m constructing multiple commands similar to:
sh 'cd /usr/src/app && ' +
"MOCHA_E2E_PARAMS='--grep=${tag} " +
"--rootUrl=http://frontend:3000 --seleniumServer=hub " +
"--browserName=chrome --screenshotDir=${env.WORKSPACE}/screenshots/selenium " +
"-C -R mocha-jenkins-reporter -O junit_report_path=${env.WORKSPACE}/tests/test-results/selenium_chrome_${tag}.xml' " +
"yarn run mocha-e2e"
I then run these inside a docker container using parallel
. This has worked well using the xunit
reporter (though I had other issues with it, unrelated to the runtime itself), but ever since integrating mocha-jenkins-reporter
I’m getting the following error every time a suite fails:
fs.js:793
return binding.writeString(fd, buffer, offset, length, position);
^
Error: EBADF: bad file descriptor, write
at Error (native)
at Object.fs.writeSync (fs.js:793:18)
at Runner.<anonymous> (/usr/src/app/node_modules/mocha-jenkins-reporter/lib/jenkins.js:308:10)
at emitNone (events.js:91:20)
at Runner.emit (events.js:185:7)
at /usr/src/app/node_modules/mocha/lib/runner.js:812:12
at done (/usr/src/app/node_modules/mocha/lib/runner.js:649:7)
at Runner.next [as nextSuite] (/usr/src/app/node_modules/mocha/lib/runner.js:616:16)
at Runner.uncaught (/usr/src/app/node_modules/mocha/lib/runner.js:737:17)
at process.uncaught (/usr/src/app/node_modules/mocha/lib/runner.js:804:10)
at emitOne (events.js:96:13)
at process.emit (events.js:188:7)
at process._fatalException (bootstrap_node.js:296:26)
error Command failed with exit code 7.
After looking at the source, this comes from the following line: https://github.com/juhovh/mocha-jenkins-reporter/blob/master/lib/jenkins.js#L308
Since this is happening only after errors, I assume it’s related to the onError
handler I use, which basically dumps the client console and takes a screenshot:
onError: function (error, testTitle, done) {
error && console.error(error);
const activeClient = require('./setup.js').browser.activeClient();
dumpBrowsersConsole(activeClient)
.then(() => saveScreenshot(activeClient, testTitle.replace('/', '_')))
.execute(`return "LOG: Ending test ${testTitle}"`)
.end()
.call(done)
.call(() => {
process.exit(1);
});
}
and relevant functions:
function dumpBrowsersConsole (client, excludeLevels = []) {
return client.log('browser').then(function (logmessage) {
logmessage.value.forEach(entry => {
if (excludeLevels.indexOf(entry.level) <= -1) {
console.log('> ', entry.level, '> ', entry.message.substring(0, 500));
}
});
return true;
});
}
function saveScreenshot (client, testTitle) {
if (!fs.existsSync(screenshotDir)) {
fs.mkdirSync(screenshotDir);
}
const currentTestTitle = testTitle && testTitle.replace(/\s/g, '_');
const screenshotPath = screenshotDir + '/e2e-screenshot-' + currentTestTitle + '.png';
console.info('Creating screenshot', screenshotPath);
return client
.saveScreenshot(screenshotPath);
}
Again, this never happened with the xunit reporter, and this also doesn’t happen when I try to replicate it locally. It seems like it’s coming from the writing of the xml file itself, but AFAICT the xml file is written.
Issue Analytics
- State:
- Created 6 years ago
- Comments:7 (4 by maintainers)
Top GitHub Comments
@Pourliver I tried to fix this in the latest 0.3.12 release, please try it out and let me know if it helped.
Well the fixe mutes the error, so I think we can see this as a fix 😃 Thanks for the fast reply.