Skip to content
This repository has been archived by the owner on Jul 24, 2021. It is now read-only.

Commit

Permalink
also set both conflicting devices to the error state for better detec…
Browse files Browse the repository at this point in the history
…tion

This resolves Rollbar items 3490, 3491 occurring 2020-04-15.
  • Loading branch information
karenetheridge committed Apr 15, 2020
1 parent abb862d commit 2d1eb9e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/Conch/Controller/DeviceReport.pm
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,14 @@ sub process ($c) {
});

if (not $device) {
if (my $serial_device = $c->db_devices->find({ id => $c->stash('device_id') })) {
$serial_device->health('error');
$serial_device->update({ updated => \'now()' }) if $serial_device->is_changed;
}
if (my $system_uuid_device = $c->db_devices->find({ system_uuid => $unserialized_report->{system_uuid} })) {
$system_uuid_device->health('error');
$system_uuid_device->update({ updated => \'now()' }) if $system_uuid_device->is_changed;
}
return $c->status(400, { error => 'could not process report for device '
.$c->stash('device_id')
.($c->stash('exception') ? ': '.(split(/\n/, $c->stash('exception'), 2))[0] : '') });
Expand Down
6 changes: 6 additions & 0 deletions t/integration/device-reports.t
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ subtest 'system_uuid collisions' => sub {

$t->post_ok('/device/i_was_here_first', json => $report_data)
->json_cmp_deeply({ error => re(qr/could not process report for device i_was_here_first.*duplicate key value violates unique constraint "device_system_uuid_key"/) });

$existing_device->discard_changes;
is($existing_device->health, 'error', 'existing device had health set to error');

my $test_device = $t->app->db_devices->find('TEST');
is($test_device->health, 'error', 'TEST device had health set to error as well');
};

done_testing;

0 comments on commit 2d1eb9e

Please sign in to comment.