Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Some more S17-supply tests, more to come
  • Loading branch information
lizmat committed Jul 11, 2014
1 parent 6dfefc4 commit 669ec1f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
12 changes: 11 additions & 1 deletion S17-supply/Channel.t
Expand Up @@ -2,7 +2,7 @@ use v6;

use Test;

plan 11;
plan 12;

dies_ok { Supply.Channel }, 'can not be called as a class method';

Expand All @@ -23,3 +23,13 @@ for ThreadPoolScheduler.new, CurrentThreadScheduler -> $*SCHEDULER {
ok $c.closed, 'doneing closes the Channel';
}
}

my $s = Supply.new;
my $c = $s.Channel;
my $done = 0;
my $times = 10;

my $promise = start { while $done < $times { $c.receive; $done++ } };
$s.more($_) for ^$times;
await $promise;
is $done, $times, 'did we receive all?';
26 changes: 25 additions & 1 deletion S17-supply/flat.t
Expand Up @@ -4,7 +4,7 @@ use lib 't/spec/packages';
use Test;
use Test::Tap;

plan 3;
plan 17;

#?rakudo.jvm todo "D: doesn't work in signatures RT #122229"
dies_ok { Supply.flat }, 'can not be called as a class method';
Expand All @@ -14,4 +14,28 @@ for ThreadPoolScheduler.new, CurrentThreadScheduler -> $*SCHEDULER {

tap_ok Supply.for( [1,2],[3,4,5] ).flat,
[1..5], "On demand publish with flat";

my $s = Supply.new;
my $f = $s.flat;

my $seen1 = [];
my $t1 = $f.tap( { $seen1.push: $_ } );
$s.more([1,2]);
is $seen1, [1,2], 'did we get the first more (1)';

my $seen2 = [];
my $t2 = $f.tap( { $seen2.push: $_ } );
$s.more([3,4]);
is $seen1, [1,2,3,4], 'did we get the second more (1)';
is $seen2, [3,4], 'did we get the second more (2)';

$t1.close;
$s.more([5,6]);
is $seen1, [1,2,3,4], 'did we get the third more (1)';
is $seen2, [3,4,5,6], 'did we get the third more (2)';

$t2.close;
$s.more([7,8]);
is $seen1, [1,2,3,4], 'did we not get the fourth more (1)';
is $seen2, [3,4,5,6], 'did we not get the fourth more (2)';
}

0 comments on commit 669ec1f

Please sign in to comment.