mirror of
https://github.com/percona/percona-toolkit.git
synced 2026-04-26 01:02:25 +08:00
Test pt-agent::send_data() with 400 error.
This commit is contained in:
+2
-2
@@ -7751,12 +7751,12 @@ sub send_data {
|
|||||||
if ( my $e = $EVAL_ERROR ) {
|
if ( my $e = $EVAL_ERROR ) {
|
||||||
if (blessed($e) && $e->isa('Percona::WebAPI::Exception::Request')) {
|
if (blessed($e) && $e->isa('Percona::WebAPI::Exception::Request')) {
|
||||||
my $error_msg = $client->response->content;
|
my $error_msg = $client->response->content;
|
||||||
$logger->warning('Error ' . $e->status . " sending $data_file: "
|
$logger->warning('Error ' . $e->status . " sending $data_file ($data_file_size bytes): "
|
||||||
. ($error_msg || '(No error message from server)'));
|
. ($error_msg || '(No error message from server)'));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
chomp $e;
|
chomp $e;
|
||||||
$logger->warning("Error sending $data_file: $e");
|
$logger->warning("Error sending $data_file ($data_file_size bytes): $e");
|
||||||
}
|
}
|
||||||
next DATA_FILE;
|
next DATA_FILE;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -171,6 +171,63 @@ is(
|
|||||||
'Content-Type=multipart/form-data; boundary=Ym91bmRhcnk'
|
'Content-Type=multipart/form-data; boundary=Ym91bmRhcnk'
|
||||||
) or diag(Dumper($ua));
|
) or diag(Dumper($ua));
|
||||||
|
|
||||||
|
# #############################################################################
|
||||||
|
# Error 400 on send
|
||||||
|
# #############################################################################
|
||||||
|
|
||||||
|
@log = ();
|
||||||
|
$client->ua->{content}->{post} = [];
|
||||||
|
$ua->{requests} = [];
|
||||||
|
|
||||||
|
`cp $trunk/$sample/query-history/data001.json $tmpdir/query-history/1.data001.data`;
|
||||||
|
|
||||||
|
$ua->{responses}->{get} = [
|
||||||
|
{
|
||||||
|
headers => { 'X-Percona-Resource-Type' => 'Agent' },
|
||||||
|
content => as_hashref($agent, with_links => 1),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
$ua->{responses}->{post} = [
|
||||||
|
{
|
||||||
|
code => 400,
|
||||||
|
content => '',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
$output = output(
|
||||||
|
sub {
|
||||||
|
pt_agent::send_data(
|
||||||
|
api_key => '123',
|
||||||
|
service => 'query-history',
|
||||||
|
lib_dir => $tmpdir,
|
||||||
|
spool_dir => $tmpdir,
|
||||||
|
# optional, for testing:
|
||||||
|
client => $client,
|
||||||
|
entry_links => $links,
|
||||||
|
agent => $agent,
|
||||||
|
log_file => "$tmpdir/log",
|
||||||
|
json => $json,
|
||||||
|
delay => 0,
|
||||||
|
),
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
is(
|
||||||
|
scalar @{$client->ua->{content}->{post}},
|
||||||
|
1,
|
||||||
|
"400: sent resource"
|
||||||
|
) or diag(
|
||||||
|
$output,
|
||||||
|
Dumper($client->ua->{content}->{post}),
|
||||||
|
`cat $tmpdir/logs/query-history.send`
|
||||||
|
);
|
||||||
|
|
||||||
|
ok(
|
||||||
|
-f "$tmpdir/query-history/1.data001.data",
|
||||||
|
"400: file not removed"
|
||||||
|
) or diag($output);
|
||||||
|
|
||||||
# #############################################################################
|
# #############################################################################
|
||||||
# Done.
|
# Done.
|
||||||
# #############################################################################
|
# #############################################################################
|
||||||
|
|||||||
Reference in New Issue
Block a user