Skip to content

Commit

Permalink
Merge pull request #1969 from misch2/michals/convert-tests-to-use-sub…
Browse files Browse the repository at this point in the history
…tests-ioloop-ipv6

Convert t/mojo/ioloop_ipv6.t to use subtests
  • Loading branch information
mergify[bot] authored Aug 14, 2022
2 parents 5443420 + bd2f7fa commit ac8eb21
Showing 1 changed file with 26 additions and 25 deletions.
51 changes: 26 additions & 25 deletions t/mojo/ioloop_ipv6.t
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,31 @@ plan skip_all => 'set TEST_IPV6 to enable this test (developer only!)' unless $E

use Mojo::IOLoop;

# IPv6 roundtrip
my ($server, $client);
my $promise = Mojo::Promise->new;
my $id = Mojo::IOLoop->server(
{address => '[::1]'} => sub {
my ($loop, $stream) = @_;
$stream->write('test' => sub { shift->write('321') });
$stream->on(close => sub { $promise->resolve });
$stream->on(read => sub { $server .= pop });
}
);
my $port = Mojo::IOLoop->acceptor($id)->port;
my $promise2 = Mojo::Promise->new;
Mojo::IOLoop->client(
{address => '[::1]', port => $port} => sub {
my ($loop, $err, $stream) = @_;
$stream->write('tset' => sub { shift->write('123') });
$stream->on(close => sub { $promise2->resolve });
$stream->on(read => sub { $client .= pop });
$stream->timeout(0.5);
}
);
Mojo::Promise->all($promise, $promise2)->wait;
is $server, 'tset123', 'right content';
is $client, 'test321', 'right content';
subtest 'IPv6 roundtrip' => sub {
my ($server, $client);
my $promise = Mojo::Promise->new;
my $id = Mojo::IOLoop->server(
{address => '[::1]'} => sub {
my ($loop, $stream) = @_;
$stream->write('test' => sub { shift->write('321') });
$stream->on(close => sub { $promise->resolve });
$stream->on(read => sub { $server .= pop });
}
);
my $port = Mojo::IOLoop->acceptor($id)->port;
my $promise2 = Mojo::Promise->new;
Mojo::IOLoop->client(
{address => '[::1]', port => $port} => sub {
my ($loop, $err, $stream) = @_;
$stream->write('tset' => sub { shift->write('123') });
$stream->on(close => sub { $promise2->resolve });
$stream->on(read => sub { $client .= pop });
$stream->timeout(0.5);
}
);
Mojo::Promise->all($promise, $promise2)->wait;
is $server, 'tset123', 'right content';
is $client, 'test321', 'right content';
};

done_testing();

0 comments on commit ac8eb21

Please sign in to comment.