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

LINK-2210: fix randomly failing tests #1022

Merged
merged 2 commits into from
Jan 10, 2025

Conversation

danipran
Copy link
Contributor

@danipran danipran commented Jan 9, 2025

This was causing random failures with two tests (test_recurring_sub_event_put_cancellation_emails_sent_payments_not_refunded_for_super_event and test_recurring_sub_event_put_cancellation_emails_sent_signups_not_cancelled_for_super_event) which assume that the notifications were sent in a certain order (desc pk). However, if an order is not specified, Postgres cannot guarantee an order, and that's exactly what happened here.

There were two ways of resolving this; either guarantee an order or change the test to be order-agnostic. In this case, I chose the path of least resistance.

I've no clue how to default order works, but it's probably related to the underlying data structures. It would also explain why the tests were failing randomly since there is some random data involved in the tests (e.g. factories & Faker).

I was able to replicate the issue locally (using Docker) by running only the two tests with the same database (i.e. --reuse-db flag with pytest, need to do the first run with --create-db to recreate the database) 20 times in a row. From the 21st run onward, the two tests start to fail. I realize this sounds more like an urban legend than actual steps for replicating this, but I was able to do this consistently. Not sure if it works on every machine since Postgres' default order is something of a mystery (or for me, at least).

Also fixed a misnamed init file.

This was causing failures with two tests which assume that the
notifications were sent in a certain order (desc pk). However,
if an order is not specified, Postgres cannot guarantee an order,
and that's exactly what happened here.

There were two ways of resolving this; either guarantee an order or
change the test to be order-agnostic. In this case, I chose the
path of least resistance.

Refs: LINK-2210
Copy link

sonarqubecloud bot commented Jan 9, 2025

@danipran danipran marked this pull request as ready for review January 9, 2025 15:13
@danipran danipran requested a review from a team January 9, 2025 15:14
@terovirtanen
Copy link
Contributor

LINKEDEVENTS-API branch is deployed to platta: https://linkedevents-pr1022.api.dev.hel.ninja 🚀🚀🚀

Copy link
Contributor

@tuomas777 tuomas777 left a comment

Choose a reason for hiding this comment

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

LGTM 👍

Copy link
Contributor

@voneiden voneiden left a comment

Choose a reason for hiding this comment

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

wild

@danipran danipran merged commit 7b95c09 into main Jan 10, 2025
21 checks passed
@danipran danipran deleted the LINK-2210/fix-randomly-failing-tests branch January 10, 2025 08:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants