def test_speedChangePropagates(self): mockTime = self.mockTime a = self.newSysClock(tickRate=1000) mockTime.timeNow = 5 a1 = CorrelatedClock(a, tickRate=1000, correlation=Correlation(50, 0)) a2 = CorrelatedClock(a1, tickRate=100, correlation=Correlation(28, 999)) a3 = CorrelatedClock(a2, tickRate=50, correlation=Correlation(5, 1003)) a4 = CorrelatedClock(a3, tickRate=25, correlation=Correlation(1000, 9)) b3 = CorrelatedClock(a2, tickRate=1000, correlation=Correlation(500, 20)) b4 = CorrelatedClock(b3, tickRate=2000, correlation=Correlation(15, 90)) at1, a1t1, a2t1, a3t1, a4t1, b3t1, b4t1 = [ x.ticks for x in [a, a1, a2, a3, a4, b3, b4] ] a3.speed = 0.5 a4.speed = 0.2 self.assertEquals(1.0, a.getEffectiveSpeed()) self.assertEquals(1.0, a1.getEffectiveSpeed()) self.assertEquals(1.0, a2.getEffectiveSpeed()) self.assertEquals(0.5, a3.getEffectiveSpeed()) self.assertEquals(0.1, a4.getEffectiveSpeed()) a3.speed = 0 a4.speed = 1.0 self.assertEquals(1.0, a.getEffectiveSpeed()) self.assertEquals(1.0, a1.getEffectiveSpeed()) self.assertEquals(1.0, a2.getEffectiveSpeed()) self.assertEquals(0.0, a3.getEffectiveSpeed()) self.assertEquals(0.0, a4.getEffectiveSpeed()) mockTime.timeNow = 6 # advance time 1 second at2, a1t2, a2t2, a3t2, a4t2, b3t2, b4t2 = [ x.ticks for x in [a, a1, a2, a3, a4, b3, b4] ] self.assertEquals(at2, at1 + 1000) # a still advances self.assertEquals(a1t2, a1t1 + 1000) # a1 still advances self.assertEquals(a2t2, a2t1 + 100) # a2 still advances self.assertEquals( a3t2, 1003) # a3 is speed zero, is now at the correlation point self.assertEquals( a4t2, 10.5 ) # a4 is speed zero, a3.ticks is 3 ticks from correlation point for a4, translating to 1.5 ticks from a4 correlation point at its tickRate self.assertEquals(b3t2, b3t1 + 1000) # b3 still advances self.assertEquals(b4t2, b4t1 + 2000) # b4 is paused
def makeTSServerObjects(tsServer, wallClock, timelineSelector, tickRate, startTickValue): """\ create a clock with tick rate, and correlated with wall clock to be paused at the intended start value. create a time line source, that uses the wall clock and timeline clock for creating time stamps to be sent by the TS server on demand of the harness (by calling sendTSMessage). attach that time line to the TS server. No messages are sent over TS protocol until client(s) are connected, and only then when sendTSMessage() is called by the harness """ syncClock = CorrelatedClock(parentClock=wallClock, tickRate=tickRate) syncClock.speed = 0 syncClock.correlation = (wallClock.ticks, startTickValue) pauseSyncTimelineClock(syncClock) # Once added to the TS server, the timeline is available for clients to request via the server # for TS messages from this type of timeline, if it exists for the CI stem sent by the TS client. # normally this CI stem matches a substring of the CII-delivered contentId. syncTimelineSrc = SimpleClockTimelineSource( timelineSelector=timelineSelector, wallClock=wallClock, clock=syncClock) tsServer.attachTimelineSource(syncTimelineSrc) return syncClock
def test_speedChangePropagates(self): mockTime = self.mockTime mockTime.timeNow = 5 a = SysClock(tickRate=1000) a1 = CorrelatedClock(a, tickRate=1000, correlation=(50,0)) a2 = CorrelatedClock(a1, tickRate=100, correlation=(28,999)) a3 = CorrelatedClock(a2, tickRate=50, correlation=(5,1003)) a4 = CorrelatedClock(a3, tickRate=25, correlation=(1000,9)) b3 = CorrelatedClock(a2, tickRate=1000, correlation=(500,20)) b4 = CorrelatedClock(b3, tickRate=2000, correlation=(15,90)) at1, a1t1, a2t1, a3t1, a4t1, b3t1, b4t1 = [x.ticks for x in [a,a1,a2,a3,a4,b3,b4]] a3.speed = 0 mockTime.timeNow = 6 # advance time 1 second at2, a1t2, a2t2, a3t2, a4t2, b3t2, b4t2 = [x.ticks for x in [a,a1,a2,a3,a4,b3,b4]] self.assertEquals(at2, at1 + 1000) # a still advances self.assertEquals(a1t2, a1t1 + 1000) # a1 still advances self.assertEquals(a2t2, a2t1 + 100) # a2 still advances self.assertEquals(a3t2, 1003) # a3 is speed zero, is now at the correlation point self.assertEquals(a4t2, 10.5) # a4 is speed zero, a3.ticks is 3 ticks from correlation point for a4, translating to 1.5 ticks from a4 correlation point at its tickRate self.assertEquals(b3t2, b3t1 + 1000) # b3 still advances self.assertEquals(b4t2, b4t1 + 2000) # b4 is paused
def test_quantifyChange(self): a = self.newSysClock() b = CorrelatedClock(a, 1000, correlation=Correlation(0, 0)) self.assertEquals(float('inf'), b.quantifyChange(Correlation(0, 0), 1.01)) self.assertEquals(1.0, b.quantifyChange(Correlation(0, 1000), 1.0)) b.speed = 0.0 self.assertEquals(0.005, b.quantifyChange(Correlation(0, 5), 0.0))
def test_setCorrelationAndSpeed(self): a = self.newSysClock(tickRate=1000000) b = CorrelatedClock(a, 1000, correlation=Correlation(0, 0)) b.speed = 1.0 db = MockDependent() b.bind(db) b.setCorrelationAndSpeed(Correlation(5, 0), 2) db.assertNotificationsEqual([b]) self.assertEqual(b.toParentTicks(10), 5005)
def test_changeSpeedeNotifies(self): """Check a change to the correlation propagates notifications to dependents of this clock""" b = self.newSysClock() c = CorrelatedClock(b, 1000, correlation=Correlation(0, 300)) cc = CorrelatedClock(c, 50) d1 = MockDependent() d2 = MockDependent() d3 = MockDependent() b.bind(d1) c.bind(d2) cc.bind(d3) c.speed = 0.5 d1.assertNotNotified() d2.assertNotificationsEqual([c]) d3.assertNotificationsEqual([cc])
def test_changeSpeedeNotifies(self): """Check a change to the correlation propagates notifications to dependents of this clock""" b = SysClock() c = CorrelatedClock(b, 1000, correlation=(0,300)) cc = CorrelatedClock(c, 50) d1 = MockDependent() d2 = MockDependent() d3 = MockDependent() b.bind(d1) c.bind(d2) cc.bind(d3) c.speed = 0.5 d1.assertNotNotified() d2.assertNotificationsEqual([c]) d3.assertNotificationsEqual([cc])
def test_clockDiff(self): a = self.newSysClock() self.mockTime.timeNow = 1 b = CorrelatedClock(a, 1000, correlation=Correlation(0, 0)) c = CorrelatedClock(b, 2000, correlation=Correlation(0, 0)) d = CorrelatedClock(c, 3000, correlation=Correlation(0, 0)) e = RangeCorrelatedClock(d, 1000, Correlation(5, 0), Correlation(15005, 5000)) self.assertEquals(float('inf'), b.clockDiff(c)) self.assertEquals(float('inf'), b.clockDiff(d)) self.assertAlmostEquals(0.001666667, b.clockDiff(e), delta=0.000001) self.mockTime.timeNow += 10000000 self.assertEquals(float('inf'), b.clockDiff(c)) self.assertEquals(float('inf'), b.clockDiff(d)) self.assertAlmostEquals(0.001666667, b.clockDiff(e), delta=0.000001) c.tickRate = 1000 self.assertEquals(0, b.clockDiff(c)) c.speed = 1.01 self.assertEquals(float('inf'), b.clockDiff(c))