Skip to content
Newer
Older
100644 92 lines (76 sloc) 2.32 KB
ee7d6f0 @cpanelWade First git commit.
authored Feb 9, 2011
1 #!/usr/bin/perl
2
3 # Test the cPanel::TaskQueue::Processor module.
4 #
5 use strict;
6 use warnings;
7
8 use Test::More tests => 12;
9 use cPanel::TaskQueue::Processor;
10
11 my $proc = cPanel::TaskQueue::Processor->new;
12 isa_ok( $proc, 'cPanel::TaskQueue::Processor' );
13
14 {
15 package MockTask;
16
17 sub new {
18 my $class = shift;
19 my $self = { @_ };
20 return bless $self, $class;
21 }
22
23 sub command {
24 return $_[0]->{command};
25 }
26
27 sub args {
28 return @{$_[0]->{args}};
29 }
30 }
31
32 # Test the is_dupe method.
33 my @dupe_checks = (
34 [ MockTask->new( command => 'me', args => [] ),
35 MockTask->new( command => 'you', args => [] ),
36 0,
37 'is_dupe: commands are different'
38 ],
39 [ MockTask->new( command => 'me', args => [] ),
40 MockTask->new( command => 'me', args => [] ),
41 1,
42 'is_dupe: Same commands no args'
43 ],
44 [ MockTask->new( command => 'me', args => [ 'a' ] ),
45 MockTask->new( command => 'me', args => [ 'a' ] ),
46 1,
47 'is_dupe: Same commands 1 matching arg'
48 ],
49 [ MockTask->new( command => 'me', args => [ 'a' ] ),
50 MockTask->new( command => 'me', args => [ 'b' ] ),
51 0,
52 'is_dupe: Same commands 1 non-matching arg'
53 ],
54 [ MockTask->new( command => 'me', args => [ qw/a b c d e f g/ ] ),
55 MockTask->new( command => 'me', args => [ qw/a b c d e f g/ ] ),
56 1,
57 'is_dupe: Same commands matching n args'
58 ],
59 [ MockTask->new( command => 'me', args => [ qw/a b c d e f g/ ] ),
60 MockTask->new( command => 'me', args => [ qw/a b c d e f g h/ ] ),
61 0,
62 'is_dupe: Same commands different number of args'
63 ],
64 );
65
66 foreach my $try (@dupe_checks) {
67 is( !!$proc->is_dupe( $try->[0], $try->[1] ), !!$try->[2], $try->[3] );
68 }
69
70 eval {
71 $proc->process_task();
72 };
73 like( $@, qr/No processing/, "process_task: default exceptions" );
74
75 ok( !defined $proc->get_timeout(), q{Default to use queue's timeout.} );
76
77 eval {
78 cPanel::TaskQueue::Processor::CodeRef->new({ });
79 };
80 like( $@, qr/required code/, 'Cannot create without code param.' );
81
82 eval {
83 cPanel::TaskQueue::Processor::CodeRef->new({ code => undef });
84 };
85 like( $@, qr/required code/, 'Cannot create with undefined code param.' );
86
87 eval {
88 cPanel::TaskQueue::Processor::CodeRef->new({ code => 'fred' });
89 };
90 like( $@, qr/required code/, 'Code param must be a code ref.' );
91
Something went wrong with that request. Please try again.