forked from Raku/roast
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement spec tests for .native-dfescriptor on async sockets
Fixes Raku#490
- Loading branch information
Showing
2 changed files
with
46 additions
and
21 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 |
---|---|---|
@@ -1,45 +1,51 @@ | ||
use v6; | ||
use Test; | ||
|
||
plan 3; | ||
plan 5; | ||
|
||
my $hostname = 'localhost'; | ||
my $port = 5001; | ||
|
||
{ | ||
my $sock = IO::Socket::Async.bind-udp($hostname, $port); | ||
my $s = IO::Socket::Async.bind-udp($hostname, $port); | ||
dies-ok { IO::Socket::Async.bind-udp($hostname, $port) }, | ||
'Error on trying to re-use port with UDP bind'; | ||
$sock.close; | ||
$s.close; | ||
} | ||
|
||
# Promise used to check listener received the correct data. | ||
my $rec-prom; | ||
|
||
# Listener | ||
{ | ||
my $sock = IO::Socket::Async.bind-udp($hostname, $port); | ||
my $tap = $sock.Supply.tap: -> $chars { | ||
if $chars.chars > 0 { | ||
$rec-prom.keep($chars); | ||
} | ||
my Promise $rec-prom; | ||
my $s = IO::Socket::Async.bind-udp($hostname, $port); | ||
my $tap = $s.Supply.tap: -> $chars { | ||
if $chars.chars > 0 { | ||
$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"); | ||
$rec-prom .= new; | ||
my $c = IO::Socket::Async.udp(); | ||
$c.print-to($hostname, $port, "Unusually Dubious Protocol"); | ||
is $rec-prom.result, "Unusually Dubious Protocol", "Sent/received data with UDP (print)"; | ||
$sock.close; | ||
$c.close; | ||
} | ||
|
||
# Client write-to | ||
{ | ||
$rec-prom = Promise.new; | ||
my $sock = IO::Socket::Async.udp(); | ||
$sock.write-to($hostname, $port, "Unhelpful Dataloss Protocol".encode('ascii')); | ||
$rec-prom .= new; | ||
my $c = IO::Socket::Async.udp(); | ||
$c.write-to($hostname, $port, "Unhelpful Dataloss Protocol".encode('ascii')); | ||
is $rec-prom.result, "Unhelpful Dataloss Protocol", "Sent/received data with UDP (write)"; | ||
$sock.close; | ||
$c.close; | ||
} | ||
|
||
#?rakudo,jvm skip 'nqp::filenofh not yet implemented on the JVM' | ||
{ | ||
my $c = IO::Socket::Async.udp(); | ||
cmp-ok $s.native-descriptor, '>', -1, 'server file descriptor makes sense'; | ||
cmp-ok $c.native-descriptor, '>', -1, 'client file descriptor makes sense'; | ||
$c.close; | ||
} | ||
|
||
$s.close; |
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