aboutsummaryrefslogtreecommitdiff
path: root/tests/timer.lua
diff options
context:
space:
mode:
Diffstat (limited to 'tests/timer.lua')
-rw-r--r--tests/timer.lua12
1 files changed, 7 insertions, 5 deletions
diff --git a/tests/timer.lua b/tests/timer.lua
index ec23cee..73ecb93 100644
--- a/tests/timer.lua
+++ b/tests/timer.lua
@@ -18,13 +18,14 @@ end
18 18
19local T1= "1s" -- these keys can be anything... 19local T1= "1s" -- these keys can be anything...
20local T2= "5s" 20local T2= "5s"
21local PING_DURATION = 20
21 22
22local step= {} 23local step= {}
23 24
24lanes.timer( linda, T1, 1.0, 1.0 ) 25lanes.timer( linda, T1, 1.0, 1.0 )
25step[T1]= 1.0 26step[T1]= 1.0
26 27
27PRINT( "\n*** Timers every second (not synced to wall clock) ***\n" ) 28PRINT( "\n*** Starting 1s Timer (not synced to wall clock) ***\n" )
28 29
29local v_first 30local v_first
30local v_last= {} -- { [channel]= num } 31local v_last= {} -- { [channel]= num }
@@ -46,14 +47,15 @@ while true do
46 -- do not make measurements, first round is not 5secs due to wall clock adjustment 47 -- do not make measurements, first round is not 5secs due to wall clock adjustment
47 T2_first_round= false 48 T2_first_round= false
48 else 49 else
49 assert( math.abs(v-v_last[channel]- step[channel]) < 0.02 ) 50 local dt = math.abs(v-v_last[channel]- step[channel])
51 assert( dt < 0.02, "channel " .. channel .. " is late: " .. dt)
50 end 52 end
51 end 53 end
52 54
53 if not v_first then 55 if not v_first then
54 v_first= v 56 v_first= v
55 elseif v-v_first > 3.0 and (not step[T2]) then 57 elseif v-v_first > 3.0 and (not step[T2]) then
56 PRINT( "\n*** Adding timers every 5 second (synced to wall clock) ***\n" ) 58 PRINT( "\n*** Starting 5s timer (synced to wall clock) ***\n" )
57 59
58 -- The first event can be in the past (just cut seconds down to 5s) 60 -- The first event can be in the past (just cut seconds down to 5s)
59 -- 61 --
@@ -63,7 +65,7 @@ while true do
63 lanes.timer( linda, T2, date, 5.0 ) 65 lanes.timer( linda, T2, date, 5.0 )
64 step[T2]= 5.0 66 step[T2]= 5.0
65 67
66 elseif v-v_first > 10 then -- exit condition 68 elseif v-v_first > PING_DURATION then -- exit condition
67 break 69 break
68 end 70 end
69 v_last[channel]= v 71 v_last[channel]= v
@@ -80,7 +82,7 @@ PRINT( "\n*** Listing timers ***\n" )
80local r = lanes.timers() -- list of {linda, key, {}} 82local r = lanes.timers() -- list of {linda, key, {}}
81for _,t in ipairs( r) do 83for _,t in ipairs( r) do
82 local linda, key, timer = t[1], t[2], t[3] 84 local linda, key, timer = t[1], t[2], t[3]
83 print( tostring( linda), key, timer[1], timer[2]) 85 print( tostring( linda), key, timer[1], timer[2])
84end 86end
85 87
86 88