Skip to content

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

Merged
taylorotwell merged 1 commit into
laravel:10.xfrom
KentarouTakeda:fix-timing-sensitive-flaky-test
Oct 9, 2023
Merged

taylorotwell merged 1 commit into
laravel:10.xfrom
KentarouTakeda:fix-timing-sensitive-flaky-test

Conversation

@KentarouTakeda

Copy link
Copy Markdown
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];
}

@KentarouTakeda
KentarouTakeda force-pushed the fix-timing-sensitive-flaky-test branch from 9a6d146 to 9de304b Compare October 7, 2023 09:54

@driesvints driesvints left a comment

Copy link
Copy Markdown
Member

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
@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.

3 participants