1 |
#!/usr/bin/perl |
2 |
use strict; |
3 |
use warnings; |
4 |
|
5 |
my $debug = shift @ARGV; |
6 |
|
7 |
use Test::More tests => 256; |
8 |
use Data::Dump qw/dump/; |
9 |
use lib 'lib'; |
10 |
|
11 |
use Devel::LeakTrace::Fast; |
12 |
|
13 |
BEGIN { |
14 |
use_ok('CWMP::Queue'); |
15 |
} |
16 |
|
17 |
use Cwd qw/abs_path/; |
18 |
ok(my $abs_path = abs_path($0), "abs_path"); |
19 |
$abs_path =~ s!/[^/]*$!/!; #!fix-vim |
20 |
|
21 |
ok( my $obj = CWMP::Queue->new({ |
22 |
id => 'test', |
23 |
dir => "$abs_path/queue", |
24 |
clean => 1, |
25 |
debug => $debug, |
26 |
}), 'new' ); |
27 |
isa_ok( $obj, 'CWMP::Queue' ); |
28 |
|
29 |
for my $i ( 1 .. 42 ) { |
30 |
ok( $obj->enqueue( |
31 |
"command-$i", |
32 |
{ |
33 |
i => $i, |
34 |
foo => 'bar', |
35 |
} |
36 |
), "enqueue $i" ); |
37 |
}; |
38 |
|
39 |
my $i = 1; |
40 |
|
41 |
while ( my $job = $obj->dequeue ) { |
42 |
ok( $job, "dequeue $i" ); |
43 |
ok( my ( $dispatch, $args ) = $job->dispatch, "job->dispatch $i" ); |
44 |
cmp_ok( $dispatch, 'eq', "command-$i", "dispatch $i" ); |
45 |
diag "args = ",dump( $args ) if $debug; |
46 |
cmp_ok( $args->{i}, '==', $i, "args i == $i" ); |
47 |
ok( $job->finish, "finish $i" ); |
48 |
$i++; |
49 |
} |