8000 Make usleep longer and simplify assertions · symfony/symfony@beae3b1 · GitHub
[go: up one dir, main page]

Skip to content

Commit beae3b1

Browse files
brikoufabpot
authored andcommitted
Make usleep longer and simplify assertions
1 parent 879305e commit beae3b1

File tree

2 files changed

+22
-25
lines changed

2 files changed

+22
-25
lines changed

src/Symfony/Component/Stopwatch/Tests/StopwatchEventTest.php

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
*/
2121
class StopwatchEventTest extends \PHPUnit_Framework_TestCase
2222
{
23+
const DELTA = 20;
24+
2325
public function testGetOrigin()
2426
{
2527
$event = new StopwatchEvent(12);
@@ -66,20 +68,18 @@ public function testDuration()
6668
{
6769
$event = new StopwatchEvent(microtime(true) * 1000);
6870
$event->start();
69-
usleep(20000);
71+
usleep(200000);
7072
$event->stop();
71-
$total = $event->getDuration();
72-
$this->assertTrue($total >= 11 && $total <= 29, $total.' should be 20 (between 11 and 29)');
73+
$this->assertEquals(200, $event->getDuration(), null, self::DELTA);
7374

7475
$event = new StopwatchEvent(microtime(true) * 1000);
7576
$event->start();
76-
usleep(10000);
77+
usleep(100000);
7778
$event->stop();
7879
$event->start();
79-
usleep(10000);
80+
usleep(100000);
8081
$event->stop();
81-
$total = $event->getDuration();
82-
$this->assertTrue($total >= 11 && $total <= 29, $total.' should be 20 (between 11 and 29)');
82+
$this->assertEquals(200, $event->getDuration(), null, self::DELTA);
8383
}
8484

8585
/**
@@ -96,12 +96,11 @@ public function testEnsureStopped()
9696
// this also test overlap between two periods
9797
$event = new StopwatchEvent(microtime(true) * 1000);
9898
$event->start();
99-
usleep(10000);
99+
usleep(100000);
100100
$event->start();
101-
usleep(10000);
101+
usleep(100000);
102102
$event->ensureStopped();
103-
$total = $event->getDuration();
104-
$this->assertTrue($total >= 21 && $total <= 39, $total.' should be 30 (between 21 and 39)');
103+
$this->assertEquals(300, $event->getDuration(), null, self::DELTA);
105104
}
106105

107106
public function testStartTime()
@@ -116,10 +115,9 @@ public function testStartTime()
116115

117116
$event = new StopwatchEvent(microtime(true) * 1000);
118117
$event->start();
119-
usleep(10000);
118+
usleep(100000);
120119
$event->stop();
121-
$start = $event->getStartTime();
122-
$this->assertTrue($start >= 0 && $start <= 20);
120+
$this->assertEquals(0, $event->getStartTime(), null, self::DELTA);
123121
}
124122

125123
public function testEndTime()
@@ -133,13 +131,12 @@ public function testEndTime()
133131

134132
$event = new StopwatchEvent(microtime(true) * 1000);
135133
$event->start();
136-
usleep(10000);
134+
usleep(100000);
137135
$event->stop();
138136
$event->start();
139-
usleep(10000);
137+
usleep(100000);
140138
$event->stop();
141-
$end = $event->getEndTime();
142-
$this->assertTrue($end >= 11 && $end <= 29, $end.' should be 20 (between 11 and 29)');
139+
$this->assertEquals(200, $event->getEndTime(), null, self::DELTA);
143140
}
144141

145142
/**

src/Symfony/Component/Stopwatch/Tests/StopwatchTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
*/
2121
class StopwatchTest extends \PHPUnit_Framework_TestCase
2222
{
23+
const DELTA = 20;
24+
2325
public function testStart()
2426
{
2527
$stopwatch = new Stopwatch();
@@ -33,26 +35,24 @@ public function testStop()
3335
{
3436
$stopwatch = new Stopwatch();
3537
$stopwatch->start('foo', 'cat');
36-
usleep(20000);
38+
usleep(200000);
3739
$event = $stopwatch->stop('foo');
3840

3941
$this->assertInstanceof('Symfony\Component\Stopwatch\StopwatchEvent', $event);
40-
$total = $event->getDuration();
41-
$this->assertTrue($total > 10 && $total <= 29, $total.' should be 20 (between 10 and 29)');
42+
$this->assertEquals(200, $event->getDuration(), null, self::DELTA);
4243
}
4344

4445
public function testLap()
4546
{
4647
$stopwatch = new Stopwatch();
4748
$stopwatch->start('foo', 'cat');
48-
usleep(10000);
49+
usleep(100000);
4950
$event = $stopwatch->lap('foo');
50-
usleep(10000);
51+
usleep(100000);
5152
$stopwatch->stop('foo');
5253

5354
$this->assertInstanceof('Symfony\Component\Stopwatch\StopwatchEvent', $event);
54-
$total = $event->getDuration();
55-
$this->assertTrue($total > 10 && $total <= 29, $total.' should be 20 (between 10 and 29)');
55+
$this->assertEquals(200, $event->getDuration(), null, self::DELTA);
5656
}
5757

5858
/**

0 commit comments

Comments
 (0)
0