Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Some Channel tests.
  • Loading branch information
jnthn committed Oct 31, 2013
1 parent 46006ae commit 6013403
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions S17-concurrency/channel.t
@@ -0,0 +1,34 @@
use v6;
use Test;

plan 12;

{
my $c = Channel.new;
$c.send(1);
$c.send(2);
is $c.peek, 1, "Peeked first value";
is $c.receive, 1, "Received first value";
is $c.poll, 2, "Polled for second value";
ok $c.peek === Nil, "peek returns Nil when no values available";
ok $c.poll === Nil, "poll returns Nil when no values available";
}

{
my $c = Channel.new;
$c.send(42);
$c.close();
nok $c.closed, "Channel not closed before value received";
is $c.receive, 42, "Received value";
ok $c.closed, "Channel closed after all values received";
dies_ok { $c.receive }, "Receiving from closed channel throws";
}

{
my $c = Channel.new;
$c.send(1);
$c.fail("oh noes");
is $c.receive, 1, "received first value";
dies_ok { $c.receive }, "error thrown on receive";
is $c.closed.cause.message, "oh noes", "failure reason conveyed";
}

0 comments on commit 6013403

Please sign in to comment.