3448: unit tests for deleting new blocks
authorTim Pierce <twp@curoverse.com>
Thu, 21 Aug 2014 20:33:50 +0000 (16:33 -0400)
committerTim Pierce <twp@curoverse.com>
Thu, 21 Aug 2014 20:33:50 +0000 (16:33 -0400)
Added cases to TestDeleteHandler to test that blocks newer than
-permission_ttl will not be removed from the volume even if
volume.Delete() returned true.

Refs #3448.

services/keepstore/handler_test.go
services/keepstore/volume.go

index 64a417f9a7ae24d01d4905c7df34437fbd4c8fc6..200e1b17930ebcad9193309b8c039b74585af318 100644 (file)
@@ -451,6 +451,11 @@ func TestDeleteHandler(t *testing.T) {
        vols := KeepVM.Volumes()
        vols[0].Put(TEST_HASH, TEST_BLOCK)
 
+       // Explicitly set the permission_ttl to 0 for these
+       // tests, to ensure the MockVolume deletes the blocks
+       // even though they have just been created.
+       permission_ttl = time.Duration(0)
+
        // Set up a REST router for testing the handlers.
        rest := MakeRESTRouter()
 
@@ -536,6 +541,29 @@ func TestDeleteHandler(t *testing.T) {
        if !block_deleted {
                t.Error("superuser_existing_block_req: block not deleted")
        }
+
+       // A DELETE request on a block newer than permission_ttl should return
+       // success but leave the block on the volume.
+       vols[0].Put(TEST_HASH, TEST_BLOCK)
+       permission_ttl = time.Duration(1) * time.Hour
+
+       response = IssueRequest(rest, superuser_existing_block_req)
+       ExpectStatusCode(t,
+               "data manager request, existing block",
+               http.StatusOK,
+               response)
+       // Expect response {"copies_deleted":1,"copies_failed":0}
+       expected_dc = deletecounter{1, 0}
+       json.NewDecoder(response.Body).Decode(&response_dc)
+       if response_dc != expected_dc {
+               t.Errorf("superuser_existing_block_req\nexpected: %+v\nreceived: %+v",
+                       expected_dc, response_dc)
+       }
+       // Confirm the block has NOT been deleted.
+       _, err = vols[0].Get(TEST_HASH)
+       if err != nil {
+               t.Errorf("testing delete on new block: %s\n", err)
+       }
 }
 
 // ====================
index fbf63b729c86728e9abf547e716eaf536a3f6896..0406c3d1983fc9ce718f20797447d7218ea93276 100644 (file)
@@ -79,6 +79,9 @@ func (v *MockVolume) Index(prefix string) string {
 
 func (v *MockVolume) Delete(loc string) error {
        if _, ok := v.Store[loc]; ok {
+               if time.Since(v.Timestamps[loc]) < permission_ttl {
+                       return nil
+               }
                delete(v.Store, loc)
                return nil
        }