EV-ClickHouse
view release on metacpan or search on metacpan
t/24_review_gaps.t view on Meta::CPAN
my ($timeout) = @_;
my $t = EV::timer($timeout, 0, sub { EV::break });
EV::run;
}
# 1-3: profile_rows and profile_bytes (HTTP â populated from X-ClickHouse-Summary).
SKIP: {
skip "HTTP port not reachable", 3 unless $http_ok;
my ($ch, $rows, $err);
$ch = EV::ClickHouse->new(
host => $host, port => $http_port,
on_connect => sub {
$ch->query("select number from numbers(123) format TabSeparated", sub {
($rows, $err) = @_;
EV::break;
});
},
);
run_with_timeout(10);
ok(!$err, "HTTP profile: query ok") or diag "err=$err";
cmp_ok($ch->profile_rows // 0, '>=', 123, "HTTP profile_rows >= 123");
cmp_ok($ch->profile_bytes // 0, '>', 0, "HTTP profile_bytes > 0");
$ch->finish if $ch->is_connected;
}
# 4-6: profile_rows and profile_bytes (native â Progress packet).
SKIP: {
skip "Native port not reachable", 3 unless $nat_ok;
my ($ch, $rows, $err);
$ch = EV::ClickHouse->new(
host => $host, port => $nat_port, protocol => 'native',
on_connect => sub {
$ch->query("select number from numbers(500)", sub {
($rows, $err) = @_;
EV::break;
});
},
);
run_with_timeout(10);
ok(!$err, "native profile: query ok") or diag "err=$err";
cmp_ok($ch->profile_rows // 0, '>=', 500, "native profile_rows >= 500");
cmp_ok($ch->profile_bytes // 0, '>', 0, "native profile_bytes > 0");
$ch->finish if $ch->is_connected;
}
# 7: UUID 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',
on_connect => sub {
$ch->query("select toUUID('6ba7b810-9dad-11d1-80b4-00c04fd430c8')", sub {
($rows) = @_; EV::break;
});
},
);
run_with_timeout(10);
is($rows && @$rows ? $rows->[0][0] : undef,
'6ba7b810-9dad-11d1-80b4-00c04fd430c8',
"UUID decoded as canonical text");
$ch->finish if $ch->is_connected;
}
# 8: Date32 column round-trip with explicit decode (text form).
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_datetime => 1,
on_connect => sub {
$ch->query("select toDate32('2099-12-31')", sub {
($rows) = @_; EV::break;
});
},
);
run_with_timeout(10);
is($rows && @$rows ? $rows->[0][0] : undef, '2099-12-31',
"Date32 decoded as text past 2038 (no time_t overflow)");
$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);
};
( run in 0.419 second using v1.01-cache-2.11-cpan-f4a522933cf )