aboutsummaryrefslogtreecommitdiff
path: root/unit_tests/scripts/linda
diff options
context:
space:
mode:
Diffstat (limited to 'unit_tests/scripts/linda')
-rw-r--r--unit_tests/scripts/linda/send_receive_func_and_string.lua13
-rw-r--r--unit_tests/scripts/linda/wake_period.lua5
2 files changed, 16 insertions, 2 deletions
diff --git a/unit_tests/scripts/linda/send_receive_func_and_string.lua b/unit_tests/scripts/linda/send_receive_func_and_string.lua
new file mode 100644
index 0000000..188cfcd
--- /dev/null
+++ b/unit_tests/scripts/linda/send_receive_func_and_string.lua
@@ -0,0 +1,13 @@
1local lanes = require "lanes"
2
3-- a newly created linda doesn't contain anything
4local l = lanes.linda()
5
6-- send a function and a string, make sure that's what we read back
7l:send("k", function() end, "str")
8local c = l:count("k")
9assert(c == 2, "got " .. c)
10local k, v1, v2 = l:receive_batched("k", 2)
11local tv1, tv2 = type(v1), type(v2)
12assert(k == "k" and tv1 == "function" and tv2 == "string", "got " .. tv1 .. " " .. tv2)
13assert(l:count("k") == 0)
diff --git a/unit_tests/scripts/linda/wake_period.lua b/unit_tests/scripts/linda/wake_period.lua
index e4a900d..d2dccc3 100644
--- a/unit_tests/scripts/linda/wake_period.lua
+++ b/unit_tests/scripts/linda/wake_period.lua
@@ -6,7 +6,7 @@ local lanes = require_lanes_result_1
6local body = function(linda_) 6local body = function(linda_)
7 -- a blocking read that lasts longer than the tested wake_period values 7 -- a blocking read that lasts longer than the tested wake_period values
8 linda_:receive(2, "empty_slot") 8 linda_:receive(2, "empty_slot")
9 return true 9 return "done"
10end 10end
11 11
12-- if we don't cancel the lane, we should wait the whole duration 12-- if we don't cancel the lane, we should wait the whole duration
@@ -22,7 +22,8 @@ local function check_wake_duration(linda_, expected_, do_cancel_)
22 assert(result == false and reason == 'timeout', "unexpected cancel result") 22 assert(result == false and reason == 'timeout', "unexpected cancel result")
23 end 23 end
24 -- this should wait until the linda wakes by itself before the actual receive timeout and sees the cancel request 24 -- this should wait until the linda wakes by itself before the actual receive timeout and sees the cancel request
25 h:join() 25 local r, ret = h:join()
26 assert(r == true and ret == "done")
26 local t1 = lanes.now_secs() 27 local t1 = lanes.now_secs()
27 local delta = t1 - t0 28 local delta = t1 - t0
28 -- the linda should check for cancellation at about the expected period, not earlier 29 -- the linda should check for cancellation at about the expected period, not earlier