EV-ClickHouse
view release on metacpan or search on metacpan
t/24_review_gaps.t view on Meta::CPAN
$ch->finish if $ch->is_connected;
}
# 9: Enum16 column round-trip.
SKIP: {
skip "Native port not reachable", 1 unless $nat_ok;
my ($ch, $rows);
$ch = EV::ClickHouse->new(
host => $host, port => $nat_port, protocol => 'native', decode_enum => 1,
on_connect => sub {
$ch->query("select CAST('b' as Enum16('a' = 1, 'b' = 2, 'c' = 3))", sub {
($rows) = @_; EV::break;
});
},
);
run_with_timeout(10);
is($rows && @$rows ? $rows->[0][0] : undef, 'b', "Enum16 decoded with decode_enum");
$ch->finish if $ch->is_connected;
}
# 10-11: reset() explicit re-handshake. After reset(), the connection should
# be reconnect-able and the next query must succeed.
SKIP: {
skip "Native port not reachable", 2 unless $nat_ok;
my ($ch, $rows);
my $second_connects = 0;
$ch = EV::ClickHouse->new(
host => $host, port => $nat_port, protocol => 'native',
on_connect => sub {
$second_connects++;
if ($second_connects == 1) {
$ch->reset; # explicit re-handshake
} else {
$ch->query("select 1", sub { ($rows) = @_; EV::break });
}
},
);
run_with_timeout(10);
cmp_ok($second_connects, '>=', 2, "reset triggers reconnect (on_connect fires twice)");
is($rows && @$rows ? $rows->[0][0] : undef, 1, "post-reset query succeeds");
$ch->finish if $ch->is_connected;
}
# 12: cancel() with nothing in-flight is a safe no-op.
SKIP: {
skip "Native port not reachable", 1 unless $nat_ok;
my ($ch, $rows);
$ch = EV::ClickHouse->new(
host => $host, port => $nat_port, protocol => 'native',
on_connect => sub {
$ch->cancel; # nothing pending â must not crash
$ch->query("select 1", sub { ($rows) = @_; EV::break });
},
);
run_with_timeout(10);
is($rows && @$rows ? $rows->[0][0] : undef, 1,
"cancel() with no in-flight is a no-op; subsequent query succeeds");
$ch->finish if $ch->is_connected;
}
# 13: on_data on HTTP protocol must croak (or error-deliver) â streaming is
# native-only.
SKIP: {
skip "HTTP port not reachable", 1 unless $http_ok;
my $ch;
$ch = EV::ClickHouse->new(
host => $host, port => $http_port,
on_connect => sub { EV::break },
);
run_with_timeout(5);
eval {
$ch->query("select 1 format TabSeparated",
{ on_data => sub { } },
sub { EV::break });
run_with_timeout(2);
};
like($@ || '', qr/native|on_data|http/i,
"on_data on HTTP croaks/refuses (native-only feature)")
or diag "no croak â got: " . ($@ || '<no exception>');
$ch->finish if $ch->is_connected;
}
# 14: IPv6 bracketed URI literal parse â uses 127.0.0.1 in brackets so we
# don't need an actual IPv6 listener.
SKIP: {
skip "Native port not reachable", 1 unless $nat_ok;
my ($ch, $rows);
$ch = EV::ClickHouse->new(
uri => "clickhouse://[$host]:$nat_port/default",
protocol => 'native',
on_connect => sub {
$ch->query("select 42", sub { ($rows) = @_; EV::break });
},
);
run_with_timeout(10);
is($rows && @$rows ? $rows->[0][0] : undef, 42,
"IPv6-bracketed URI ([host]:port/db) parses and connects");
$ch->finish if $ch->is_connected;
}
# 15-16: zero-row select must still populate column_names/types (regression
# for the empty-block schema fix).
SKIP: {
skip "Native port not reachable", 2 unless $nat_ok;
my ($ch, $rows, $names, $types);
$ch = EV::ClickHouse->new(
host => $host, port => $nat_port, protocol => 'native',
on_connect => sub {
$ch->query("select 1 as a, 'x' as b where 0", sub {
($rows) = @_;
$names = $ch->column_names;
$types = $ch->column_types;
EV::break;
});
},
);
run_with_timeout(10);
is_deeply($names, ['a', 'b'], "0-row select populates column_names");
is_deeply($types, ['UInt8', 'String'], "0-row select populates column_types");
$ch->finish if $ch->is_connected;
( run in 0.627 second using v1.01-cache-2.11-cpan-995e09ba956 )