From 7e8d918a3a8a65f571b3fb8704a9d2f45131f2ad Mon Sep 17 00:00:00 2001 From: Nate Nuss Date: Mon, 13 Apr 2015 17:27:42 +0200 Subject: [PATCH 1/3] Test double-delete ok --- t/rest.t | 3 +++ 1 file changed, 3 insertions(+) diff --git a/t/rest.t b/t/rest.t index 26a4540..054ce78 100755 --- a/t/rest.t +++ b/t/rest.t @@ -121,5 +121,8 @@ foreach my $i (0..$num_items) { is($skv->get("${key}$i"), undef); } +# Multiple delete ok +is($skv->delete("${key}0"), 1); +is($skv->delete("${key}0"), 1); done_testing(); From 30f33b9ec9f32964a6557b1566ab59683e8e68ae Mon Sep 17 00:00:00 2001 From: Nate Nuss Date: Mon, 13 Apr 2015 17:29:11 +0200 Subject: [PATCH 2/3] Test for typical delete responses As currently defined ShardedKV::Storage::Rest suceeds on: 2xx and fails on any other HTTP response code. --- t/rest.t | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/t/rest.t b/t/rest.t index 054ce78..995e877 100755 --- a/t/rest.t +++ b/t/rest.t @@ -60,6 +60,9 @@ sub Test::HTTP::Server::Request::test } } elsif ($self->{request}->[0] eq 'DELETE') { $self->{out_headers}->{'Content-Length'} = 0; + if ($path =~ m@\A /test/DELETE-(\d{3}) \z@x) { + $self->{out_code} = "$1 ($1 Response)"; + } unlink "$tempdir/$key.$me"; } return ""; @@ -125,4 +128,12 @@ foreach my $i (0..$num_items) { is($skv->delete("${key}0"), 1); is($skv->delete("${key}0"), 1); +# Delete successes +is($skv->delete("DELETE-200"), 1); +is($skv->delete("DELETE-204"), 1); + +# Delete failures +is($skv->delete("DELETE-403"), 0); +is($skv->delete("DELETE-500"), 0); + done_testing(); From b2a9fe93449e3ac551bfe8e476ff8c25cbd717c0 Mon Sep 17 00:00:00 2001 From: Nate Nuss Date: Mon, 13 Apr 2015 17:34:54 +0200 Subject: [PATCH 3/3] Consider a 404 response to DELETE request to be a delete() success. --- lib/ShardedKV/Storage/Rest.pm | 3 +++ t/rest.t | 1 + 2 files changed, 4 insertions(+) diff --git a/lib/ShardedKV/Storage/Rest.pm b/lib/ShardedKV/Storage/Rest.pm index 175edac..60f609d 100644 --- a/lib/ShardedKV/Storage/Rest.pm +++ b/lib/ShardedKV/Storage/Rest.pm @@ -114,6 +114,9 @@ sub delete { if ($code >= 200 && $code < 300) { return 1; } + if ($code == 404) { + return 1; # already gone + } return 0; } diff --git a/t/rest.t b/t/rest.t index 995e877..b098ce8 100755 --- a/t/rest.t +++ b/t/rest.t @@ -131,6 +131,7 @@ is($skv->delete("${key}0"), 1); # Delete successes is($skv->delete("DELETE-200"), 1); is($skv->delete("DELETE-204"), 1); +is($skv->delete("DELETE-404"), 1); # Delete failures is($skv->delete("DELETE-403"), 0);