Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update tests WRT IO::Socket::INET bind before connect #631

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 42 additions & 33 deletions S32-io/IO-Socket-INET-UNIX.t
Original file line number Diff line number Diff line change
@@ -1,43 +1,52 @@
use v6;
use Test;

plan 8;
plan 9;

if $*DISTRO.is-win {
skip-rest 'UNIX socket support on Windows NYI';
} else {
my IO::Socket::INET:_ $server;
my IO::Socket::INET:_ $client;
my IO::Socket::INET:_ $accepted;
my Str:D $host = $?FILE.IO.sibling('test.sock').Str;
my Str:D $sent = 'Hello, world!';
my Str:_ $received;
LEAVE $host.IO.unlink if $host.IO.e;

lives-ok {
$server = IO::Socket::INET.listen: $host, 0, family => PF_UNIX;
}, 'can create TCP UNIX socket servers';
lives-ok {
$client = IO::Socket::INET.connect: $host, $server.localport, family => PF_UNIX;
}, 'can create TCP UNIX socket clients';
lives-ok {
$accepted = $server.accept;
}, 'can accept connections to TCP UNIX socket servers';

lives-ok {
$client.print: $sent;
}, 'can write data to TCP UNIX sockets';
lives-ok {
$received = $accepted.recv;
}, 'can receive data from TCP UNIX sockets...';
is $received, $sent, '...which matches the original data sent';

lives-ok {
$client.close;
}, 'can close TCP UNIX socket clients';
lives-ok {
$server.close;
}, 'can close TCP UNIX socket servers';
my Str:D $host = $?FILE.IO.sibling('test.sock').Str;

{
my IO::Socket::INET:_ $server;
my IO::Socket::INET:_ $client;
my IO::Socket::INET:_ $accepted;
my Str:D $sent = 'Hello, world!';
my Str:_ $received;
LEAVE $host.IO.unlink if $host.IO.e;

lives-ok {
$server = IO::Socket::INET.listen: $host, 0, family => PF_UNIX;
}, 'can create TCP UNIX socket servers';
lives-ok {
$client = IO::Socket::INET.connect: $host, $server.localport, family => PF_UNIX;
}, 'can create TCP UNIX socket clients';
lives-ok {
$accepted = $server.accept;
}, 'can accept connections to TCP UNIX socket servers';

lives-ok {
$client.print: $sent;
}, 'can write data to TCP UNIX sockets';
lives-ok {
$received = $accepted.recv;
}, 'can receive data from TCP UNIX sockets...';
is $received, $sent, '...which matches the original data sent';

lives-ok {
$client.close;
}, 'can close TCP UNIX socket clients';
lives-ok {
$server.close;
}, 'can close TCP UNIX socket servers';
}

fails-like {
LEAVE $host.IO.unlink if $host.IO.e;
IO::Socket::INET.connect: $host, 0, :localhost<foo>, :family(PF_UNIX)
}, X::IO::Socket::Unsupported,
'attempting to bind before connect with UNIX sockets fails';
}

# vim: ft=perl6
13 changes: 4 additions & 9 deletions S32-io/socket-fail-invalid-values.t
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,10 @@ constant PORT_VALUE_TOO_HIGH = 65_536;

plan 4;

dies-ok &port-too-low, 'Fails when port is too low';

dies-ok &port-too-high, 'Fails when port is too high';

dies-ok &family-too-low, 'Fails when family is too low';

dies-ok &family-too-high, 'Fails when family is too high';

done-testing;
fails-like &port-too-low, X::AdHoc, 'Fails when port is too low';
fails-like &port-too-high, X::AdHoc, 'Fails when port is too high';
fails-like &family-too-low, X::AdHoc, 'Fails when family is too low';
fails-like &family-too-high, X::AdHoc, 'Fails when family is too high';

sub port-too-low() {
my $listen = IO::Socket::INET.new(
Expand Down