Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
First round of updates for supply changes.
  • Loading branch information
jnthn committed Nov 25, 2015
1 parent b287fb8 commit 46231a7
Show file tree
Hide file tree
Showing 22 changed files with 111 additions and 216 deletions.
8 changes: 4 additions & 4 deletions S17-supply/Channel.t
Expand Up @@ -10,8 +10,8 @@ for ThreadPoolScheduler.new, CurrentThreadScheduler -> $*SCHEDULER {
diag "**** scheduling with {$*SCHEDULER.WHAT.perl}";

{
my $s = Supply.new;
my $c = $s.Channel;
my $s = Supplier.new;
my $c = $s.Supply.Channel;
isa-ok $c, Channel, 'we got a Channel';
$s.emit(42);
is $c.receive, 42, 'got first emitted value';
Expand All @@ -24,8 +24,8 @@ for ThreadPoolScheduler.new, CurrentThreadScheduler -> $*SCHEDULER {
}
}

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

Expand Down
20 changes: 10 additions & 10 deletions S17-supply/Promise.t
Expand Up @@ -10,21 +10,21 @@ for ThreadPoolScheduler.new, CurrentThreadScheduler -> $*SCHEDULER {
diag "**** scheduling with {$*SCHEDULER.WHAT.perl}";

{
my $s = Supply.new;
my $p1 = $s.Promise;
my $s = Supplier.new;
my $p1 = $s.Supply.Promise;
isa-ok $p1, Promise, 'we got a Promise';
is $p1.status, Planned, 'Promise still waiting';
$s.emit(42);
is $p1.status, Kept, 'Promise is kept';
is $p1.result, 42, 'got first emitted value';
is $p1.status, Planned, 'Promise is still Planned after emit';

my $p2 = $s.Promise;
$s.emit(43);
$s.emit(44);
is $p2.result, 43, 'got second emitted value';
$s.done();
is $p1.status, Kept, 'Promise is kept after done';
is $p1.result, 43, 'got last emitted value';

my $p3 = $s.Promise;
$s.done;
is $p3.status, Broken, 'Promise is broken';
$s = Supplier.new;
my $p2 = $s.Supply.Promise;
$s.quit('oops');
is $p2.status, Broken, 'Promise is broken after quit';
}
}
10 changes: 5 additions & 5 deletions S17-supply/basic.t
Expand Up @@ -8,11 +8,11 @@ for ThreadPoolScheduler.new, CurrentThreadScheduler -> $*SCHEDULER {
diag "**** scheduling with {$*SCHEDULER.WHAT.perl}";

{
my $s = Supply.new;
my $s = Supplier.new;

my @vals;
my $saw_done;
my $tap = $s.tap( -> $val { @vals.push($val) },
my $tap = $s.Supply.tap( -> $val { @vals.push($val) },
done => { $saw_done = True });

$s.emit(1);
Expand All @@ -27,16 +27,16 @@ for ThreadPoolScheduler.new, CurrentThreadScheduler -> $*SCHEDULER {
}

{
my $s = Supply.new;
my $s = Supplier.new;

my @tap1_vals;
my @tap2_vals;
my $tap1 = $s.tap(-> $val { @tap1_vals.push($val) });
my $tap1 = $s.Supply.tap(-> $val { @tap1_vals.push($val) });

$s.emit(1);
is ~@tap1_vals, "1", "First tap got initial value";

my $tap2 = $s.tap(-> $val { @tap2_vals.push($val) });
my $tap2 = $s.Supply.tap(-> $val { @tap2_vals.push($val) });
$s.emit(2);
is ~@tap1_vals, "1 2", "First tap has both values";
is ~@tap2_vals, "2", "Second tap missed first value";
Expand Down
8 changes: 4 additions & 4 deletions S17-supply/batch.t
Expand Up @@ -17,8 +17,8 @@ for ThreadPoolScheduler.new, CurrentThreadScheduler -> $*SCHEDULER {

{
my $seconds = 5;
my $s = Supply.new;
my $b = $s.batch( :$seconds );
my $s = Supplier.new;
my $b = $s.Supply.batch( :$seconds );
sleep $seconds - now % $seconds; # wait until next $sleep second period
my $base = time div $seconds;
tap-ok $b,
Expand All @@ -38,8 +38,8 @@ for ThreadPoolScheduler.new, CurrentThreadScheduler -> $*SCHEDULER {
my $elems = 7;
my $spurt = 10;
my $rest = $spurt - $elems;
my $s = Supply.new;
my $b = $s.batch( :$elems, :$seconds );
my $s = Supplier.new;
my $b = $s.Supply.batch( :$elems, :$seconds );
sleep $seconds - now % $seconds; # wait until next $sleep second period
my $base = time div $seconds;
tap-ok $b,
Expand Down
14 changes: 6 additions & 8 deletions S17-supply/categorize.t
Expand Up @@ -4,7 +4,7 @@ use lib 't/spec/packages';
use Test;
use Test::Tap;

plan 75;
plan 63;

dies-ok { Supply.categorize( {...} ) }, 'can not be called as a class method';
dies-ok { Supply.categorize( {a=>1} ) }, 'can not be called as a class method';
Expand All @@ -19,9 +19,8 @@ for ThreadPoolScheduler.new, CurrentThreadScheduler -> $*SCHEDULER {
my @mapper = 0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1;
for &mapper, %mapper, @mapper -> \mapper {
my $what = mapper.WHAT.perl;
my $s = Supply.new;
ok $s ~~ Supply, "we got a base Supply ($what)";
my $c = $s.categorize( mapper );
my $s = Supplier.new;
my $c = $s.Supply.categorize( mapper );
ok $c ~~ Supply, "we got a classification Supply ($what)";

my @keys;
Expand All @@ -45,10 +44,9 @@ for ThreadPoolScheduler.new, CurrentThreadScheduler -> $*SCHEDULER {
$(0,1),$(0,1),$(0,1),$(0,1),$(0,1),$(0,1),$(0,1),$(0,1),$(0,1),$(0,1);
for &mapper, %mapper, @mapper -> \mapper {
my $what = mapper.WHAT.perl;
my $s = Supply.new;
ok $s ~~ Supply, "we got a base Supply ($what)";
my $c = $s.categorize( mapper );
ok $s ~~ Supply, "we got a classification Supply ($what)";
my $s = Supplier.new;
my $c = $s.Supply.categorize( mapper );
ok $c ~~ Supply, "we got a classification Supply ($what)";

my @keys;
my @supplies;
Expand Down
7 changes: 3 additions & 4 deletions S17-supply/classify.t
Expand Up @@ -4,7 +4,7 @@ use lib 't/spec/packages';
use Test;
use Test::Tap;

plan 39;
plan 33;

dies-ok { Supply.classify( {...} ) }, 'can not be called as a class method';
dies-ok { Supply.classify( {a=>1} ) }, 'can not be called as a class method';
Expand All @@ -19,9 +19,8 @@ for ThreadPoolScheduler.new, CurrentThreadScheduler -> $*SCHEDULER {
for &mapper, %mapper, @mapper -> \mapper {
diag "mapping {mapper.^name} now";
my $what = mapper.WHAT.perl;
my $s = Supply.new;
ok $s ~~ Supply, "we got a base Supply ($what)";
my $c = $s.classify( mapper );
my $s = Supplier.new;
my $c = $s.Supply.classify( mapper );
ok $c ~~ Supply, "we got a classification Supply ($what)";

my @keys;
Expand Down
4 changes: 2 additions & 2 deletions S17-supply/elems.t
Expand Up @@ -14,8 +14,8 @@ for ThreadPoolScheduler.new, CurrentThreadScheduler -> $*SCHEDULER {
tap-ok Supply.from-list(42..51).elems, [1..10], "just tracing elems works";

{
my $s = Supply.new;
tap-ok $s.elems(1),
my $s = Supplier.new;
tap-ok $s.Supply.elems(1),
[1,2,5],
'works in 1 second increments',
# :live,
Expand Down
4 changes: 2 additions & 2 deletions S17-supply/flat.t
Expand Up @@ -14,8 +14,8 @@ for ThreadPoolScheduler.new, CurrentThreadScheduler -> $*SCHEDULER {
tap-ok Supply.from-list( [1,2],[3,4,5] ).flat,
[1..5], "On demand publish with flat";

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

my $seen1 = [];
my $t1 = $f.tap( { $seen1.push: $_ } );
Expand Down
12 changes: 6 additions & 6 deletions S17-supply/lines.t
Expand Up @@ -48,9 +48,9 @@ for ThreadPoolScheduler.new, CurrentThreadScheduler -> $*SCHEDULER {
"handle a simple list of lines with mixed line ending w/o chomping";

{
my $s = Supply.new;
my $s = Supplier.new;
#?rakudo.jvm todo '\r\n not yet handled as grapheme'
tap-ok $s.lines,
tap-ok $s.Supply.lines,
['a','b','c','d', '', 'eeee'],
"handle chunked lines",
:after-tap( {
Expand All @@ -63,9 +63,9 @@ for ThreadPoolScheduler.new, CurrentThreadScheduler -> $*SCHEDULER {
}

{
my $s = Supply.new;
my $s = Supplier.new;
#?rakudo.jvm todo '\r\n not yet handled as grapheme'
tap-ok $s.lines(:!chomp),
tap-ok $s.Supply.lines(:!chomp),
["a\n","b\r\n","c\r","d\n","\n","eeee"],
"handle chunked lines",
:after-tap( {
Expand All @@ -79,9 +79,9 @@ for ThreadPoolScheduler.new, CurrentThreadScheduler -> $*SCHEDULER {

# See 97b93c3.
{
my $s = Supply.new;
my $s = Supplier.new;
#?rakudo.jvm todo '\r\n not yet handled as grapheme'
my $l = $s.lines(:!chomp);
my $l = $s.Supply.lines(:!chomp);
my @res;
$l.tap({ @res.push: $_ });
$s.emit("a\r");
Expand Down
6 changes: 3 additions & 3 deletions S17-supply/merge.t
Expand Up @@ -10,9 +10,9 @@ for ThreadPoolScheduler.new, CurrentThreadScheduler -> $*SCHEDULER {
diag "**** scheduling with {$*SCHEDULER.WHAT.perl}";

{
my $s1 = Supply.new;
my $s2 = Supply.new;
tap-ok $s1.merge($s2),
my $s1 = Supplier.new;
my $s2 = Supplier.new;
tap-ok $s1.Supply.merge($s2.Supply),
[1,2,'a',3,'b'],
"merging supplies works",
:after-tap( {
Expand Down
22 changes: 9 additions & 13 deletions S17-supply/migrate.t
@@ -1,34 +1,31 @@
use v6;

use Test;
plan 21;
plan 13;

dies-ok { Supply.migrate }, 'can not be called as a class method';

for ThreadPoolScheduler.new, CurrentThreadScheduler -> $*SCHEDULER {
diag "**** scheduling with {$*SCHEDULER.WHAT.perl}";

{
my $master = Supply.new;
ok $master ~~ Supply, 'Did we get a master Supply?';
my $migrate = $master.migrate;
my $master = Supplier.new;
my $migrate = $master.Supply.migrate;
ok $migrate ~~ Supply, 'Did we get a migrate Supply?';

my @seen;
my $tap = $migrate.tap( { @seen.push: $_ } );
isa-ok $tap, Tap, 'Did we get a Tap';

my $s1 = Supply.new;
ok $s1 ~~ Supply, 'Did we get a Supply 1?';
$master.emit($s1); # first get it from here
my $s1 = Supplier.new;
$master.emit($s1.Supply); # first get it from here

$s1.emit(42);
$s1.emit(43);
is-deeply @seen, [42,43], 'did we get these?';

my $s2 = Supply.new;
ok $s2 ~~ Supply, 'Did we get a Supply 2?';
$master.emit($s2); # now get it from here
my $s2 = Supplier.new;
$master.emit($s2.Supply); # now get it from here

$s1.emit(44); # should not see this one
$s2.emit(666);
Expand All @@ -37,9 +34,8 @@ for ThreadPoolScheduler.new, CurrentThreadScheduler -> $*SCHEDULER {
is-deeply @seen, [42,43,666,667,668], 'did we get the rest?';

$s2.done;
my $s3 = Supply.new;
ok $s3 ~~ Supply, 'Did we get a Supply 3?';
$master.emit($s3); # now get it from here
my $s3 = Supplier.new;
$master.emit($s3.Supply); # now get it from here

$s3.emit(7);
is-deeply @seen, [42,43,666,667,668,7], 'did we survive done?';
Expand Down
96 changes: 0 additions & 96 deletions S17-supply/on.t

This file was deleted.

0 comments on commit 46231a7

Please sign in to comment.