Skip to content

Commit 866e271

Browse files
authored
Annotate specifically designed slow tests with custom limits (#4698)
1 parent 7eef1f7 commit 866e271

6 files changed

Lines changed: 75 additions & 53 deletions

File tree

tests/system/CLI/CLITest.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
<?php namespace CodeIgniter\CLI;
1+
<?php
2+
3+
namespace CodeIgniter\CLI;
24

35
use CodeIgniter\Test\CIUnitTestCase;
46
use CodeIgniter\Test\Filters\CITestStreamFilter;
57
use ReflectionProperty;
68

7-
class CLITest extends CIUnitTestCase
9+
final class CLITest extends CIUnitTestCase
810
{
911

1012
private $stream_filter;
@@ -40,6 +42,12 @@ public function testBeep4()
4042
CLI::beep(4);
4143
}
4244

45+
/**
46+
* This test waits for 2 seconds before last assertion so this
47+
* is naturally a "slow" test on the perspective of the default limit.
48+
*
49+
* @timeLimit 2.5
50+
*/
4351
public function testWait()
4452
{
4553
$time = time();

tests/system/Cache/Handlers/FileHandlerTest.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@
66
use CodeIgniter\Test\CIUnitTestCase;
77
use Config\Cache;
88

9-
class FileHandlerTest extends CIUnitTestCase
9+
final class FileHandlerTest extends CIUnitTestCase
1010
{
11-
1211
private static $directory = 'FileHandler';
1312
private static $key1 = 'key1';
1413
private static $key2 = 'key2';
@@ -95,6 +94,12 @@ public function testSetDefaultPath()
9594
$this->assertInstanceOf(FileHandler::class, $this->fileHandler);
9695
}
9796

97+
/**
98+
* This test waits for 3 seconds before last assertion so this
99+
* is naturally a "slow" test on the perspective of the default limit.
100+
*
101+
* @timeLimit 3.5
102+
*/
98103
public function testGet()
99104
{
100105
$this->fileHandler->save(self::$key1, 'value', 2);
@@ -106,6 +111,12 @@ public function testGet()
106111
$this->assertNull($this->fileHandler->get(self::$key1));
107112
}
108113

114+
/**
115+
* This test waits for 3 seconds before last assertion so this
116+
* is naturally a "slow" test on the perspective of the default limit.
117+
*
118+
* @timeLimit 3.5
119+
*/
109120
public function testRemember()
110121
{
111122
$this->fileHandler->remember(self::$key1, 2, function () {
@@ -295,8 +306,6 @@ public function modeProvider()
295306
];
296307
}
297308

298-
//--------------------------------------------------------------------
299-
300309
public function testFileHandler()
301310
{
302311
$fileHandler = new BaseTestFileHandler();
@@ -316,7 +325,6 @@ public function testFileHandler()
316325

317326
final class BaseTestFileHandler extends FileHandler
318327
{
319-
320328
private static $directory = 'FileHandler';
321329
private $config;
322330

@@ -344,5 +352,4 @@ public function getFileInfoTest()
344352
'fileperms',
345353
]);
346354
}
347-
348355
}

tests/system/Cache/Handlers/MemcachedHandlerTest.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use Config\Cache;
88
use Exception;
99

10-
class MemcachedHandlerTest extends CIUnitTestCase
10+
final class MemcachedHandlerTest extends CIUnitTestCase
1111
{
1212
private $memcachedHandler;
1313
private static $key1 = 'key1';
@@ -32,10 +32,6 @@ protected function setUp(): void
3232
$this->config = new Cache();
3333

3434
$this->memcachedHandler = new MemcachedHandler($this->config);
35-
if (! $this->memcachedHandler->isSupported())
36-
{
37-
$this->markTestSkipped('Not support memcached and memcache');
38-
}
3935

4036
$this->memcachedHandler->initialize();
4137
}
@@ -53,6 +49,12 @@ public function testNew()
5349
$this->assertInstanceOf(MemcachedHandler::class, $this->memcachedHandler);
5450
}
5551

