Skip to content

Commit

Permalink
Test supply setup with a blocking recursion
Browse files Browse the repository at this point in the history
Having a supply that recurses back to itself during construction and
forcing a (temporary) blocking of that supply has proven to be a corner
case that's difficult to get right. Thus add a test for it.

rakudo/rakudo#5141 tells the full story of
how this test came to be.
  • Loading branch information
patrickbkr committed Mar 10, 2023
1 parent b4a0d5b commit 26298a1
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions S17-supply/construction-recursion.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
use Test;

plan 4;

# This is a reproduction of https://github.com/rakudo/rakudo/issues/5141

my $dummy-supply = supply { };

my $side-channel = Supplier.new;

my $supply0 = supply {
emit "foo";
}

my $s1 = supply {
whenever $supply0 {
start {
$side-channel.emit: "beep";
}
sleep 0.1;
emit "bar";
}
whenever $dummy-supply {}
}

my $s2 = supply {
whenever $side-channel.Supply {
sleep 0.2;
}
whenever $s1 {
emit "baz";
}
}

my $tap;
my $done;

start { $tap = $s2.tap: :done({ $done = True }) }
for ^10 {
last if $tap;
sleep .1
}

ok $tap, "supply setup with recursion re-entering a supply doesn't deadlock";
isa-ok $tap, Tap, "got a tap";

my $closed;
start { $side-channel.done; $closed = True }
for ^10 {
last if $closed;
sleep .1
}

ok $closed, "emitting done didn't hang";
ok $done, "tap closes after last emitter is done";

0 comments on commit 26298a1

Please sign in to comment.