New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is it possible to retrieve the wallaby worker id from the actual test code? #774
Comments
Depending on how you're planning to reuse it, you may make the worker id available to any other code by assigning a global variable: module.exports = function () {
return {
...
setup: function (wallaby) {
global.workerId = wallaby.workerId;
// or process.env.workerId = wallaby.workerId;
}
};
}; and then accessing it anywhere from your code. Or create a file where it's used (to set up your DB for example) and just pass it there: module.exports = function () {
return {
files: [
...
'setupFile.js'
]
...
setup: function (wallaby) {
require('./setupFile')(wallaby.workerId);
}
};
}; and the module.exports = function (workerId) {
// your initialization logic
// that can be reused by other runners (that can pass some worked id)
} Let me know if it addresses your question. |
That is fine - the global one should work the easiest. ... if it is not overwritten by the other workers? If I have e.g. six different workers running, will they have different global variables? (This might be off-topic, I know...) |
Correct. Each worker has its own separate node process, the |
Thanks very much! |
.... a tiny hiccup: I can't seem to get the setup function to work. My wallaby.js config file looks like this: module.exports = function () {
//noinspection JSUnusedGlobalSymbols
return {
env: {
type: 'node',
params: {
runner: "--harmony"
}
},
setup: function(wallaby) {
console.log(`******************* workerId: ${wallaby.workerId} ***********************`);
global.workerId = wallaby.workerId;
},
bootstrap: function() {
var path = require('path');
require('co-mocha')(require(path.join(path.dirname(process.argv[1]), 'runners/node/mocha@2.1.0/framework/')));
},
files: [
"bl/**/*.js",
"dal/**/*.js",
"model/**/*.js",
"plugins_v3/**/*.js",
"plugins/**/*.js",
"utils/**/*.js",
"config/**/*.js",
"test/test_config.js",
"test/test_db.js",
"test/test_graph.js",
"test/mocha.config.test.js",
"app.js",
],
tests: [
'test/dal/**/*.test.js',
'test/plugins/**/*.test.js',
'test/bl/**/*.test.js',
],
testFramework: "mocha",
debug: true,
workers: {
initial: 6,
regular: 2
}
};
}; And I am looking for the comment specifying the worker id in the Wallaby Console, but I cannot see it anywhere. Am I looking in the wrong place? |
You need to merge the setup: function(wallaby) {
console.log(`******************* workerId: ${wallaby.workerId} ***********************`);
global.workerId = wallaby.workerId;
var path = require('path');
require('co-mocha')(require(path.join(path.dirname(process.argv[1]), 'runners/node/mocha@2.1.0/framework/')));
}, |
Ah, thanks. I will try that. |
How about using console.log from the setup function: Shouldn't its output appear in the wallaby console window (using WebStorm)? |
Nvm - it started appearing after I merged the two functions. Thanks very much for your help! |
Issue description or question
I am doing a large suite of tests that all interact with a database. I have setup and teardown code that creates the database and then drops it afterwards. This means that if I run tests in parallel, they attempt to access the same database.
Currently I solve this by setting workers: { initial: 1, regular: 1 } in my wallaby config file, but it would be great if I could run tests in parallel to speed up things.
My thought was to use the worker Id in the database name to guarantee that each separate worker gets its own database to work with. But is it possible to retrieve the worker Id from the test code?
Edit: I found another issue, #707 , which mentions the same thing. But I am not always running my tests with Wallaby, so I do not want to put my setup code in the wallaby configuration file, as that will not be hit in those circumstances. That is why I would like to export the worker id somehow, if possible.
Thanks :-)
Code editor or IDE name and version
WebStorm v2016.2
OS name and version
OSX
The text was updated successfully, but these errors were encountered: