Testcafe: asynchronous operations not queued correctly

Created on 10 Jul 2019  Â·  3Comments  Â·  Source: DevExpress/testcafe

What is your Test Scenario?

I am trying to test simple async methods. and expect the order of execution to be preserved.

What is the current behavior?


I hope I am not doing something wrong. but if you look at the images and test code, you would see I have very simple functions a() and b(), I am expecting the console.log('after async operations in scenario') to happen after the functions are executed. so if you run a() 2 times the log should happen after them, but in this case, always the log is happening after the start of the test in the second browser. also, if you look at the methods themselves, you would see that second a() is starting in the second browser before finishing the 2 a() in the first browser ( i don't know if this is intended but I don't have concurrency enabled).

try to add 3 a() or b() and you would see that this weird behavior is consistent as in the console.log('after async operations in scenario') will always happen in the wrong order

### What is the Expected behavior?
The console.log('after async operations in scenario') should happen after the finish of methods executions and within the same browser and not the second browser.

What is your web application and your TestCafe test code?

Your website URL (or attach your complete example):


Your complete test code (or attach your test files):

``js async function a(t) { await t.typeText([name="q"],hello); console.log(async function in scenario 1`, t.testRun.browserConnection.browserInfo.userAgent);

}

async function b(t) {
await t.typeText([name="q"], hello);
console.log(async function in scenario 1, t.testRun.browserConnection.browserInfo.userAgent);

}

fixtureGetting Started
.page(https://google.com);

test("scenario 1", async t => {
await a(t);
await a(t);
console.log(after async operations in scenario 1);
});
//
test("scenario 2", async t => {
await b(t);
await b(t);
console.log(after async operations in scenario 2);

});

</details>

<details>
<summary>Your complete configuration file (if any):</summary>

 ```js
const createTestCafe = require('testcafe');
let testcafe = null;

createTestCafe('localhost', 1337, 1338)
    .then(tc => {
        testcafe = tc;
        const runner = testcafe.createLiveModeRunner();

        return runner
            .src(['./myFixture1.js'])
            .browsers(['chrome:headless','chrome-canary:headless'])
            .run();
    })
    .then(failedCount => {
        console.log('Tests failed: ' + failedCount);
        testcafe.close();
    });


Your complete test report:

with 2 async methods in each test

 Running tests in:
 - HeadlessChrome 75.0.3770 / Windows 10.0.0
 - HeadlessChrome 77.0.3848 / Windows 10.0.0

 Getting Started
async function in scenario 1 HeadlessChrome 77.0.3848 / Windows 10.0.0
async function in scenario 1 HeadlessChrome 75.0.3770 / Windows 10.0.0
async function in scenario 1 HeadlessChrome 77.0.3848 / Windows 10.0.0
after async operations in scenario 1
async function in scenario 1 HeadlessChrome 75.0.3770 / Windows 10.0.0
after async operations in scenario 1
 √ scenario 1
async function in scenario 1 HeadlessChrome 77.0.3848 / Windows 10.0.0
async function in scenario 1 HeadlessChrome 75.0.3770 / Windows 10.0.0
async function in scenario 1 HeadlessChrome 77.0.3848 / Windows 10.0.0
after async operations in scenario 2
async function in scenario 1 HeadlessChrome 75.0.3770 / Windows 10.0.0
after async operations in scenario 2
 √ scenario 2


 2 passed (9s)
with 3 async methods in each test

 Getting Started
async function in scenario 1 HeadlessChrome 77.0.3848 / Windows 10.0.0
async function in scenario 1 HeadlessChrome 77.0.3848 / Windows 10.0.0
async function in scenario 1 HeadlessChrome 75.0.3770 / Windows 10.0.0
async function in scenario 1 HeadlessChrome 77.0.3848 / Windows 10.0.0
after async operations in scenario 1
async function in scenario 1 HeadlessChrome 75.0.3770 / Windows 10.0.0
async function in scenario 1 HeadlessChrome 75.0.3770 / Windows 10.0.0
after async operations in scenario 1
 √ scenario 1
async function in scenario 1 HeadlessChrome 77.0.3848 / Windows 10.0.0
async function in scenario 1 HeadlessChrome 77.0.3848 / Windows 10.0.0
async function in scenario 1 HeadlessChrome 75.0.3770 / Windows 10.0.0
async function in scenario 1 HeadlessChrome 77.0.3848 / Windows 10.0.0
after async operations in scenario 2
async function in scenario 1 HeadlessChrome 75.0.3770 / Windows 10.0.0
async function in scenario 1 HeadlessChrome 75.0.3770 / Windows 10.0.0
after async operations in scenario 2
 √ scenario 2


 2 passed (9s)


Screenshots:

with 2 async methods in each test
image

with 3 async methods in each test
image

Steps to Reproduce:

  1. Execute this command node testcafe.js
  2. see console output

Your Environment details:

  • testcafe version:
  • node.js version:
  • command-line arguments:
  • browser name and version:
  • platform and version:
Auto-locked question

All 3 comments

I don't see any inconsistency here. Let me explain.
Here is my code created based on yours. I modified it a bit:
 

async function a(t) {
    await t.typeText(`[name="q"]`, `hello`);
    console.log(`a - async function in scenario`, t.testRun.browserConnection.browserInfo.userAgent);
}

async function b(t) {
    await t.typeText(`[name="q"]`, `hello`);
    console.log(`b - async function in scenario`, t.testRun.browserConnection.browserInfo.userAgent);
}


fixture`Getting Started`
    .page(`https://google.com`);

test("scenario 1", async t => {
    await a(t);
    await b(t);
    console.log(`after async operations in scenario 1 ${t.testRun.browserConnection.browserInfo.userAgent}`);
});

test("scenario 2", async t => {
    await a(t);
    await b(t);
    console.log(`after async operations in scenario 2 ${t.testRun.browserConnection.browserInfo.userAgent}`);
});


And here is the report:

 Running tests in:
 - HeadlessChrome 75.0.3770 / Windows 10.0.0
 - Firefox 67.0.0 / Windows 10.0.0

 Getting Started
a - async function in scenario Firefox 67.0.0 / Windows 10.0.0
a - async function in scenario HeadlessChrome 75.0.3770 / Windows 10.0.0
b - async function in scenario Firefox 67.0.0 / Windows 10.0.0
after async operations in scenario 1 Firefox 67.0.0 / Windows 10.0.0
b - async function in scenario HeadlessChrome 75.0.3770 / Windows 10.0.0
after async operations in scenario 1 HeadlessChrome 75.0.3770 / Windows 10.0.0
 √ scenario 1
a - async function in scenario Firefox 67.0.0 / Windows 10.0.0
a - async function in scenario HeadlessChrome 75.0.3770 / Windows 10.0.0
b - async function in scenario Firefox 67.0.0 / Windows 10.0.0
after async operations in scenario 2 Firefox 67.0.0 / Windows 10.0.0
b - async function in scenario HeadlessChrome 75.0.3770 / Windows 10.0.0
after async operations in scenario 2 HeadlessChrome 75.0.3770 / Windows 10.0.0
 √ scenario 2

 
First we see that the a method is executed in both browsers.
Then the b method is executed in Firefox.
Then we see the after async operations... message in Firefox. It's OK since Firefox has already executed the a and b methods.
Then we see the b method in Chrome.
And in the end we see the after async operations... message in Chrome since Chrome finally executed both the a and b methods.
 
Thus, every async function in scenario message is executed only after the a and b methods in corresponding browsers. This means that async operations are executed in sequence for each browser, but they can be executed at the same time in different browsers, since they not interfere each other.

thank you for the detailed explanation, the key take away, is that even with no concurrency the tests run in parallel when defining multiple browsers, this is nice.

This thread has been automatically locked since it is closed and there has not been any recent activity. Please open a new issue for related bugs or feature requests. We recommend you ask TestCafe API, usage and configuration inquiries on StackOverflow.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

marchugon picture marchugon  Â·  4Comments

multivoltage picture multivoltage  Â·  3Comments

madroneropaulo picture madroneropaulo  Â·  3Comments

darkowic picture darkowic  Â·  3Comments

ParachuteCat picture ParachuteCat  Â·  3Comments