Skip to content

Commit c5bad52

Browse files
committed
resolve review
1 parent f0ff844 commit c5bad52

File tree

1 file changed

+22
-22
lines changed

1 file changed

+22
-22
lines changed

tests/drivers/redis/QueueTest.php

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ protected function tearDown()
139139
parent::tearDown();
140140
}
141141

142-
public function testMoveExpired()
142+
public function testConsumeMsgAtLeastOnce()
143143
{
144144
$job = $this->createSimpleJob();
145145
$this->getQueue()->delay(1)->push($job);
@@ -149,28 +149,28 @@ public function testMoveExpired()
149149
$msgCount++;
150150
};
151151

152-
$fault = function () {
153-
sleep(2);
154-
$mockRedis = Instance::ensure([
155-
'class' => RedisCrashMock::class,
156-
'hostname' => getenv('REDIS_HOST') ?: 'localhost',
157-
'database' => getenv('REDIS_DB') ?: 1,
158-
], 'yii\redis\Connection');
159-
160-
$queue = $this->getQueue();
161-
$old = $queue->redis;
162-
$queue->redis = $mockRedis;
163-
164-
try {
165-
$queue->run(false);
166-
}catch (\Exception $e){
167-
}finally{
168-
$queue->redis = $old;
169-
}
170-
};
171-
$fault();
152+
//ensuer the delayed msg can be consumed
153+
sleep(2);
172154

173-
//make the redlock invalid after 1s
155+
//based on the implemention, emulate a crash when redis "rpush" command should be execute
156+
$mockRedis = Instance::ensure([
157+
'class' => RedisCrashMock::class,
158+
'hostname' => getenv('REDIS_HOST') ?: 'localhost',
159+
'database' => getenv('REDIS_DB') ?: 1,
160+
], 'yii\redis\Connection');
161+
162+
$queue = $this->getQueue();
163+
$old = $queue->redis;
164+
$queue->redis = $mockRedis;
165+
166+
try {
167+
$queue->run(false);
168+
}catch (\Exception $e){
169+
}finally{
170+
$queue->redis = $old;
171+
}
172+
173+
//ensure the redlock invalid after 1s
174174
sleep(2);
175175
$this->getQueue()->run(false);
176176
$this->assertEquals(1, $msgCount);

0 commit comments

Comments
 (0)