forked from llvm/phabricator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPhabricatorMetronomeTestCase.php
61 lines (47 loc) · 1.52 KB
/
PhabricatorMetronomeTestCase.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
final class PhabricatorMetronomeTestCase
extends PhabricatorTestCase {
public function testMetronomeOffsets() {
$cases = array(
'web001.example.net' => 44,
'web002.example.net' => 36,
'web003.example.net' => 25,
'web004.example.net' => 25,
'web005.example.net' => 16,
'web006.example.net' => 26,
'web007.example.net' => 35,
'web008.example.net' => 14,
);
$metronome = id(new PhabricatorMetronome())
->setFrequency(60);
foreach ($cases as $input => $expect) {
$metronome->setOffsetFromSeed($input);
$this->assertEqual(
$expect,
$metronome->getOffset(),
pht('Offset for: %s', $input));
}
}
public function testMetronomeTicks() {
$metronome = id(new PhabricatorMetronome())
->setFrequency(60)
->setOffset(13);
$tick_epoch = strtotime('2000-01-01 11:11:13 AM UTC');
// Since the epoch is at "0:13" on the clock, the metronome should tick
// then.
$this->assertEqual(
$tick_epoch,
$metronome->getNextTickAfter($tick_epoch - 1),
pht('Tick at 11:11:13 AM.'));
// The next tick should be a minute later.
$this->assertEqual(
$tick_epoch + 60,
$metronome->getNextTickAfter($tick_epoch),
pht('Tick at 11:12:13 AM.'));
// There's no tick in the next 59 seconds.
$this->assertFalse(
$metronome->didTickBetween($tick_epoch, $tick_epoch + 59));
$this->assertTrue(
$metronome->didTickBetween($tick_epoch, $tick_epoch + 60));
}
}