Open alxroyer opened 5 years ago
My experience exactly. I put a setTimeout
in my afterEach
hook for 10s to prevent this (using AVA).
10s... Geez! Makes me feel that the spectron technology is not ready for automated system testing yet. :-(
So I ran into this same issue, and what I found out after debugging was that with running multiple applications, they seemed to be having app.client connect to 127.0.0.1:9515. It seems like when the first Spectron app stops, it calls app.client.end and that may shut down that shared client for ALL apps, which stops the rest of them from doing anything with their own version of app.client (including stopping theirs). The simple fix in my case was to add in the following where we had an array pool of multiple applications called appPool:
let app = new Application({
... // other parameters here
port: 9515 + appPool.length, // This is the important line
})
appPool.push(app)
I noticed that in your example code you weren't setting different ports per Spectron Application. Maybe it's the same issue?
Interesting info! A quick and safe workaround indeed. Neverthless, I still believe something could be fixed in spectron. Thanks for sharing @senyszrm.
Short description
When several Electron applications have been launched with spectron, it seems that calls to .stop() fail as soon as the first application has been stopped.
Configuration
Related issues
Root cause could be similar to #186, or #272? To be checked.
Investigations / steps to reproduce
Assume we have an Electron application ready, for instance the electron-quick-start app:
app.js
Add the following 'app.js' file in the 'electron-quick-start' directory:
fifoFails.js
Let's start several Electron applications with spectron, then stop them. Add the following 'fifoFails.js' file in the 'electron-quick-start' directory:
Then execute:
Stopping the application 'B' ends with a ECONNREFUSED error.
lifoWorks.js
If FIFO fails, let's test LIFO. Add the following 'lifoWorks.js' file in the 'electron-quick-start' directory:
The test ends with success:
mixWorking.js
Sounds wierd it could simply be a matter of FIFO / LIFO. Let's test a little bit further what works or not. Add the following 'mixWorking.js' file in the 'electron-quick-start' directory:
The test still ends with success, even though we have swtched applications B and C:
mixFailing.js
So what's the configuration that makes it fail? Add the following 'mixFailing.js' file in the 'electron-quick-start' directory:
B can be stopped successfully, but C (which is now behind A) fails stopping:
Conclusion
It seems that stopping the first application launched kills spectron resources, which prevents other applications to be stopped from that point, unless anything else is wrong in my code & configuration... :-) Let me know !