You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
test: use built-in wait function and fix wait times to avoid flaky tests - #11812
The timeout values have been changed from 150ms/0.2s to 200ms/0.3s. This change should be validated to ensure it doesn't make the timeout tests less effective at catching actual timeout issues, while still preventing flakiness.
The assertion was changed from checking inequality (not.eql) to checking greater-than relationship. While this is more precise, verify that this change is intentional and that the 100ms wait is sufficient for all database systems to register a timestamp difference.
Multiple cache expiration tests now wait 1010ms instead of 1000ms. While this adds a safety margin, verify that the cache expiration is set to 1000ms in the test setup, and confirm that 1010ms is sufficient across all test environments without being excessive.
Why: The suggestion correctly identifies that a 100ms wait might be too short for reliably detecting timestamp changes in a database, potentially causing flaky tests. Increasing the wait time improves test robustness.
Why: The suggestion correctly identifies a potential for flaky tests due to a short wait time, and increasing it aligns with other tests in the PR, improving test reliability.
Increase the wait time from 1010ms to 1100ms for cache expiration tests. This provides a larger buffer over the 1000ms cache duration, making the tests more reliable and less prone to flakiness.
// give some time for cache to expire
-await scheduler.wait(1010)+await scheduler.wait(1100)
Suggestion importance[1-10]: 6
__
Why: The suggestion correctly identifies a potential source of test flakiness by pointing out that a 10ms buffer for a 1000ms cache timeout is too small, and proposes a more robust value.
To prevent flaky tests due to low database timestamp precision, increase the wait time from 100ms to over a second (e.g., 1001ms) before updating the entity.
-// wait a bit-await scheduler.wait(100)+// wait a bit to ensure updated date will be different+await scheduler.wait(1001)
// update post once again
post.title = "Updated Title"
await postRepository.save(post)
// check if date was updated
const loadedPostAfterUpdate =
await postRepository.findOneByOrFail({
id: post.id,
})
expect(
loadedPostAfterUpdate.updatedAt.getTime(),
).to.be.greaterThan(loadedPostBeforeUpdate.updatedAt.getTime())
Suggestion importance[1-10]: 8
__
Why: The suggestion correctly identifies that a 100ms wait is insufficient to guarantee a change in the updatedAt timestamp on databases with low time precision, which could lead to flaky tests.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description of change
Replace custom
sleep()function with built-inscheduler.waitfromnode:timers/promises.Modify
waittimes so the tests are less flaky.Pull-Request Checklist
masterbranchFixes #00000