Skip to content

Commit baa8ccb

Browse files
committed
Test Promise.in/at/Supply.interval with degenerate delays
Rakudo fix: rakudo/rakudo@df01ad97e5
1 parent cedf738 commit baa8ccb

File tree

3 files changed

+32
-4
lines changed

3 files changed

+32
-4
lines changed

S17-promise/at.t

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
use v6;
2+
use lib <t/spec/packages/>;
23
use Test;
4+
use Test::Util;
35

4-
plan 3;
6+
plan 4;
57

68
# RT #123520
79
# This test comes first in the file so it's the first to start any threads;
@@ -23,3 +25,7 @@ plan 3;
2325
is $p.result, True, "Promise.at result is True";
2426
ok now - $start >= 1, "Promise.at took long enough";
2527
}
28+
29+
is_run await Promise.at(now - 1000).then: {print 'pass'},
30+
{:out<pass>, :err(''), :0status},
31+
'.at with negative value works and does not warn';

S17-promise/in.t

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use v6;
22
use Test;
33

4-
plan 3;
4+
plan 4;
55

66
# RT #123520
77
# This test comes first in the file so it's the first to start any threads;
@@ -23,3 +23,8 @@ plan 3;
2323
is $p.result, True, "Promise.in result is True";
2424
ok now - $start >= 1, "Promise.in took long enough";
2525
}
26+
27+
subtest 'Promise.in with negative value works' => {
28+
plan 1;
29+
await Promise.in(-rand).then: { pass ".then'ed code ran" }
30+
}

S17-supply/interval.t

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use Test;
55
use Test::Tap;
66
use Test::Util;
77

8-
plan 8;
8+
plan 9;
99

1010
dies-ok { Supplier.new.Supply.interval(1) }, 'can not be called as an instance method';
1111

@@ -48,14 +48,31 @@ is_run(
4848

4949
# RT #130168
5050
{
51+
# treat too-small values as minimum timer resolution (e.g. 0.001 seconds)
52+
# emitting optional warning in such cases is allowed
53+
CONTROL { when CX::Warn { .resume } }
5154
my @a;
5255
react {
5356
whenever Supply.interval(.0001) {
5457
push @a, $_;
5558
done if $_ == 5
5659
}
5760
}
58-
is @a, [0..5], "Timer with very short interval fires multiple times";
61+
is-deeply @a, [0..5], "Timer with very short interval fires multiple times";
62+
}
63+
64+
{
65+
# treat negatives/zeros as minimum timer resolution (e.g. 0.001 seconds)
66+
# emitting optional warning in such cases is allowed
67+
CONTROL { when CX::Warn { .resume } }
68+
my @a;
69+
react {
70+
whenever Supply.interval(-100) {
71+
push @a, $_;
72+
done if $_ == 5
73+
}
74+
}
75+
is-deeply @a, [0..5], "Timer with very short interval fires multiple times";
5976
}
6077

6178
# vim: ft=perl6 expandtab sw=4

0 commit comments

Comments
 (0)