line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Couchbase::Test::Async; |
2
|
1
|
|
|
1
|
|
566
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
177
|
|
3
|
1
|
|
|
1
|
|
9
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
54
|
|
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
7
|
use base qw(Couchbase::Test::Common); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
127
|
|
6
|
1
|
|
|
1
|
|
6
|
use base qw(POE::Sugar::Attributes); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
597
|
|
7
|
|
|
|
|
|
|
use Test::More; |
8
|
|
|
|
|
|
|
use Couchbase::Client::Async; |
9
|
|
|
|
|
|
|
use Couchbase::Client::Errors; |
10
|
|
|
|
|
|
|
use Couchbase::Client::IDXConst; |
11
|
|
|
|
|
|
|
use Array::Assign; |
12
|
|
|
|
|
|
|
use Data::Dumper; |
13
|
|
|
|
|
|
|
use Log::Fu; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
my $loop_session = "cbc_test_async"; |
16
|
|
|
|
|
|
|
my $client_session = 'our_client'; |
17
|
|
|
|
|
|
|
my $poe_kernel = 'POE::Kernel'; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
my $can_async = eval { |
20
|
|
|
|
|
|
|
use Couchbase::Test::Async::Loop; |
21
|
|
|
|
|
|
|
use POE::Kernel; 1; |
22
|
|
|
|
|
|
|
}; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
if(!$can_async) { |
25
|
|
|
|
|
|
|
__PACKAGE__->SKIP_CLASS("Can't run async tests: $@"); |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
if($^O eq 'netbsd') { |
29
|
|
|
|
|
|
|
__PACKAGE__->SKIP_CLASS("Skipping Async tests on netbsd ". |
30
|
|
|
|
|
|
|
"due to weird kernel bug"); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
$poe_kernel->run(); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
my $ReadyReceived = 0; |
36
|
|
|
|
|
|
|
my $Return = undef; |
37
|
|
|
|
|
|
|
my $Errnum; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub setup_async :Test(startup) { |
40
|
|
|
|
|
|
|
my $self = shift; |
41
|
|
|
|
|
|
|
$self->mock_init(); |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
Couchbase::Test::Async::Loop->spawn($loop_session, |
44
|
|
|
|
|
|
|
on_ready => \&loop_ready, |
45
|
|
|
|
|
|
|
on_error => sub { $Errnum = $_[0]; diag "Grrr!"; }, |
46
|
|
|
|
|
|
|
%{$self->common_options} |
47
|
|
|
|
|
|
|
); |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub loop_ready { |
51
|
|
|
|
|
|
|
$ReadyReceived = 1; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub _run_poe { |
55
|
|
|
|
|
|
|
$poe_kernel->run_one_timeslice() while ($ReadyReceived == 0); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub cb_result_single { |
59
|
|
|
|
|
|
|
my ($key,$return,$errnum) = @_; |
60
|
|
|
|
|
|
|
if($errnum >= 0) { |
61
|
|
|
|
|
|
|
is($return->errnum, $errnum, |
62
|
|
|
|
|
|
|
"Got return for key $key (expected=$errnum)"); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
$Return = $return; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub reset_vars :Test(setup) { |
68
|
|
|
|
|
|
|
$ReadyReceived = 0; |
69
|
|
|
|
|
|
|
$Return = undef; |
70
|
|
|
|
|
|
|
$Errnum = -1; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub post_to_loop { |
74
|
|
|
|
|
|
|
my ($self,$command,$opargs,$errnum) = @_; |
75
|
|
|
|
|
|
|
reset_vars(); |
76
|
|
|
|
|
|
|
$poe_kernel->post($loop_session, $command, $opargs, |
77
|
|
|
|
|
|
|
{callback => \&cb_result_single, arg => $errnum }); |
78
|
|
|
|
|
|
|
_run_poe(); |
79
|
|
|
|
|
|
|
ok($Return, "Have return object"); |
80
|
|
|
|
|
|
|
return $Return; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub T10_connect :Test(no_plan) { |
84
|
|
|
|
|
|
|
my $self = shift; |
85
|
|
|
|
|
|
|
$poe_kernel->run_one_timeslice() while ($ReadyReceived == 0); |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
ok($ReadyReceived, "Eventually connected.."); |
88
|
|
|
|
|
|
|
ok($Errnum <= 0, "Got no errors ($Errnum)"); |
89
|
|
|
|
|
|
|
if($Errnum > 0) { |
90
|
|
|
|
|
|
|
die("Got errors. Cannot continue"); |
91
|
|
|
|
|
|
|
$self->FAIL_ALL("Async tests cannot continue without hanging"); |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub T11_set :Test(no_plan) { |
96
|
|
|
|
|
|
|
my $self = shift; |
97
|
|
|
|
|
|
|
my $key = "async_key"; |
98
|
|
|
|
|
|
|
my $value = $self->k2v($key); |
99
|
|
|
|
|
|
|
$self->post_to_loop(set => [ $key, $value ], COUCHBASE_SUCCESS); |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub T12_get :Test(no_plan) { |
103
|
|
|
|
|
|
|
my $self = shift; |
104
|
|
|
|
|
|
|
my $key = "async_key"; |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
my $ret = $self->post_to_loop(get => "async_key", COUCHBASE_SUCCESS); |
107
|
|
|
|
|
|
|
is($ret->value, $self->k2v($key), "Got expected value"); |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub T14_arith_ext :Test(no_plan) { |
111
|
|
|
|
|
|
|
my $self = shift; |
112
|
|
|
|
|
|
|
my $key = "async_key"; |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
my $ret; |
115
|
|
|
|
|
|
|
$self->post_to_loop(remove => [$key], -1); |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
$ret = $self->post_to_loop( |
118
|
|
|
|
|
|
|
arithmetic => [ $key, 42, undef ], COUCHBASE_KEY_ENOENT); |
119
|
|
|
|
|
|
|
is($ret->value, undef, "Didn't get value for missing initial value"); |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
$ret = $self->post_to_loop( |
122
|
|
|
|
|
|
|
arithmetic => [ $key, 9999, 42 ], COUCHBASE_SUCCESS); |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
is($Return->value, 42, "Initial value set via arithmetic"); |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
1; |