testcafe
testcafe copied to clipboard
An error is thrown on creating temporary files if multiple instances of TestCafe are used
What is your Scenario?
I run some services in parallel to execute testcafe tests in multiple instances After now running a couple of days well I have now the proble that chrome cannot start because some temp files cannot created. In my mind this happens if the different instances starts too fast a new browser. But in all my system is high end and the i/o is no problem.
What is the Current behavior?
The error:
2|Worker server 3 | GeneralError: Unable to open the "chrome:" browser due to the following error:
2|Worker server 3 | Error: ENOENT: no such file or directory, mkdir 'C:\Users\ingof\AppData\Local\Temp\testcafe\chrome-profile-54708e053K2VnMf8H\Default'
2|Worker server 3 | at BrowserConnection._runBrowser (C:\devel\heimlich\clipcafebot\node_modules\testcafe\src\browser\connection\index.ts:221:32) {
2|Worker server 3 | code: 'E1038',
2|Worker server 3 | data: [
2|Worker server 3 | 'chrome:',
2|Worker server 3 | "Error: ENOENT: no such file or directory, mkdir 'C:\\Users\\ingof\\AppData\\Local\\Temp\\testcafe\\chrome-profile-54708e053K2VnMf8H\\Default'"
2|Worker server 3 | ]
2|Worker server 3 | }
What is the Expected behavior?
That chrome can create the needed temp files. If testcafe fails with this error it have to retry it.
What is your public website URL? (or attach your complete example)
local on a very fast host
What is your TestCafe test code?
A simple test code. But the crash happens before.
Your complete configuration file
No response
Your complete test report
No response
Screenshots
No response
Steps to Reproduce
TestCafe version
1.20
Node.js version
16.16
Command-line arguments
none
Browser name(s) and version(s)
Chrome 103.0.5060.134 / Windows 10
Platform(s) and version(s)
Windows 10 64 bit
Other
No response
Iam sorry to say but this is a no go for us. The problem occour now with EVERY bulk run.
Thank you for submitting this issue. We would love to assist you and diagnose it. However, we need a simple sample that we can easily run on our side in order to replicate the issue and research its cause. Without a sample, we are not able to figure out what's going on and why this issue occurs. Refer to this article to create the best example: How To: Create a Minimal Working Example When You Submit an Issue. We look forward to your response.
Why do I always read that a sample is required? This is nonsense. As a developer of Testcafe there are enough resources, unit tests and examples. How else do you check your releases? However. Why should I waste any more time? what your needs: 1.) ecosystem file (attached). 2.) Run all instances in parallel so you have at least 3 Testcafe instances open at the same time. 3.) loop this Testcafe instances with 3 seconds timeout. You will see the crashes in the pm2 log.
I can't: 1.) Give you access to our test server. 2.) Give access to the website we are testing ecosystem.config.js.zip . It will help a lot to answer case 7215 because it is not possible to test with independent browser.
I went deeper into the error. In my eyes this happens when Testcafe cannot delete temporary files and then try to write new temporary files with the same foodprint (name). As a sample Tescafe create "chrome-profile-20232cVxsj0Tg3Nk6" in temp folder. After te execution of Testcafe it looks like Testcafe cannot close this files (delete). Next time Testcafe tries to write the file with the same name "chrome-profile-20232cVxsj0Tg3Nk6". This happens mostly if there is a process still running (check with taskmanager) I think we need to have a function that force close a Chrome instance or Testcafe instance with browser Chrome. So we make sure everything is cleaned well. After some tests I have many openend Chrome tasks in the WIndows 10 taskmanager. If I cleaned this next time the same. Because I start multiple instances for Chrome with different NodeJS server it will helpfull to have this cleanup possibility. Like process id or similar. "testcafe.close()" will not help here.
Hi @ognif ,
I asked you about a simple sample because I couldn't reproduce your use case. If you share a full simple sample example that I can implement locally, it will help me diagnose the problem.
Please at least describe how you start multiple tests. Testcafe has a concurrency option. Do you use it or do this in another way?
Multiple instances: I have a nodejs server that start a Testcafe instance. The Testcafe is started with:
const options = {
hostname: "localhost",
port1: parseInt(process.env.TCPORT1), //from ecosystem
port2: parseInt(process.env.TCPORT2), //from ecosystem
};
var testBrowser = "chrome:headless --no-sandbox --disable-gpu";
let myBrowser = new Array(testBrowser);
var testcase = __basedir + "/tests/ana.js";
let testcafe = await createTestCafe(options);
let runner = testcafe.createRunner();
try {
const failedCount = await runner.src([testcase]).browsers(browserarray).run();
if (failedCount > 0) {
console.log("No Success. Fails: " + failedCount);
} else {
console.log("All success");
}
} catch (err) {
console.log("Testcafe Error" + err);
} finally {
console.log("Testcafe close");
await testcafe.close();
}
I fork the server with pm2 to 4 instances (ecosystem file I already sent) and run the tests parallel. Each Instance has a different port for Testcafe to communicate well. Each Instance tests I run in a loop of 20.
Thank you for sharing your code. The issue occurs because you create testcafe multiple times. You need to create it only once and then reuse it for creating runner multiple times.
Hmm, please explain. On Each NodeJS instance there is just one testcafe and one runner available. Each NodeJ isntance use a dedicated port so testcafe can control this browser. So everything is inside an own Instance. Just the Temp folder is the same on the WIndows machine and this I think is a problem. A possible solution will be to give each testcafe on each Nodejs instance the possibility to set an own temp folder, so the 3 parallel running testcafe instances will not try to overwrite themself inside one global temp folder. So an option setTempFolder path will be a good way to give each instance a real own ecosystem.
The behavior you are experiencing is a bug. You can create multiple runners to work around it:
const createTestCafe = require('testcafe');
const N_RUNNERS = 4;
const testcafe = await createTestCafe('localhost', 1337, 1338);
const runners = [];
for (let i = 0; i < N_RUNNERS; i++)
runners.push(testcafe.createRunner());
Alternatively, use the concurrent mode.
After additional research, we came to the conclusion that the described behavior is a limitation. The official workaround is to use different runners or the concurrency mode to run multiple tests simultaneously.