diff options
author | Benoit Germain <benoit.germain@ubisoft.com> | 2024-04-11 15:14:52 +0200 |
---|---|---|
committer | Benoit Germain <benoit.germain@ubisoft.com> | 2024-04-11 15:14:52 +0200 |
commit | adaa36dbec1ce9aaafd61873b9d3d898a8c240cf (patch) | |
tree | 4c81e8f5983c3d696a636e2cc433ce7c0a9c3dd8 /tests/keeper.lua | |
parent | 1d310e6ecb6e156598337612f16573d9cd284f5e (diff) | |
download | lanes-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.lua | 63 |
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 | ||
7 | local lanes = require "lanes".configure{ with_timers = false, nb_keepers = 200} | 7 | local lanes = require "lanes".configure{ with_timers = false, nb_keepers = 1, keepers_gc_threshold = 500} |
8 | |||
9 | do | ||
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 | ||
25 | end | ||
26 | print "collecting garbage" | ||
27 | collectgarbage() | ||
28 | print "GC deadlock test done" | ||
29 | |||
30 | local print_id = 0 | ||
31 | local PRINT = function(...) | ||
32 | print_id = print_id + 1 | ||
33 | print("main", print_id .. ".", ...) | ||
34 | end | ||
8 | 35 | ||
9 | local function keeper(linda) | 36 | local function keeper(linda) |
10 | local mt= { | 37 | local mt= { |
@@ -25,23 +52,49 @@ local A= keeper( lindaA ) | |||
25 | local lindaB= lanes.linda( "B", 2) | 52 | local lindaB= lanes.linda( "B", 2) |
26 | local B= keeper( lindaB ) | 53 | local B= keeper( lindaB ) |
27 | 54 | ||
55 | local lindaC= lanes.linda( "C", 3) | ||
56 | local C= keeper( lindaC ) | ||
57 | print("Created", lindaA, lindaB, lindaC) | ||
58 | |||
28 | A.some= 1 | 59 | A.some= 1 |
29 | print( A.some ) | 60 | PRINT("A.some == " .. A.some ) |
30 | assert( A.some==1 ) | 61 | assert( A.some==1 ) |
31 | 62 | ||
32 | B.some= "hoo" | 63 | B.some= "hoo" |
64 | PRINT("B.some == " .. B.some ) | ||
33 | assert( B.some=="hoo" ) | 65 | assert( B.some=="hoo" ) |
34 | assert( A.some==1 ) | 66 | assert( A.some==1 ) |
67 | assert( C.some==nil ) | ||
35 | 68 | ||
36 | function lane() | 69 | function 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) | ||
41 | end | 89 | end |
42 | 90 | ||
91 | PRINT("lane started") | ||
43 | local h= lanes.gen( "io", lane )() | 92 | local h= lanes.gen( "io", lane )() |
44 | h:join() | 93 | PRINT("lane joined:", h:join()) |
45 | 94 | ||
46 | print( A.some ) -- 2 | 95 | PRINT("A.some = " .. A.some ) |
47 | assert( A.some==2 ) | 96 | assert( A.some==2 ) |
97 | PRINT("C.some = " .. C.some ) | ||
98 | assert( C.some==3 ) | ||
99 | lindaC:set("some") | ||
100 | assert( C.some==nil ) \ No newline at end of file | ||