diff options
Diffstat (limited to 'stdlib/source/test/lux/world/net/udp.lux')
-rw-r--r-- | stdlib/source/test/lux/world/net/udp.lux | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/stdlib/source/test/lux/world/net/udp.lux b/stdlib/source/test/lux/world/net/udp.lux new file mode 100644 index 000000000..2b85958fa --- /dev/null +++ b/stdlib/source/test/lux/world/net/udp.lux @@ -0,0 +1,64 @@ +(.module: + [lux #* + [control + [monad (#+ do)] + [security + ["." integrity]]] + [concurrency + ["." promise]] + [data + ["." error] + ["." text + format]] + ["." io] + [world + ["." binary] + ["." net + ["@" udp]]] + [math + ["r" random]]] + lux/test + [/// + ["_." binary]]) + +(def: localhost net.Address "127.0.0.1") +(def: port + (r.Random net.Port) + (|> r.nat + (:: r.monad map + (|>> (n/% 1000) + (n/+ 8000))))) + +(context: "UDP networking." + (do @ + [port ..port + size (|> r.nat (:: @ map (|>> (n/% 100) (n/max 10)))) + from (_binary.binary size) + to (_binary.binary size)] + ($_ seq + (wrap (do promise.monad + [result (promise.future + (do io.monad + [server (@.server port) + client @.client + #################### + _ (:: client write [[localhost port] from]) + [bytes-from [from-address from-port] temp] (:: server read size) + #let [from-worked? (and (n/= size bytes-from) + (:: binary.equivalence = from (integrity.trust temp)))] + #################### + _ (:: server write [[from-address from-port] to]) + [bytes-to [to-address to-port] temp] (:: client read size) + #let [to-worked? (and (n/= size bytes-to) + (:: binary.equivalence = to (integrity.trust temp)) + (n/= port to-port))] + #################### + _ (:: client close []) + _ (:: server close [])] + ## (wrap false) + (wrap (and from-worked? + to-worked?)) + ))] + (assert "Can communicate between client and server." + (error.default #0 result)))) + ))) |