Test pt-agent::send_data() with 400 error.

This commit is contained in:
Daniel Nichter
2013-10-09 12:10:56 -07:00
parent 9527daea4c
commit 3c2376023d
2 changed files with 59 additions and 2 deletions

View File

@@ -7751,12 +7751,12 @@ sub send_data {
if ( my $e = $EVAL_ERROR ) {
if (blessed($e) && $e->isa('Percona::WebAPI::Exception::Request')) {
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)'));
}
else {
chomp $e;
$logger->warning("Error sending $data_file: $e");
$logger->warning("Error sending $data_file ($data_file_size bytes): $e");
}
next DATA_FILE;
}

View File

@@ -171,6 +171,63 @@ is(
'Content-Type=multipart/form-data; boundary=Ym91bmRhcnk'
) 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.
# #############################################################################