forked from sng2c/Gearman-SlotManager
/
05-SlotManagerWork.t
70 lines (59 loc) · 1.21 KB
/
05-SlotManagerWork.t
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package main;
use lib './t','./lib';
use Test::More tests=>12;
use Gear;
use AnyEvent;
use AnyEvent::Gearman;
use Gearman::SlotManager;
use Log::Log4perl qw(:easy);
Log::Log4perl->easy_init($ERROR);
use Scalar::Util qw(weaken);
my $port = '9955';
my @js = ("localhost:$port");
use_ok('Gearman::Server');
gstart($port);
my $cv = AE::cv;
my $sig = AE::signal 'INT'=> sub{
DEBUG "TERM!!";
$cv->send;
};
my $t = AE::timer 10,0,sub{ $cv->send('timeout')};
my $slotman = Gearman::SlotManager->new(
config=>
{
global=>{
job_servers=>\@js,
libs=>['./t','./lib'],
max=>3,
},
slots=>{
'TestWorker'=>{
min=>3,
max=>5,
workleft=>10,
}
}
},
port=>55595,
);
$slotman->start();
my $c = gearman_client @js;
foreach (1 .. 10){
my $n = $_;
my $str = "HELLO$n";
DEBUG 'cl';
$c->add_task(
'TestWorker::reverse'=>$str,
on_complete=>sub{is $_[1], reverse($str),"check $n";},
);
}
my $tt = AE::timer 5,0,sub{
$cv->send;
};
my $res = $cv->recv;
isnt $res,'timeout','ends successfully';
undef($tt);
$slotman->stop;
undef($slotman);
gstop();
done_testing();