Skip to content

chore: improve notifications tests #13863

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

Merged
merged 7 commits into from
Jul 10, 2024

Conversation

dannykopping
Copy link
Contributor

Blocks #13799

  • only use Postgres when necessary
  • add some more comments to improve readability

Also add some more comments to improve readability

Signed-off-by: Danny Kopping <danny@coder.com>
@dannykopping dannykopping requested review from mafredri and mtojek July 10, 2024 10:31
@dannykopping dannykopping self-assigned this Jul 10, 2024
Signed-off-by: Danny Kopping <danny@coder.com>
Signed-off-by: Danny Kopping <danny@coder.com>
Signed-off-by: Danny Kopping <danny@coder.com>
if !dbtestutil.WillUsePostgres() {
t.Skip("This test requires postgres")
t.Skip("This test requires postgres; it relies on business-logic implemented in the database")
Copy link
Member

Choose a reason for hiding this comment

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

nit: implemented only

}
ctx, logger, db := setup(t)
// SETUP
ctx, logger, db := setupInMemory(t)
Copy link
Member

Choose a reason for hiding this comment

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

The problem with this approach is that we are not testing against the real database. I'm convinced if it is a truly safe way to go. Which parts of the implementation are missing in dbmem?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

dbmem doesn't actually perform the bulk updates, and along with that comes the retry logic; nor does it handle leases or locking.

There still are some tests which test the real database such as TestBackpressure, TestRetries, and TestExpiredLeaseIsRequeued. Each of those test the full scope of enqueue -> dequeue -> update -> requeue -> update.

In this test specifically, the database is not required to be tested - provided the observed behaviour of having a notification be dispatched to a webhook endpoint is achieved; so it's safe to use a mock database.

Copy link
Member

@mafredri mafredri left a comment

Choose a reason for hiding this comment

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

What's the pro of no longer using Postgres for these tests? I'm unsure of how may PostgreSQL tests remain, but I'd feel a bit uncomfortable if all our testing was in dbmem.

Otherwise changes look good 👍🏻

Signed-off-by: Danny Kopping <danny@coder.com>
@dannykopping
Copy link
Contributor Author

dannykopping commented Jul 10, 2024

What's the pro of no longer using Postgres for these tests? I'm unsure of how may PostgreSQL tests remain, but I'd feel a bit uncomfortable if all our testing was in dbmem.

Otherwise changes look good 👍🏻

The main benefit of not using Postgres really is just speed. See also #13863 (comment) for further explanation about the tests still using the database.

It's also useful to have a ~functioning dbmem implementation (at least for the happy path) for use in integration tests.

…include state sync

Signed-off-by: Danny Kopping <danny@coder.com>
@dannykopping
Copy link
Contributor Author

@mafredri @mtojek I've modified TestBasicNotificationRoundtrip in edc4e7a to use Postgres, so that we have at least 1 test which is explicitly testing the full roundtrip with the database, not implicitly like the others I mentioned.

Would you mind re-reviewing? I'll merge if you're happy.

Signed-off-by: Danny Kopping <danny@coder.com>
Copy link
Member

@mtojek mtojek left a comment

Choose a reason for hiding this comment

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

Good to go 👍

@dannykopping dannykopping merged commit 542fff7 into main Jul 10, 2024
28 checks passed
@dannykopping dannykopping deleted the dk/system-notifications-improve-tests branch July 10, 2024 13:25
@github-actions github-actions bot locked and limited conversation to collaborators Jul 10, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants