-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
chore(tests): add setupDatabaseReset utility #24786
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
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Have you done tests on speed? I think this was originally added during the creation of the document service when we discovered the tests ran about 90% faster with this method. As long as this is not a major increase in runtime I'm all for it though |
3710076 to
e97712c
Compare
I just did some and indeed it appears quite a bit slower, wdyt of keeping both? Favor the transaction util but use table truncate reset where needed? As an example adonis exposes utils like that for similar reasons (ie nested transaction) https://docs.adonisjs.com/guides/testing/database |
3d5d23d to
7ca70ae
Compare
7ca70ae to
ba53c3f
Compare
I'm fine with having this as an option too, it's better than our current method of requiring every test to clean up after itself and then causing unrelated tests down the line to fail when they don't. The ideal solution would be a db reset that is fast enough to run before every test suite, so maybe this would be a first step towards that. |
mathildeleg
left a comment
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 (but I don't think I know enough on this subject to give my full approval 🙈)
|
@innerdvations If you are ok with the changes could you give me an approval? As you mentioned we can always improve it or even remove it and find a better solution if it isn't suiting our needs. |
araksyagevorgyan
left a comment
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 👍
What does it do?
Add
setupDatabaseResetutility. Accomplishes the same goal astestInTransactionby resetting the database after each test has run. It's slower but more reliable and is not vulnerable to test failures caused by function calls outside the test's transaction context when using testInTransaction.Updates the docker file to spin up test databases since it was throwing an error when starting
Why is it needed?
testInTransaction often causes API tests to fail since some async code is intentionally fired without await and then tries to execute after the test's transaction context has closed
For example see: https://github.com/strapi/strapi/actions/runs/19104795038/job/54586327649?pr=24648
How to test it?
The API tests should pass on this PR
Test it locally by running the docker test file
docker-compose -f docker-compose.test.yml upNow you can test all database dialects with
yarn test:api --db=<sqlite | postgres | mysql>Related issue(s)/PR(s)
I've tested (in the CI) this will resolves the transaction error causing tests to fail on:
#24648