File: 2_single_iterations.t

package info (click to toggle)
libschedule-ratelimiter-perl 0.01-5
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 84 kB
  • sloc: perl: 47; makefile: 2
file content (43 lines) | stat: -rw-r--r-- 1,712 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#use Test::More qw( no_plan );
use Test::More tests => 11;

use Schedule::RateLimiter;
ok(1, 'Did the Schedule::RateLimiter module load?'); # If we made it this far, we're ok.

#########################


# Blocking mode unspecified (default: blocking)
my $throttle = Schedule::RateLimiter->new( seconds => 999999, iterations => 1 );

ok( $throttle->event( block => 0 ), 'Did the first event return success?' );

ok( ! $throttle->event( block => 0 ), 'Did the second event fail?' );

eval { local $SIG{ALRM}= sub{ die 'alarm1' }; alarm( 2 ); $throttle->event(); alarm( 0 ) };
ok( $@ =~ /alarm1/i, "Did an implicit blocking event hang?" );

eval { local $SIG{ALRM}= sub{ die 'alarm2' }; alarm( 2 ); $throttle->event( block => 1); alarm( 0 ) };
ok( $@ =~ /alarm2/i, "Did an explicit blocking event hang?" );

# Blocking mode specified to block.
$throttle = Schedule::RateLimiter->new( seconds => 999999, iterations => 1, block => 1 );

ok( $throttle->event( block => 0 ), 'Did the first event return success?' );

ok( ! $throttle->event( block => 0 ), 'Did the second event fail?' );

eval { local $SIG{ALRM}= sub{ die 'alarm1' }; alarm( 2 ); $throttle->event(); alarm( 0 ) };
ok( $@ =~ /alarm1/i, "Did an implicit blocking event hang when blocking is explicitly on?" );


# Blocking mode specified to non-block.
$throttle = Schedule::RateLimiter->new( seconds => 999999, iterations => 1, block => 0 );

ok( $throttle->event( block => 0 ), 'Did the first event return success?' );

ok( ! $throttle->event( block => 0 ), 'Did the second event fail?' );

eval { local $SIG{ALRM}= sub{ die 'alarm3' }; alarm( 10 ); $throttle->event(); alarm( 0 ) };
ok( $@ !~ /alarm3/i, "Did an implicit non-blocking event hang?" );