aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorBenoit Germain <benoit.germain@ubisoft.com>2024-06-10 11:25:30 +0200
committerBenoit Germain <benoit.germain@ubisoft.com>2024-06-10 11:25:30 +0200
commit770e3c0c533a94631885a4d04d8c36a76d5c185e (patch)
tree8e433365ddebc3e37540a0b43c3aa94d2b78e836 /tests
parente7fa2439c8f328ab146037628bce30894e36a32c (diff)
downloadlanes-770e3c0c533a94631885a4d04d8c36a76d5c185e.tar.gz
lanes-770e3c0c533a94631885a4d04d8c36a76d5c185e.tar.bz2
lanes-770e3c0c533a94631885a4d04d8c36a76d5c185e.zip
Fix track_lanes.lua
Diffstat (limited to 'tests')
-rw-r--r--tests/track_lanes.lua22
1 files changed, 13 insertions, 9 deletions
diff --git a/tests/track_lanes.lua b/tests/track_lanes.lua
index 5ea9a4e..7fd1d2e 100644
--- a/tests/track_lanes.lua
+++ b/tests/track_lanes.lua
@@ -16,7 +16,7 @@ local track = function( title_, expected_count_)
16 print( k, v.name, v.status) 16 print( k, v.name, v.status)
17 count = count + 1 17 count = count + 1
18 end 18 end
19 assert(count == expected_count_, "unexpected active lane count") 19 assert(count == expected_count_, "unexpected active lane count " .. count .. " ~= " .. expected_count_)
20 print( "\n") 20 print( "\n")
21 return threads 21 return threads
22end 22end
@@ -41,39 +41,43 @@ end
41local g = lanes.gen( "*", sleeper) 41local g = lanes.gen( "*", sleeper)
42 42
43-- start a forever-waiting lane (nil timeout) 43-- start a forever-waiting lane (nil timeout)
44g( "forever", 'indefinitely') 44local forever = g( "forever", 'indefinitely')
45 45
46-- start a lane that will last 2 seconds 46-- start a lane that will last 2 seconds
47g( "two_seconds", 2) 47local ephemeral1 = g( "two_seconds", 2)
48 48
49-- give a bit of time to reach the linda waiting call 49-- give a bit of time to reach the linda waiting call
50SLEEP(0.1) 50SLEEP(0.1)
51 51
52-- list the known lanes (should be living lanes) 52-- list the known lanes (both should be living lanes)
53local threads = track( "============= START", 2) 53local threads = track( "============= START", 2)
54-- two_seconds forever 54-- two_seconds forever
55assert(threads[1].status == 'waiting' and threads[2].status == 'waiting') 55assert(threads[1].status == 'waiting' and threads[2].status == 'waiting')
56 56
57-- wait until "two_seconds has completed" 57-- wait until ephemeral1 has completed
58SLEEP(2.1) 58SLEEP(2.1)
59 59
60local threads = track( "============= two_seconds dead", 2) 60local threads = track( "============= two_seconds dead", 2)
61-- two_seconds forever 61-- two_seconds forever
62assert(threads[1].status == 'done' and threads[2].status == 'waiting') 62assert(threads[1].status == 'done' and threads[2].status == 'waiting')
63 63
64-- start another lane that will last 2 seconds, with the same name 64-- start another lane that will last 2 seconds, with the same name
65g( "two_seconds", 2) 65local ephemeral2 = g( "two_seconds", 2)
66 66
67-- give a bit of time to reach the linda waiting call 67-- give a bit of time to reach the linda waiting call
68SLEEP( 0.1) 68SLEEP( 0.1)
69 69
70-- list the known lanes 70-- list the known lanes
71-- unless garbage collector cleaned it, we should have 3 lanes 71-- we should have 3 lanes
72local threads = track( "============= ANOTHER", 3) 72local threads = track( "============= ANOTHER", 3)
73-- two_seconds #2 two_seconds #1 forever 73-- two_seconds #2 two_seconds #1 forever
74assert(threads[1].status == 'waiting' and threads[2].status == 'done' and threads[3].status == 'waiting') 74assert(threads[1].status == 'waiting' and threads[2].status == 'done' and threads[3].status == 'waiting')
75 75
76-- this will collect the completed lane (and remove it from the tracking queue) 76-- this will collect all lane handles.
77-- since ephemeral1 has completed, it is no longer tracked, but the other 2 should still be
78forever = nil
79ephemeral1 = nil
80ephemeral2 = nil
77collectgarbage() 81collectgarbage()
78 82
79-- list the known lanes 83-- list the known lanes