@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.)
hq.recaptime.dev/wiki/Phorge
phorge
phabricator
1<?php
2
3final class PhabricatorMetronomeTestCase
4 extends PhabricatorTestCase {
5
6 public function testMetronomeOffsets() {
7 $cases = array(
8 'web001.example.net' => 44,
9 'web002.example.net' => 36,
10 'web003.example.net' => 25,
11 'web004.example.net' => 25,
12 'web005.example.net' => 16,
13 'web006.example.net' => 26,
14 'web007.example.net' => 35,
15 'web008.example.net' => 14,
16 );
17
18 $metronome = id(new PhabricatorMetronome())
19 ->setFrequency(60);
20
21 foreach ($cases as $input => $expect) {
22 $metronome->setOffsetFromSeed($input);
23
24 $this->assertEqual(
25 $expect,
26 $metronome->getOffset(),
27 pht('Offset for: %s', $input));
28 }
29 }
30
31 public function testMetronomeTicks() {
32 $metronome = id(new PhabricatorMetronome())
33 ->setFrequency(60)
34 ->setOffset(13);
35
36 $tick_epoch = strtotime('2000-01-01 11:11:13 AM UTC');
37
38 // Since the epoch is at "0:13" on the clock, the metronome should tick
39 // then.
40 $this->assertEqual(
41 $tick_epoch,
42 $metronome->getNextTickAfter($tick_epoch - 1),
43 pht('Tick at 11:11:13 AM.'));
44
45 // The next tick should be a minute later.
46 $this->assertEqual(
47 $tick_epoch + 60,
48 $metronome->getNextTickAfter($tick_epoch),
49 pht('Tick at 11:12:13 AM.'));
50
51
52 // There's no tick in the next 59 seconds.
53 $this->assertFalse(
54 $metronome->didTickBetween($tick_epoch, $tick_epoch + 59));
55
56 $this->assertTrue(
57 $metronome->didTickBetween($tick_epoch, $tick_epoch + 60));
58 }
59
60
61}