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