52+
/**
53+
* This test waits for 3 seconds before last assertion so this
54+
* is naturally a "slow" test on the perspective of the default limit.
55+
*
56+
* @timeLimit 3.5
57+
*/
5658
public function testGet()
5759
{
5860
$this->memcachedHandler->save(self::$key1, 'value', 2);
@@ -64,6 +66,12 @@ public function testGet()
6466
$this->assertNull($this->memcachedHandler->get(self::$key1));
6567
}
6668

69+
/**
70+
* This test waits for 3 seconds before last assertion so this
71+
* is naturally a "slow" test on the perspective of the default limit.
72+
*
73+
* @timeLimit 3.5
74+
*/
6775
public function testRemember()
6876
{
6977
$this->memcachedHandler->remember(self::$key1, 2, function () {

tests/system/Cache/Handlers/PredisHandlerTest.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use CodeIgniter\Test\CIUnitTestCase;
77
use Config\Cache;
88

9-
class PredisHandlerTest extends CIUnitTestCase
9+
final class PredisHandlerTest extends CIUnitTestCase
1010
{
1111
private $PredisHandler;
1212
private static $key1 = 'key1';
@@ -32,10 +32,6 @@ protected function setUp(): void
3232
$this->config = new Cache();
3333

3434
$this->PredisHandler = new PredisHandler($this->config);
35-
if (! $this->PredisHandler->isSupported())
36-
{
37-
$this->markTestSkipped('Not support Predis');
38-
}
3935

4036
$this->PredisHandler->initialize();
4137
}
@@ -61,6 +57,12 @@ public function testDestruct()
6157
$this->assertInstanceOf(PRedisHandler::class, $this->PredisHandler);
6258
}
6359

60+
/**
61+
* This test waits for 3 seconds before last assertion so this
62+
* is naturally a "slow" test on the perspective of the default limit.
63+
*
64+
* @timeLimit 3.5
65+
*/
6466
public function testGet()
6567
{
6668
$this->PredisHandler->save(self::$key1, 'value', 2);
@@ -72,6 +74,12 @@ public function testGet()
7274
$this->assertNull($this->PredisHandler->get(self::$key1));
7375
}
7476

77+
/**
78+
* This test waits for 3 seconds before last assertion so this
79+
* is naturally a "slow" test on the perspective of the default limit.
80+
*
81+
* @timeLimit 3.5
82+
*/
7583
public function testRemember()
7684
{
7785
$this->PredisHandler->remember(self::$key1, 2, function () {

tests/system/Cache/Handlers/RedisHandlerTest.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use CodeIgniter\Test\CIUnitTestCase;
77
use Config\Cache;
88

9-
class RedisHandlerTest extends CIUnitTestCase
9+
final class RedisHandlerTest extends CIUnitTestCase
1010
{
1111
private $redisHandler;
1212
private static $key1 = 'key1';
@@ -32,10 +32,6 @@ protected function setUp(): void
3232
$this->config = new Cache();
3333

3434
$this->redisHandler = new RedisHandler($this->config);
35-
if (! $this->redisHandler->isSupported())
36-
{
37-
$this->markTestSkipped('Not support redis');
38-
}
3935

4036
$this->redisHandler->initialize();
4137
}
@@ -61,6 +57,12 @@ public function testDestruct()
6157
$this->assertInstanceOf(RedisHandler::class, $this->redisHandler);
6258
}
6359

60+
/**
61+
* This test waits for 3 seconds before last assertion so this
62+
* is naturally a "slow" test on the perspective of the default limit.
63+
*
64+
* @timeLimit 3.5
65+
*/
6466
public function testGet()
6567
{
6668
$this->redisHandler->save(self::$key1, 'value', 2);
@@ -72,6 +74,12 @@ public function testGet()
7274
$this->assertNull($this->redisHandler->get(self::$key1));
7375
}
7476

77+
/**
78+
* This test waits for 3 seconds before last assertion so this
79+
* is naturally a "slow" test on the perspective of the default limit.
80+
*
81+
* @timeLimit 3.5
82+
*/
7583
public function testRemember()
7684
{
7785
$this->redisHandler->remember(self::$key1, 2, function () {

tests/system/Debug/TimerTest.php

Lines changed: 13 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,17 @@
11
<?php
2+
23
namespace CodeIgniter\Debug;
34

45
use CodeIgniter\Test\CIUnitTestCase;
56

6-
class TimerTest extends CIUnitTestCase
7+
final class TimerTest extends CIUnitTestCase
78
{
8-
9-
protected function setUp(): void
10-
{
11-
}
12-
13-
//--------------------------------------------------------------------
14-
15-
public function tearDown(): void
16-
{
17-
}
18-
19-
//--------------------------------------------------------------------
20-
219
/**
2210
* We do most of our tests in this one method. While I usually frown
2311
* on this, it's handy here so that we don't stall the tests any
2412
* longer then needed.
13+
*
14+
* @timeLimit 1.5
2515
*/
2616
public function testStoresTimers()
2717
{
@@ -44,8 +34,9 @@ public function testStoresTimers()
4434
$this->assertGreaterThanOrEqual(1.0, $timers['test1']['duration']);
4535
}
4636

47-
//--------------------------------------------------------------------
48-
37+
/**
38+
* @timeLimit 1.5
39+
*/
4940
public function testAutoCalcsTimerEnd()
5041
{
5142
$timer = new Timer();
@@ -59,8 +50,9 @@ public function testAutoCalcsTimerEnd()
5950
$this->assertGreaterThanOrEqual(1.0, $timers['test1']['duration']);
6051
}
6152

62-
//--------------------------------------------------------------------
63-
53+
/**
54+
* @timeLimit 1.5
55+
*/
6456
public function testElapsedTimeGivesSameResultAsTimersArray()
6557
{
6658
$timer = new Timer();
@@ -76,8 +68,6 @@ public function testElapsedTimeGivesSameResultAsTimersArray()
7668
$this->assertEquals($expected, $timer->getElapsedTime('test1'));
7769
}
7870

79-
//--------------------------------------------------------------------
80-
8171
public function testThrowsExceptionStoppingNonTimer()
8272
{
8373
$this->expectException('RunTimeException');
@@ -87,26 +77,23 @@ public function testThrowsExceptionStoppingNonTimer()
8777
$timer->stop('test1');
8878
}
8979

90-
//--------------------------------------------------------------------
91-
9280
public function testLongExecutionTime()
9381
{
9482
$timer = new Timer();
9583
$timer->start('longjohn', strtotime('-11 minutes'));
9684
$this->assertCloseEnough(11 * 60, $timer->getElapsedTime('longjohn'));
9785
}
9886

99-
//--------------------------------------------------------------------
100-
10187
public function testLongExecutionTimeThroughCommonFunc()
10288
{
10389
$timer = new Timer();
10490
$timer->start('longjohn', strtotime('-11 minutes'));
10591
$this->assertCloseEnough(11 * 60, $timer->getElapsedTime('longjohn'));
10692
}
10793

108-
//--------------------------------------------------------------------
109-
94+
/**
95+
* @timeLimit 1.5
96+
*/
11097
public function testCommonStartStop()
11198
{
11299
timer('test1');
@@ -116,14 +103,10 @@ public function testCommonStartStop()
116103
$this->assertGreaterThanOrEqual(1.0, timer()->getElapsedTime('test1'));
117104
}
118105

119-
//--------------------------------------------------------------------
120-
121106
public function testReturnsNullGettingElapsedTimeOfNonTimer()
122107
{
123108
$timer = new Timer();
124109

125110
$this->assertNull($timer->getElapsedTime('test1'));
126111
}
127-
128-
//--------------------------------------------------------------------
129112
}

0 commit comments

Comments
 (0)