Debian Codegraph @

t/60_Cxn/10_basic.t

raw
1 # Licensed to Elasticsearch B.V. under one or more contributor
2 # license agreements. See the NOTICE file distributed with
3 # this work for additional information regarding copyright
4 # ownership. Elasticsearch B.V. licenses this file to you under
5 # the Apache License, Version 2.0 (the "License"); you may
6 # not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing,
12 # software distributed under the License is distributed on an
13 # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 # KIND, either express or implied. See the License for the
15 # specific language governing permissions and limitations
16 # under the License.
17
18 use Test::More;
19 use Search::Elasticsearch;
20
21 my $c = Search::Elasticsearch->new->transport->cxn_pool->cxns->[0];
22 ok $c->does('Search::Elasticsearch::Role::Cxn'),
23 'Does Search::Elasticsearch::Role::Cxn';
24
25 # MARK LIVE
26
27 $c->mark_live;
28
29 ok $c->is_live, "Cxn is live";
30 is $c->ping_failures, 0, "No ping failures";
31 is $c->next_ping, 0, "No ping scheduled";
32
33 # MARK DEAD
34
35 $c->mark_dead;
36
37 ok $c->is_dead, "Cxn is dead";
38 is $c->ping_failures, 1, "Has ping failure";
39 ok $c->next_ping > time(), "Ping scheduled";
40 ok $c->next_ping <= time() + $c->dead_timeout, "Dead timeout x 1";
41
42 $c->mark_dead;
43 ok $c->is_dead, "Cxn still dead";
44 is $c->ping_failures, 2, "Has 2 ping failures";
45 ok $c->next_ping > time(), "Ping scheduled";
46 ok $c->next_ping <= time() + 2 * $c->dead_timeout, "Dead timeout x 2";
47
48 $c->mark_dead for 1 .. 100;
49 ok $c->is_dead, "Cxn still dead";
50 is $c->ping_failures, 102, "Has 102 ping failures";
51 ok $c->next_ping > time(), "Ping scheduled";
52 ok $c->next_ping <= time() + $c->max_dead_timeout, "Max dead timeout";
53
54 # FORCE PING
55
56 $c->force_ping;
57 ok $c->is_dead, "Cxn is dead after force ping";
58 is $c->ping_failures, 0, "Force ping has no ping failures";
59 is $c->next_ping, -1, "Next ping scheduled for now";
60
61 done_testing;