-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
[usage] Fix flakes by deleting records created by each test, not deleting all #10971
Conversation
@easyCZ Got a couple of these while testing:
|
Interesting, I wasn't able to reproduce these. I guess that happens when the tests create too many connection against the DB. Perhaps a connection pool on the app side can solve this. Let me try with a larger sample (1k runs) to see if I can reproduce, to test a fix. |
@geropl I've moved the test connection setup into the |
Now the only ones which do not like to be run in parallel are the ones where we create raw objects, due to seed values of random generation of workspace name. I'm gonna drop these tests as they are no longer really relevant, they existed to validate we can read from the existing DB without issues but we've long been running in that state that the data in the unit tests are no longer up-to-date either. |
// Licensed under the GNU Affero General Public License (AGPL). | ||
// See License-AGPL.txt in the project root for license information. | ||
|
||
package db_test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These tests were moved to a seperate file because they required using the dbtest.ConnectForTest
but were previously in the db
package. This would create a circular import. Nothing changed about the test.
There remains an issue with the test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, tested and works as expected as per this comment.
Golang will run tests from different files (and packages) concurrently (in seperate go-routines). This presents a problem for our test cleanup logic which tries to execute
DELETE * FROM <table>
to cleanup a test table.Follows guidance from https://kevin.burke.dev/kevin/fast-parallel-database-tests/
When tests are run, we use a helper from
dbtest.CreateWorkspaces
ordbtest.CreateWorkspaceInstances
to create records which have a test cleanup hook. This hook deletes created records by ID instead of deleting all. This is necessary because when tests run concurrently, we don't want to drop records possibly created by other tests.There still remain a problem for tests which try to do ListAll without any constraints but we don't have any of these in our usage component, yet.
Description
Related Issue(s)
Fixes #
How to test
Unit tests
Release Notes
Documentation
NONE
Werft options: