diff options
Diffstat (limited to 'stdlib/source/test/lux/control/concurrency/semaphore.lux')
-rw-r--r-- | stdlib/source/test/lux/control/concurrency/semaphore.lux | 132 |
1 files changed, 66 insertions, 66 deletions
diff --git a/stdlib/source/test/lux/control/concurrency/semaphore.lux b/stdlib/source/test/lux/control/concurrency/semaphore.lux index d1077ae53..1e6dd9a48 100644 --- a/stdlib/source/test/lux/control/concurrency/semaphore.lux +++ b/stdlib/source/test/lux/control/concurrency/semaphore.lux @@ -41,56 +41,56 @@ (do {! random.monad} [initial_open_positions (|> random.nat (\ ! map (|>> (n.% 10) (n.max 1)))) #let [semaphore (/.semaphore initial_open_positions)]] - (wrap (do async.monad - [result (async.time_out ..delay (/.wait semaphore))] - (_.cover' [/.semaphore] - (case result - (#.Some _) - true + (in (do async.monad + [result (async.time_out ..delay (/.wait semaphore))] + (_.cover' [/.semaphore] + (case result + (#.Some _) + true - #.None - false))))) + #.None + false))))) (do {! random.monad} [initial_open_positions (|> random.nat (\ ! map (|>> (n.% 10) (n.max 1)))) #let [semaphore (/.semaphore initial_open_positions)]] - (wrap (do {! async.monad} - [_ (monad.map ! /.wait (list.repeat initial_open_positions semaphore)) - result (async.time_out ..delay (/.wait semaphore))] - (_.cover' [/.wait] - (case result - (#.Some _) - false + (in (do {! async.monad} + [_ (monad.map ! /.wait (list.repeat initial_open_positions semaphore)) + result (async.time_out ..delay (/.wait semaphore))] + (_.cover' [/.wait] + (case result + (#.Some _) + false - #.None - true))))) + #.None + true))))) (do {! random.monad} [initial_open_positions (|> random.nat (\ ! map (|>> (n.% 10) (n.max 1)))) #let [semaphore (/.semaphore initial_open_positions)]] - (wrap (do {! async.monad} - [_ (monad.map ! /.wait (list.repeat initial_open_positions semaphore)) - #let [block (/.wait semaphore)] - result/0 (async.time_out ..delay block) - open_positions (/.signal semaphore) - result/1 (async.time_out ..delay block)] - (_.cover' [/.signal] - (case [result/0 result/1 open_positions] - [#.None (#.Some _) (#try.Success +0)] - true + (in (do {! async.monad} + [_ (monad.map ! /.wait (list.repeat initial_open_positions semaphore)) + #let [block (/.wait semaphore)] + result/0 (async.time_out ..delay block) + open_positions (/.signal semaphore) + result/1 (async.time_out ..delay block)] + (_.cover' [/.signal] + (case [result/0 result/1 open_positions] + [#.None (#.Some _) (#try.Success +0)] + true - _ - false))))) + _ + false))))) (do {! random.monad} [initial_open_positions (|> random.nat (\ ! map (|>> (n.% 10) (n.max 1)))) #let [semaphore (/.semaphore initial_open_positions)]] - (wrap (do async.monad - [outcome (/.signal semaphore)] - (_.cover' [/.semaphore_is_maxed_out] - (case outcome - (#try.Failure error) - (exception.match? /.semaphore_is_maxed_out error) + (in (do async.monad + [outcome (/.signal semaphore)] + (_.cover' [/.semaphore_is_maxed_out] + (case outcome + (#try.Failure error) + (exception.match? /.semaphore_is_maxed_out error) - _ - false))))) + _ + false))))) ))) (def: mutex @@ -110,7 +110,7 @@ [_ (<| (monad.seq !) (list.repeat repetitions) (atom.update (|>> (format "A")) resource))] - (wrap []))) + (in []))) processB (<| (/.synchronize mutex) io.io async.future @@ -118,16 +118,16 @@ [_ (<| (monad.seq !) (list.repeat repetitions) (atom.update (|>> (format "B")) resource))] - (wrap [])))]] - (wrap (do async.monad - [_ processA - _ processB - #let [outcome (io.run (atom.read resource))]] - (_.cover' [/.mutex /.synchronize] - (or (text\= (format expected_As expected_Bs) - outcome) - (text\= (format expected_Bs expected_As) - outcome)))))) + (in [])))]] + (in (do async.monad + [_ processA + _ processB + #let [outcome (io.run (atom.read resource))]] + (_.cover' [/.mutex /.synchronize] + (or (text\= (format expected_As expected_Bs) + outcome) + (text\= (format expected_Bs expected_As) + outcome)))))) ))) (def: (waiter resource barrier id) @@ -135,7 +135,7 @@ (do async.monad [_ (/.block barrier) _ (async.future (atom.update (|>> (format (%.nat id))) resource))] - (wrap []))) + (in []))) (def: barrier Test @@ -158,23 +158,23 @@ [limit (\ ! map (|>> (n.% 9) inc) random.nat) #let [barrier (/.barrier (maybe.assume (/.limit limit))) resource (atom.atom "")]] - (wrap (do {! async.monad} - [#let [suffix "_" - expected_ending (|> suffix - (list.repeat limit) - (text.join_with "")) - expected_ids (enum.range n.enum 0 (dec limit))] - _ (|> expected_ids - (list\map (function (_ id) - (exec (io.run (atom.update (|>> (format suffix)) resource)) - (waiter resource barrier id)))) - (monad.seq !)) - #let [outcome (io.run (atom.read resource))]] - (_.cover' [/.barrier /.block] - (and (text.ends_with? expected_ending outcome) - (list.every? (function (_ id) - (text.contains? (%.nat id) outcome)) - expected_ids)))))) + (in (do {! async.monad} + [#let [suffix "_" + expected_ending (|> suffix + (list.repeat limit) + (text.join_with "")) + expected_ids (enum.range n.enum 0 (dec limit))] + _ (|> expected_ids + (list\map (function (_ id) + (exec (io.run (atom.update (|>> (format suffix)) resource)) + (waiter resource barrier id)))) + (monad.seq !)) + #let [outcome (io.run (atom.read resource))]] + (_.cover' [/.barrier /.block] + (and (text.ends_with? expected_ending outcome) + (list.every? (function (_ id) + (text.contains? (%.nat id) outcome)) + expected_ids)))))) ))) (def: #export test |