aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test/lux/world/net/udp.lux
diff options
context:
space:
mode:
Diffstat (limited to 'stdlib/source/test/lux/world/net/udp.lux')
-rw-r--r--stdlib/source/test/lux/world/net/udp.lux90
1 files changed, 47 insertions, 43 deletions
diff --git a/stdlib/source/test/lux/world/net/udp.lux b/stdlib/source/test/lux/world/net/udp.lux
index d3d2531f9..1740c861c 100644
--- a/stdlib/source/test/lux/world/net/udp.lux
+++ b/stdlib/source/test/lux/world/net/udp.lux
@@ -1,21 +1,23 @@
(.module:
[lux #*
+ data/text/format
+ ["r" math/random (#+ Random)]
+ ["_" test (#+ Test)]
[control
- [monad (#+ do)]]
- [concurrency
- ["." promise]]
+ ["." monad (#+ do)]
+ [concurrency
+ ["." promise]]
+ [security
+ ["!" capability]]]
[data
["." error]
- ["." text
- format]]
+ ["." text]]
["." io]
[world
["." binary]
- ["." net
- ["@" udp]]]
- [math
- ["r" random]]]
- lux/test
+ ["." net]]]
+ {1
+ ["." /]}
[///
["_." binary]])
@@ -27,36 +29,38 @@
(|>> (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 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 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))))
- )))
+(def: #export test
+ Test
+ (<| (_.context (%name (name-of /._)))
+ (do r.monad
+ [port ..port
+ size (|> r.nat (:: @ map (|>> (n/% 100) (n/max 10))))
+ from (_binary.binary size)
+ to (_binary.binary size)]
+ ($_ _.and
+ (wrap (do promise.monad
+ [result (promise.future
+ (do (error.with io.monad)
+ [server (/.server port)
+ client /.client
+ ####################
+ _ (!.use (:: client write) [[localhost port] from])
+ [bytes-from [from-address from-port] temp] (!.use (:: server read) size)
+ #let [from-worked? (and (n/= size bytes-from)
+ (:: binary.equivalence = from temp))]
+ ####################
+ _ (!.use (:: server write) [[from-address from-port] to])
+ [bytes-to [to-address to-port] temp] (!.use (:: client read) size)
+ #let [to-worked? (and (n/= size bytes-to)
+ (:: binary.equivalence = to temp)
+ (n/= port to-port))]
+ ####################
+ _ (!.use (:: client close) [])
+ _ (!.use (:: server close) [])]
+ ## (wrap false)
+ (wrap (and from-worked?
+ to-worked?))
+ ))]
+ (_.assert "Can communicate between client and server."
+ (error.default #0 result))))
+ ))))