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

[10.x] Fix timing sensitive flaky test #48664

Merged

Conversation

KentarouTakeda
Copy link
Contributor

Summary

Fixed the issue where the Queue retry time test, when using the Redis Driver, would occasionally fail.

For example, #48662 (comment) also seems to have encountered this problem.

An earlier attempt was made to address this problem by retrying the test itself, as seen in commit e0d8e3d .
However, it was not a fundamental solution.

In the test, we specified a delay of 10 minutes and asserted that the actual delay was 600 seconds . However, due to the time elapsed during the test execution, the test may rarely reach 599 seconds and fail. I solved this problem by fixing the time using Carbon::setTestNow() at the beginning of the test.

Before the fix, the test would fail after about 30 to 100 attempts. After the fix, I tried it 10,000 times and it didn't fail.

Note

It actually asserts for more than 600 seconds. This is because redis-server calculates the retry time, so it cannot be controlled with setTestNow().

public function acquire()
{
$results = $this->redis->eval(
$this->luaScript(), 1, $this->name, microtime(true), time(), $this->decay, $this->maxLocks
);
$this->decaysAt = $results[1];
$this->remaining = max(0, $results[2]);
return (bool) $results[0];
}

Copy link
Member

@driesvints driesvints left a comment

Choose a reason for hiding this comment

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

Thanks!

@taylorotwell taylorotwell merged commit 8b49204 into laravel:10.x Oct 9, 2023
20 checks passed
@KentarouTakeda KentarouTakeda deleted the fix-timing-sensitive-flaky-test branch October 9, 2023 14:30
@GrahamCampbell GrahamCampbell changed the title Fix timing sensitive flaky test [10.x] Fix timing sensitive flaky test Oct 9, 2023
timacdonald pushed a commit to timacdonald/framework that referenced this pull request Oct 24, 2023
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.

None yet

3 participants