From 770e3c0c533a94631885a4d04d8c36a76d5c185e Mon Sep 17 00:00:00 2001 From: Benoit Germain Date: Mon, 10 Jun 2024 11:25:30 +0200 Subject: Fix track_lanes.lua --- tests/track_lanes.lua | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'tests') 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_) print( k, v.name, v.status) count = count + 1 end - assert(count == expected_count_, "unexpected active lane count") + assert(count == expected_count_, "unexpected active lane count " .. count .. " ~= " .. expected_count_) print( "\n") return threads end @@ -41,39 +41,43 @@ end local g = lanes.gen( "*", sleeper) -- start a forever-waiting lane (nil timeout) -g( "forever", 'indefinitely') +local forever = g( "forever", 'indefinitely') -- start a lane that will last 2 seconds -g( "two_seconds", 2) +local ephemeral1 = g( "two_seconds", 2) -- give a bit of time to reach the linda waiting call SLEEP(0.1) --- list the known lanes (should be living lanes) +-- list the known lanes (both should be living lanes) local threads = track( "============= START", 2) -- two_seconds forever assert(threads[1].status == 'waiting' and threads[2].status == 'waiting') --- wait until "two_seconds has completed" +-- wait until ephemeral1 has completed SLEEP(2.1) local threads = track( "============= two_seconds dead", 2) --- two_seconds forever +-- two_seconds forever assert(threads[1].status == 'done' and threads[2].status == 'waiting') -- start another lane that will last 2 seconds, with the same name -g( "two_seconds", 2) +local ephemeral2 = g( "two_seconds", 2) -- give a bit of time to reach the linda waiting call SLEEP( 0.1) -- list the known lanes --- unless garbage collector cleaned it, we should have 3 lanes +-- we should have 3 lanes local threads = track( "============= ANOTHER", 3) -- two_seconds #2 two_seconds #1 forever assert(threads[1].status == 'waiting' and threads[2].status == 'done' and threads[3].status == 'waiting') --- this will collect the completed lane (and remove it from the tracking queue) +-- this will collect all lane handles. +-- since ephemeral1 has completed, it is no longer tracked, but the other 2 should still be +forever = nil +ephemeral1 = nil +ephemeral2 = nil collectgarbage() -- list the known lanes -- cgit v1.2.3-55-g6feb