Skip to content

Commit be64a52

Browse files
committed
Replace timeout on multiple setTimout calls
1 parent e83a820 commit be64a52

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/AsyncTestCase.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,10 @@ final protected function setTimeout(int $timeout)
196196
{
197197
$this->timeout = $timeout;
198198

199+
if (isset($this->timeoutId)) {
200+
Loop::cancel($this->timeoutId);
201+
}
202+
199203
$this->timeoutId = Loop::delay($timeout, function () use ($timeout) {
200204
Loop::stop();
201205
Loop::setErrorHandler(null);

test/AsyncTestCaseTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,16 @@ public function testSetTimeout(): \Generator
121121
$this->assertNull(yield delay(250));
122122
}
123123

124+
public function testSetTimeoutReplace(): \Generator
125+
{
126+
$this->setTimeout(500);
127+
$this->setTimeout(1000);
128+
129+
yield delay(750);
130+
131+
$this->expectNotToPerformAssertions();
132+
}
133+
124134
public function testSetTimeoutWithCoroutine(): \Generator
125135
{
126136
$this->setTimeout(100);

0 commit comments

Comments
 (0)