aboutsummaryrefslogtreecommitdiff
path: root/tests/keeper.lua
diff options
context:
space:
mode:
authorBenoit Germain <benoit.germain@ubisoft.com>2024-04-11 15:14:52 +0200
committerBenoit Germain <benoit.germain@ubisoft.com>2024-04-11 15:14:52 +0200
commitadaa36dbec1ce9aaafd61873b9d3d898a8c240cf (patch)
tree4c81e8f5983c3d696a636e2cc433ce7c0a9c3dd8 /tests/keeper.lua
parent1d310e6ecb6e156598337612f16573d9cd284f5e (diff)
downloadlanes-adaa36dbec1ce9aaafd61873b9d3d898a8c240cf.tar.gz
lanes-adaa36dbec1ce9aaafd61873b9d3d898a8c240cf.tar.bz2
lanes-adaa36dbec1ce9aaafd61873b9d3d898a8c240cf.zip
Bring all interesting fixes from the C++ implementation back into the C implementation
Diffstat (limited to 'tests/keeper.lua')
-rw-r--r--tests/keeper.lua63
1 files changed, 58 insertions, 5 deletions
diff --git a/tests/keeper.lua b/tests/keeper.lua
index f8c915d..3333938 100644
--- a/tests/keeper.lua
+++ b/tests/keeper.lua
@@ -4,7 +4,34 @@
4-- Test program for Lua Lanes 4-- Test program for Lua Lanes
5-- 5--
6 6
7local lanes = require "lanes".configure{ with_timers = false, nb_keepers = 200} 7local lanes = require "lanes".configure{ with_timers = false, nb_keepers = 1, keepers_gc_threshold = 500}
8
9do
10 print "Linda names test:"
11 local unnamedLinda = lanes.linda()
12 local unnamedLinda2 = lanes.linda("")
13 local veeeerrrryyyylooongNamedLinda= lanes.linda( "veeeerrrryyyylooongNamedLinda", 1)
14 print(unnamedLinda, unnamedLinda2, veeeerrrryyyylooongNamedLinda)
15 print "GC deadlock test start"
16 -- store a linda in another linda (-> in a keeper)
17 unnamedLinda:set("here", lanes.linda("temporary linda"))
18 -- repeatedly add and remove stuff in the linda so that a GC happens during the keeper operation
19 for i = 1, 1000 do
20 for j = 1, 1000 do -- send 1000 tables
21 unnamedLinda:send("here", {"a", "table", "with", "some", "stuff"})
22 end
23 unnamedLinda:set("here") -- clear everything
24 end
25end
26print "collecting garbage"
27collectgarbage()
28print "GC deadlock test done"
29
30local print_id = 0
31local PRINT = function(...)
32 print_id = print_id + 1
33 print("main", print_id .. ".", ...)
34end
8 35
9local function keeper(linda) 36local function keeper(linda)
10 local mt= { 37 local mt= {
@@ -25,23 +52,49 @@ local A= keeper( lindaA )
25local lindaB= lanes.linda( "B", 2) 52local lindaB= lanes.linda( "B", 2)
26local B= keeper( lindaB ) 53local B= keeper( lindaB )
27 54
55local lindaC= lanes.linda( "C", 3)
56local C= keeper( lindaC )
57print("Created", lindaA, lindaB, lindaC)
58
28A.some= 1 59A.some= 1
29print( A.some ) 60PRINT("A.some == " .. A.some )
30assert( A.some==1 ) 61assert( A.some==1 )
31 62
32B.some= "hoo" 63B.some= "hoo"
64PRINT("B.some == " .. B.some )
33assert( B.some=="hoo" ) 65assert( B.some=="hoo" )
34assert( A.some==1 ) 66assert( A.some==1 )
67assert( C.some==nil )
35 68
36function lane() 69function lane()
70 local print_id = 0
71 local PRINT = function(...)
72 print_id = print_id + 1
73 print("lane", print_id .. ".", ...)
74 end
75
37 local a= keeper(lindaA) 76 local a= keeper(lindaA)
38 print( a.some ) 77 PRINT("a.some == " .. a.some )
39 assert( a.some==1 ) 78 assert( a.some==1 )
40 a.some= 2 79 a.some= 2
80 assert( a.some==2 )
81 PRINT("a.some == " .. a.some )
82
83 local c = keeper(lindaC)
84 assert( c.some==nil )
85 PRINT("c.some == " .. tostring(c.some))
86 c.some= 3
87 assert( c.some==3 )
88 PRINT("c.some == " .. c.some)
41end 89end
42 90
91PRINT("lane started")
43local h= lanes.gen( "io", lane )() 92local h= lanes.gen( "io", lane )()
44h:join() 93PRINT("lane joined:", h:join())
45 94
46print( A.some ) -- 2 95PRINT("A.some = " .. A.some )
47assert( A.some==2 ) 96assert( A.some==2 )
97PRINT("C.some = " .. C.some )
98assert( C.some==3 )
99lindaC:set("some")
100assert( C.some==nil ) \ No newline at end of file