Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Basic tests for UDP sockets.
- Loading branch information
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| use v6; | ||
| use Test; | ||
|
|
||
| plan 2; | ||
|
|
||
| my $hostname = 'localhost'; | ||
| my $port = 5001; | ||
|
|
||
| # Promise used to check listener received data, and to make | ||
| my $rec-prom; | ||
|
|
||
| # Listener | ||
| { | ||
| my $sock = IO::Socket::Async.bind-udp($hostname, $port); | ||
| my $tap = $sock.Supply.tap: -> $chars { | ||
| $rec-prom.keep($chars); | ||
| } | ||
| } | ||
|
|
||
| # Client print-to | ||
| { | ||
| $rec-prom = Promise.new; | ||
| my $sock = IO::Socket::Async.udp(); | ||
| $sock.print-to($hostname, $port, "Unusually Dubious Protocol"); | ||
| is $rec-prom.result, "Unusually Dubious Protocol", "Sent/received data with UDP (print)"; | ||
| $sock.close; | ||
| } | ||
|
|
||
| # Client write-to | ||
| { | ||
| $rec-prom = Promise.new; | ||
| my $sock = IO::Socket::Async.udp(); | ||
| $sock.write-to($hostname, $port, "Unhelpful Dataloss Protocl".encode('ascii')); | ||
| is $rec-prom.result, "Unhelpful Dataloss Protocl", "Sent/received data with UDP (write)"; | ||
| $sock.close; | ||
| } |