diff options
author | Benoit Germain <benoit.germain@ubisoft.com> | 2024-06-10 11:25:30 +0200 |
---|---|---|
committer | Benoit Germain <benoit.germain@ubisoft.com> | 2024-06-10 11:25:30 +0200 |
commit | 770e3c0c533a94631885a4d04d8c36a76d5c185e (patch) | |
tree | 8e433365ddebc3e37540a0b43c3aa94d2b78e836 | |
parent | e7fa2439c8f328ab146037628bce30894e36a32c (diff) | |
download | lanes-770e3c0c533a94631885a4d04d8c36a76d5c185e.tar.gz lanes-770e3c0c533a94631885a4d04d8c36a76d5c185e.tar.bz2 lanes-770e3c0c533a94631885a4d04d8c36a76d5c185e.zip |
Fix track_lanes.lua
-rw-r--r-- | tests/track_lanes.lua | 22 |
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 |
22 | end | 22 | end |
@@ -41,39 +41,43 @@ end | |||
41 | local g = lanes.gen( "*", sleeper) | 41 | local g = lanes.gen( "*", sleeper) |
42 | 42 | ||
43 | -- start a forever-waiting lane (nil timeout) | 43 | -- start a forever-waiting lane (nil timeout) |
44 | g( "forever", 'indefinitely') | 44 | local forever = g( "forever", 'indefinitely') |
45 | 45 | ||
46 | -- start a lane that will last 2 seconds | 46 | -- start a lane that will last 2 seconds |
47 | g( "two_seconds", 2) | 47 | local 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 |
50 | SLEEP(0.1) | 50 | SLEEP(0.1) |
51 | 51 | ||
52 | -- list the known lanes (should be living lanes) | 52 | -- list the known lanes (both should be living lanes) |
53 | local threads = track( "============= START", 2) | 53 | local threads = track( "============= START", 2) |
54 | -- two_seconds forever | 54 | -- two_seconds forever |
55 | assert(threads[1].status == 'waiting' and threads[2].status == 'waiting') | 55 | assert(threads[1].status == 'waiting' and threads[2].status == 'waiting') |
56 | 56 | ||
57 | -- wait until "two_seconds has completed" | 57 | -- wait until ephemeral1 has completed |
58 | SLEEP(2.1) | 58 | SLEEP(2.1) |
59 | 59 | ||
60 | local threads = track( "============= two_seconds dead", 2) | 60 | local threads = track( "============= two_seconds dead", 2) |
61 | -- two_seconds forever | 61 | -- two_seconds forever |
62 | assert(threads[1].status == 'done' and threads[2].status == 'waiting') | 62 | assert(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 |
65 | g( "two_seconds", 2) | 65 | local 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 |
68 | SLEEP( 0.1) | 68 | SLEEP( 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 |
72 | local threads = track( "============= ANOTHER", 3) | 72 | local threads = track( "============= ANOTHER", 3) |
73 | -- two_seconds #2 two_seconds #1 forever | 73 | -- two_seconds #2 two_seconds #1 forever |
74 | assert(threads[1].status == 'waiting' and threads[2].status == 'done' and threads[3].status == 'waiting') | 74 | assert(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 | ||
78 | forever = nil | ||
79 | ephemeral1 = nil | ||
80 | ephemeral2 = nil | ||
77 | collectgarbage() | 81 | collectgarbage() |
78 | 82 | ||
79 | -- list the known lanes | 83 | -- list the known lanes |