Skip to content
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

Deflake serializer tests. #449

Merged
merged 4 commits into from
Aug 14, 2024
Merged

Conversation

adk-swisstopo
Copy link
Member

@adk-swisstopo adk-swisstopo commented Aug 14, 2024

The serializer test involve comparing the "created" and "updated" fields of collections. These fields are populated with whatever Django thinks is the current time. Until this PR, the tests assumed that comparing to "test start time" +/- 2 seconds was good enough. As per PB-694 this has proved wrong several times.

This change updates the tests such that we only verify the field values are between the start time and end time of each test. As long as time goes forward this should be fine. In any case, it should already make the test much more reliable.

We verified this works by adding a 5 seconds delay after the start of the test (which was removed in the second to last change in this PR).

The serializer tests depend on test running "fast enough" for timestamp
comparison to work. This is unreliable and causes inconsistent test failure.
This change adds a time.sleep(5) right after we record the start time of the
test such that timestamp comparison always fails.

This ensures the next change that attemps to fix the test actually fixes it
correctly. I plan to remove the delay afterwards.
We have no control over the exact value of the "created" and "updated" fields.
All we can check is that their value is between test start time and test end
time. This change ensures we perform that check instead of a flaky
"start time +/- 2 seconds".
This was used to verify test flakiness is fixed. This is now done and there is
no point delaying these tests any more.
Copy link
Contributor

@benschs benschs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@adk-swisstopo adk-swisstopo merged commit d8aa708 into develop Aug 14, 2024
9 checks passed
@adk-swisstopo adk-swisstopo deleted the fix-PB-694-flaky-serialization branch August 14, 2024 09:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants