-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Proposal: Add an API to recover after DISCONNECT #3691
Comments
Hmm I've found a reference to I'm now trying to implement it like this: function recoverDisconnect(launcher, server) {
server.on('browser_error', (browser) => {
if(browser.state === 'EXECUTING_DISCONNECTED'){
console.log('restarting!')
launcher.restart(browser.id);
}
});
}
recoverDisconnect.$inject = ['launcher', 'server'];
async function main() {
const config = await karma.config.parseConfig(require.resolve('./karma.conf.js'), { frameworks: ['recoverDisconnect', 'chai', 'mocha'], plugins: [ 'karma-*', { 'framework:recoverDisconnect': ['factory', recoverDisconnect] },], singleRun: false }, { promiseConfig: true, throwErrors: true });
const server = new karma.Server(config);
server .on('run_complete', async (_browser, results) => {
console.log(results);
});
server .once('browsers_ready', async () => {
karma.runner.run(config);
});
await s.start();
}
main().catch(err => {
console.error(err);
process.exitCode = 1;
}); However, karma/lib/launchers/process.js Lines 82 to 84 in 2b71a3c
This seems by design. What is the usecase for |
Aha, I found what the issue was. I was indeed doing something wrong 😅 Providing callbacks to karma's methods is really important. I didn't provide a callback to server .once('browsers_ready', async () => {
- karma.runner.run(config);
+ karma.runner.run(config, () => {});
}); If I provide a callback it seems to work as expected and I'm able to restart the browser as expected 🤟 Only question that remains is: is this a stable API? I guess time will tell... 😅? |
Depending on what you're trying to achieve, maybe http://karma-runner.github.io/6.3/config/configuration-file.html#browserdisconnecttolerance will work?
He-he, indeed! It's rather hard to give any guarantees on this as Karma does not have a formal public API and almost any change may become breaking to somebody.
I think the error message will change somewhat, but otherwise, the logic will stay the same as before: if the browser didn't send ping until ping timeout, it will be considered disconnected and will fire the UPD Oh, the EXECUTING_DISCONNECTED state will be gone :(
Yeah.. We've already removed a bunch of |
I think we should kill the browser process upon disconnect in the #3653 implementation. I'll look into it when I've got some time. |
Hmm, my current implementation is this: if (browser.state.toUpperCase().includes('DISCONNECTED')) {
// Restart the browser for next run
this.karmaServer.get('launcher').restart(browser.id);
this.browserIsRestarting = true;
} So any state with
Would there still be a possibility to start a new one automatically? Or will that be the default behavior? If you want I can validate any changes you make to karma before release. We have a pretty robust test set for integrating StrykerJS with Karma, including infinite loops, multiple runs, exiting the process, angular integration, windows/linux, a karma-webpack scenario, etc. That would also improve the migration experience for Stryker users to the latest karma release. |
Yes, I would say so!
Yes, there would be a possibility to start a new one. We actually already kill the disconnected browser. So the only real difference is that
Thanks! I'll ping you once that PR is ready for testing. |
any updates on this issue? Hit the same issue here WRT the socket disconnection. |
We've implemented our disconnect fix and it's working ever since: https://github.com/stryker-mutator/stryker-js/blob/master/packages/karma-runner/src/karma-plugins/stryker-reporter.ts#L135-L151 |
Thanks again for the awesome work on Karma. There might already be an API for what I'm asking, but I couldn't find it. I hope I'm not wasting your time.
Current behavior
When running StrykerJS with karma (via
@stryker-mutator/karma-runner
), the code under test is being changed and can have unexpected behavior. One of the possibilities is that an infinite loop is created. For example:This will result in the browser being really busy and not able to ping to the server, eventually causing a
"Disconnected reconnect failed before timeout of 2000ms (ping timeout)"
error.There currently is no way to recover from this. The browser isn't restarted or closed and there is no way to force this in the karma API. The only solution is to close the entire node process and start a new one, which is very expensive (especially in scenario's where webpack needs to rerun).
Desired solution
Add a way to recover from this scenario. For example:
Additional question: would the solution in #3267 change this disconnect behavior?
Related issue
#3267
stryker-mutator/stryker-js#2989
The text was updated successfully, but these errors were encountered: