Skip to content

Commit 4dfd3f8

Browse files
jasnymatthiasmullieNyholm
authored
Mark tests that sleep as @Medium (#94)
* Fix expiration tests Setting a +1 second expiration is very unreliable. A +1 second expiration doesn't mean the value will expire "in a second", but "next second". If we're already at 950ms within our second, then by the time "set" and the follow-up "get" go out, we may already be within the next second. As a result, the item will already have been expired and we would no longer be able to find the value. Better to be safe and set +2 seconds (which will give us anywhere between 1 and 2 seconds) Meanwhile also reduced the amount of sleeps: we could manage with only 1 per function. * Mark tests that sleep with `@medium` * Trigger travis Co-authored-by: Matthias Mullie <git@mullie.eu> Co-authored-by: Tobias Nyholm <tobias.nyholm@gmail.com>
1 parent 31c8418 commit 4dfd3f8

2 files changed

Lines changed: 24 additions & 11 deletions

File tree

src/CachePoolTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,9 @@ public function testCommit()
482482
$this->assertTrue($return, 'commit() should return true even if no items were deferred. ');
483483
}
484484

485+
/**
486+
* @medium
487+
*/
485488
public function testExpiration()
486489
{
487490
if (isset($this->skippedTests[__FUNCTION__])) {
@@ -848,6 +851,9 @@ public function testSavingObject()
848851
$this->assertInstanceOf('DateTime', $value, 'You must be able to store objects in cache.');
849852
}
850853

854+
/**
855+
* @medium
856+
*/
851857
public function testHasItemReturnsFalseWhenDeferredItemIsExpired()
852858
{
853859
if (isset($this->skippedTests[__FUNCTION__])) {

src/SimpleCacheTest.php

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -165,21 +165,25 @@ public function testSet()
165165
$this->assertEquals('value', $this->cache->get('key'));
166166
}
167167

168+
/**
169+
* @medium
170+
*/
168171
public function testSetTtl()
169172
{
170173
if (isset($this->skippedTests[__FUNCTION__])) {
171174
$this->markTestSkipped($this->skippedTests[__FUNCTION__]);
172175
}
173176

174-
$result = $this->cache->set('key1', 'value', 1);
177+
$result = $this->cache->set('key1', 'value', 2);
175178
$this->assertTrue($result, 'set() must return true if success');
176179
$this->assertEquals('value', $this->cache->get('key1'));
177-
$this->advanceTime(2);
178-
$this->assertNull($this->cache->get('key1'), 'Value must expire after ttl.');
179180

180-
$this->cache->set('key2', 'value', new \DateInterval('PT1S'));
181+
$this->cache->set('key2', 'value', new \DateInterval('PT2S'));
181182
$this->assertEquals('value', $this->cache->get('key2'));
182-
$this->advanceTime(2);
183+
184+
$this->advanceTime(3);
185+
186+
$this->assertNull($this->cache->get('key1'), 'Value must expire after ttl.');
183187
$this->assertNull($this->cache->get('key2'), 'Value must expire after ttl.');
184188
}
185189

@@ -259,22 +263,25 @@ public function testSetMultipleWithIntegerArrayKey()
259263
$this->assertEquals('value0', $this->cache->get('0'));
260264
}
261265

266+
/**
267+
* @medium
268+
*/
262269
public function testSetMultipleTtl()
263270
{
264271
if (isset($this->skippedTests[__FUNCTION__])) {
265272
$this->markTestSkipped($this->skippedTests[__FUNCTION__]);
266273
}
267274

268-
$this->cache->setMultiple(['key2' => 'value2', 'key3' => 'value3'], 1);
275+
$this->cache->setMultiple(['key2' => 'value2', 'key3' => 'value3'], 2);
269276
$this->assertEquals('value2', $this->cache->get('key2'));
270277
$this->assertEquals('value3', $this->cache->get('key3'));
271-
$this->advanceTime(2);
272-
$this->assertNull($this->cache->get('key2'), 'Value must expire after ttl.');
273-
$this->assertNull($this->cache->get('key3'), 'Value must expire after ttl.');
274278

275-
$this->cache->setMultiple(['key4' => 'value4'], new \DateInterval('PT1S'));
279+
$this->cache->setMultiple(['key4' => 'value4'], new \DateInterval('PT2S'));
276280
$this->assertEquals('value4', $this->cache->get('key4'));
277-
$this->advanceTime(2);
281+
282+
$this->advanceTime(3);
283+
$this->assertNull($this->cache->get('key2'), 'Value must expire after ttl.');
284+
$this->assertNull($this->cache->get('key3'), 'Value must expire after ttl.');
278285
$this->assertNull($this->cache->get('key4'), 'Value must expire after ttl.');
279286
}
280287

0 commit comments

Comments
 (0)