Branch Coverage

blib/lib/MongoDB/_Topology.pm
Criterion Covered Total %
branch 157 318 49.3


line true false branch
310 0 0 unless $cluster_time and exists $cluster_time->{'clusterTime'} and ref $cluster_time->{'clusterTime'} eq 'BSON::Timestamp'
313 0 0 if (not defined $self->cluster_time) { }
0 0 elsif ($cluster_time->{'clusterTime'} > $self->cluster_time->{'clusterTime'}) { }
340 0 0 length $self->app_name ? :
358 72 259 if $self->monitoring_callback
361 72 259 if $self->monitoring_callback
369 47 284 if (my $set_name = $self->replica_set_name)
370 2 45 if ($type eq 'Single' or $type eq 'ReplicaSetNoPrimary') { }
45 0 elsif ($type eq 'Unknown') { }
382 0 331 if ($type eq 'Single' and @addresses > 1)
389 72 259 if $self->monitoring_callback
398 72 259 if $self->monitoring_callback
409 54 0 unless $type eq 'Sharded' or $type eq 'Unknown'
418 0 0 if ($self->uri->check_for_changes($options))
421 0 0 if (not $new{$address}) { }
446 0 108 if ($link and $link->is_connected) { }
465 54 0 unless defined $op and defined $op->session
467 0 0 if ($op->session->_in_transaction_state('starting', 'in_progress')) { }
0 0 elsif ($op->session->_in_transaction_state('committed')) { }
480 0 0 defined $op ? :
482 0 0 $read_pref ? :
483 0 0 $self->type eq 'Sharded' ? :
0 0 $self->type eq 'Single' ? :
488 0 0 if ($mode eq 'primary' and $self->current_primary and $self->next_scan_time > &MongoDB::_Topology::time())
491 0 0 if $link
496 0 0 if ($link)
500 0 0 if $mode eq 'primary' and $self->type eq 'ReplicaSetWithPrimary' || 1 == keys %{$self->servers;}
505 0 0 $read_pref ? :
519 0 0 if ($server and my $link = $self->_get_server_link($server)) { }
534 54 0 $self->type eq 'Single' || $self->type eq 'Sharded' ? :
540 0 54 if ($self->current_primary and $self->next_scan_time > &MongoDB::_Topology::time())
542 0 0 if $link
547 0 0 if ($link)
550 0 0 if $self->type eq 'ReplicaSetWithPrimary' or 1 == keys %{$self->servers;}
581 0 1080 $force ? :
590 1188 0 $_->type eq 'Unknown' ? :
595 1080 108 unless @to_check
597 0 108 if ($next = &first(sub { $_->type eq 'RSPrimary'; } , @to_check)) { }
0 108 elsif ($next = &first(sub { $_->type eq 'PossiblePrimary'; } , @to_check)) { }
0 108 elsif (@ordinary = grep({$_->type ne 'RSGhost' if $_->type ne 'Unknown';} @to_check)) { }
603 0 108 if $_->type ne 'Unknown'
622 0 0 if $self->replica_set_name
632 0 0 if (defined $rtt_hash->{$addr})
646 118 402 $error ? :
649 153 367 if $self->monitoring_callback
661 17 104 if (0 == $self->_primaries)
674 0 0 unless $MongoDB::_Topology::a->[1] <=> $MongoDB::_Topology::b->[1]
697 4 215 unless defined $server_max_wire_version
698 4 215 unless defined $server_min_wire_version
700 3 216 if ($server_min_wire_version > $self->max_wire_version or $server_max_wire_version < $self->min_wire_version)
706 136 83 if $server_max_wire_version < $min_seen
707 134 85 if $server_max_wire_version > $max_seen
722 15 140 defined $_->logical_session_timeout_minutes ? :
727 117 144 if (defined $timeout and $timeout < 0)
737 0 0 if $self->stale
740 0 0 if @servers == 1 and $servers[0]->type eq 'Standalone'
748 0 0 unless $self->_supports_sessions
749 0 0 if $self->type eq 'Sharded'
750 0 0 if $self->wire_version_ceil < 7
759 0 0 if $self->wire_version_ceil < 8
761 0 0 if $self->type ne 'Sharded'
767 76 0 $read_pref ? :
769 37 39 if ($max_staleness_sec > 0)
770 5 32 if ($self->wire_version_floor < 5)
776 3 29 if ($self->type eq 'ReplicaSetWithPrimary' || $self->type eq 'ReplicaSetNoPrimary' and $max_staleness_sec < &max(90, $self->heartbeat_frequency_sec + 10))
802 19 23 if ($read_pref->max_staleness_seconds > 0)
804 1 17 unless @candidates
809 27 13 unless ($read_pref->has_empty_tag_sets)
811 18 13 if (my(@ts_candidates) = grep({$_->matches_tag_set($ts);} @candidates))
828 10 9 if ($self->type eq 'ReplicaSetWithPrimary') { }
864 3 1094 if $read_pref
865 1096 0 unless @candidates
868 6 1090 $selector ? :
878 6 0 unless @candidates
881 0 6 $selector ? :
889 18 0 unless @candidates
892 0 17 $selector ? :
899 0 18 if $self->current_primary
901 18 0 unless @candidates
915 24 0 unless @candidates
918 0 24 $selector ? :
932 1091 52 unless @$servers
933 20 32 if @$servers == 1
974 0 0 unless $link and $link->connected
975 0 0 unless $link
978 0 0 if (&MongoDB::_Topology::time() - $link->last_used > $self->socket_check_interval_sec)
979 0 0 if $self->_ping_server
986 0 0 unless $server = $self->servers->{$address}
990 0 0 unless $method
993 0 0 $self->$method($read_pref, $server) ? :
1004 108 0 unless (my $link = eval { do { 'MongoDB::_Link'->new(%{$self->link_options;}, 'address', $address)->connect } })
1010 108 0 unless $link
1018 0 0 unless my $server = $self->servers->{$address}
1023 0 0 if ($self->type eq 'Single' or &first(sub { $_ eq $server->type; } , 'Standalone', 'Mongos', 'RSPrimary', 'RSSecondary'))
1027 0 0 unless (eval { do { $self->credential->authenticate($server, $link, $self->bson_codec); 1 } })
1029 0 0 $err->$MongoDB::_Topology::_isa('MongoDB::Error') ? :
1044 0 225 if ($self->current_primary and $self->current_primary->address eq $address)
1048 39 186 if $self->monitoring_callback
1077 0 54 if ($self->type =~ /^Replica/) { }
1097 0 54 if ($self->next_scan_time < $start_time)
1102 1080 54 if ($self->stale)
1106 54 1026 if not $self->server_selection_try_once and $scan_ready_time > $max_time
1111 1026 0 if $sleep_time > 0
1116 0 1080 unless ($self->is_compatible)
1123 0 0 if ($min_wire_ver > $self->max_wire_version) { }
1148 0 1080 if $server
1153 0 1080 if ($self->server_selection_try_once) { }
1155 0 0 if $self->last_scan_time > $start_time
1159 0 1080 if $loop_end_time > $max_time
1167 0 0 if ($should_perform_handshake)
1169 0 0 if ($self->credential->mechanism eq 'DEFAULT')
1173 0 0 if (@{$self->compressors;})
1177 0 0 if ($link->supports_clusterTime and defined $self->cluster_time)
1187 0 0 if $self->monitoring_callback
1206 0 0 if (my $e = $@)
1209 0 0 if $self->monitoring_callback
1211 0 0 if ($e->$MongoDB::_Topology::_isa('MongoDB::DatabaseError') and $e->code == 11)
1218 0 0 if ($e->$MongoDB::_Topology::_isa('MongoDB::NetworkError') and $link->server and $link->server->type ne 'Unknown' and $link->server->type ne 'PossiblePrimary')
1230 0 0 unless $is_master
1232 0 0 if (my $cluster_time = $is_master->{'$clusterTime'})
1239 0 0 if $rtt_sec < 0
1241 0 0 if $self->monitoring_callback
1265 0 0 unless +($is_master || {})->{'compression'}
0 0 unless my(@supported) = @{[] unless +($is_master || {})->{'compression'};}
1269 0 0 if (grep {$name eq $_;} @supported)
1286 2 261 unless $self->servers->{$address}
1288 146 115 if $self->monitoring_callback
1305 146 115 if $self->monitoring_callback
1313 128 355 if ($new_server->type eq 'Unknown') { }
1320 16 339 defined $old_avg ? :
1332 0 261 if ($self->links->{$address})
1342 2 15 if (not $self->servers->{$new_server->address} or $self->replica_set_name ne $new_server->set_name)
1350 0 17 if ($new_server->me and lc $new_server->me ne $new_server->address)
1356 1 16 unless ($self->_check_for_primary)
1360 0 0 if (length $primary and $self->servers->{$primary} and $self->servers->{$primary}->type eq 'Unknown')
1374 3 60 if (not length $self->replica_set_name) { }
3 57 elsif ($self->replica_set_name ne $new_server->set_name) { }
1389 20 40 if (defined $set_version and defined $election_id)
1390 6 7 if (defined $max_election_id and defined $max_set_version and $max_set_version > $set_version || $max_set_version == $set_version && "$max_election_id" gt "$election_id")
1410 14 8 if (defined $set_version and !defined($max_set_version) || $set_version > $max_set_version)
1418 10 54 if ($old_primary->address ne $new_server->address)
1444 1 9 if (not length $self->replica_set_name) { }
2 7 elsif ($self->replica_set_name ne $new_server->set_name) { }
1460 1 7 if ($new_server->me and $new_server->me ne $new_server->address)
1467 2 0 if (length $primary and $self->servers->{$primary} and $self->servers->{$primary}->type eq 'Unknown')
1487 41 12 if ($server_type eq 'RSPrimary') { }
9 3 elsif (grep {$server_type eq $_;} 'RSSecondary', 'RSArbiter', 'RSOther') { }
2 1 elsif (grep {$server_type eq $_;} 'Standalone', 'Mongos') { }
1511 19 35 if ($server_type eq 'RSPrimary') { }
17 18 elsif (grep {$server_type eq $_;} 'RSSecondary', 'RSArbiter', 'RSOther') { }
16 2 elsif (grep {$server_type eq $_;} 'Unknown', 'Standalone', 'Mongos') { }
1518 2 14 unless $server_type eq 'Unknown'
1536 10 1 if (grep {$server_type eq $_;} 'Unknown', 'Mongos') { }
1559 0 54 if ($server_type eq 'Mongos')
1576 2 11 if ($server_type eq 'Standalone')
1577 2 0 if ($self->number_of_seeds > 1) { }
1586 7 4 if ($server_type eq 'Mongos')
1591 3 1 if ($server_type eq 'RSPrimary') { }
1 0 elsif (grep {$server_type eq $_;} 'RSSecondary', 'RSArbiter', 'RSOther') { }