Fix flakiness in create-daml-app tests (#9165)

* Fix flakiness in create-daml-app tests

waitForSelector doesn’t do the trick here since one selector is enough
to make this return. We need to wait until we actually have the
expected number. This is what waitForFollowers already did.

changelog_begin
changelog_end

* maybe I should test my code but also I don’t want to

changelog_begin
changelog_end

* fine I tested it

changelog_begin
changelog_end
This commit is contained in:
Moritz Kiefer 2021-03-17 10:48:26 +01:00 committed by GitHub
parent 17f8bcd37d
commit 493e2154fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -216,6 +216,15 @@ const newUiPage = async (): Promise<Page> => {
return page;
};
const waitForNSelector = async (page: Page, selector: string, n: number) => {
await page.waitForFunction(
(n, selector) => document.querySelectorAll(selector).length == n,
{},
n,
selector
);
}
// Note that Follow is a consuming choice on a contract
// with a contract key so it is crucial to wait between follows.
// Otherwise, you get errors due to contention.
@ -223,11 +232,7 @@ const newUiPage = async (): Promise<Page> => {
// but that is not the underlying error (the JSON API will
// output the contention errors as well so look through the log).
const waitForFollowers = async (page: Page, n: number) => {
await page.waitForFunction(
(n) => document.querySelectorAll(".test-select-following").length == n,
{},
n
);
await waitForNSelector(page, ".test-select-following", n);
}
// LOGIN_FUNCTION_BEGIN
@ -391,7 +396,8 @@ test("log in as three different users and start following each other", async ()
expect(noFollowing3).toEqual([]);
// However, Party 3 should see both Party 1 and Party 2 in the network.
await page3.waitForSelector(".test-select-user-in-network");
await waitForNSelector(page3, ".test-select-user-in-network", 2);
const network3 = await page3.$$eval(
".test-select-user-in-network",
(following) => following.map((e) => e.innerHTML)