-
Notifications
You must be signed in to change notification settings - Fork 1
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
Tests Frontend: Flaky ResolveForecastDialog test - handleCloseCalled is false #561
Milestone
Comments
omarkohl
changed the title
Tests Frontend: Flaky ResolveForecastDialog test
Tests Frontend: Flaky ResolveForecastDialog test - handleCloseCalled is false
Jun 13, 2023
Script to run all tests until one fails. #!/bin/bash
set -o errexit
set -o nounset
set -o pipefail
npm install
count=0
while true
do
date
echo $count
# Seems to be the closest to what GitHub actions does
npm run test -- --all --bail --ci --watchAll=false --runInBand || break
echo
echo
echo
sleep 2
count=$((count+1))
done |
omarkohl
added a commit
that referenced
this issue
Jun 13, 2023
Contrary to what I initially believed the issue does not seem to be in the Footer.test.tsx but in App.test.tsx . The error message appears after the Footer.test.tsx output and before the App.test.tsx output. The App test includes all components but was not checking for the footer content. My hypothesis is that when the test was done it tore down the msw handlers making the fetch request for config.json made in the Footer either abort or not be intercepted by msw. What set me on the right track was the following issue, in particular this comment jestjs/jest#9324 (comment) . Before this fix the tests would fail about once every 10 to 40 executions. After this fix the tests failed due to #561 after about 320 and after about 60 executions. There were no more failures because of this issue.
Probably it's because the dialog only closes once the request to resolve the forecast has completed. Even in the test case with msw that might sometimes take a little longer. With the following change the test immediately fails: diff --git a/frontend/src/ResolveForecastDialog.test.tsx b/frontend/src/ResolveForecastDialog.test.tsx
index 8394aa0..e3ea2b9 100644
--- a/frontend/src/ResolveForecastDialog.test.tsx
+++ b/frontend/src/ResolveForecastDialog.test.tsx
@@ -80,6 +80,7 @@ test('forecast can be resolved with outcome', async () => {
server.use(
graphql.mutation("resolveForecast", async (req, res, ctx) => {
requestBody = await req.json();
+ await new Promise(f => setTimeout(f, 1000));
return res(
ctx.data({
"resolveForecast": { |
omarkohl
added a commit
that referenced
this issue
Jun 15, 2023
The handleClose function is only called once the resolveForecast request completes so there was a race condition where the handleClose was not always called immediately after clicking 'Save' in the test. Solve this by using waitFor() to repeat the verification several times. Also replace the previous handleClose function with the handleCloseCalled variable with the more elegant Jest mock functions. To simulate real network conditions a small delay was left in the response code.
After commit 8f34ec4 about 600 executions of all tests were successful, so it seems reasonable to conclude that this has been resolved. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It failed once after about 320 executions and another time after about 60 executions of all frontend tests.
Probably a race condition when the dialog is closed the handleClose is not called immediately.
The text was updated successfully, but these errors were encountered: