Path: blob/master/src/infrastructure/util/__tests__/PhabricatorMetronomeTestCase.php
12242 views
<?php12final class PhabricatorMetronomeTestCase3extends PhabricatorTestCase {45public function testMetronomeOffsets() {6$cases = array(7'web001.example.net' => 44,8'web002.example.net' => 36,9'web003.example.net' => 25,10'web004.example.net' => 25,11'web005.example.net' => 16,12'web006.example.net' => 26,13'web007.example.net' => 35,14'web008.example.net' => 14,15);1617$metronome = id(new PhabricatorMetronome())18->setFrequency(60);1920foreach ($cases as $input => $expect) {21$metronome->setOffsetFromSeed($input);2223$this->assertEqual(24$expect,25$metronome->getOffset(),26pht('Offset for: %s', $input));27}28}2930public function testMetronomeTicks() {31$metronome = id(new PhabricatorMetronome())32->setFrequency(60)33->setOffset(13);3435$tick_epoch = strtotime('2000-01-01 11:11:13 AM UTC');3637// Since the epoch is at "0:13" on the clock, the metronome should tick38// then.39$this->assertEqual(40$tick_epoch,41$metronome->getNextTickAfter($tick_epoch - 1),42pht('Tick at 11:11:13 AM.'));4344// The next tick should be a minute later.45$this->assertEqual(46$tick_epoch + 60,47$metronome->getNextTickAfter($tick_epoch),48pht('Tick at 11:12:13 AM.'));495051// There's no tick in the next 59 seconds.52$this->assertFalse(53$metronome->didTickBetween($tick_epoch, $tick_epoch + 59));5455$this->assertTrue(56$metronome->didTickBetween($tick_epoch, $tick_epoch + 60));57}585960}616263