7490: added couple more datamanager tests with errors injected during GetCollections
[arvados.git] / services / datamanager / datamanager_test.go
index 26a2fbf92ba124c8cbe4e534c39931107f084dca..6e5a4df83c631e49865b5dd9239ff96ce5136d76 100644 (file)
@@ -6,6 +6,8 @@ import (
        "git.curoverse.com/arvados.git/sdk/go/arvadosclient"
        "git.curoverse.com/arvados.git/sdk/go/arvadostest"
        "git.curoverse.com/arvados.git/sdk/go/keepclient"
+       "git.curoverse.com/arvados.git/services/datamanager/collection"
+       "git.curoverse.com/arvados.git/services/datamanager/summary"
        "io/ioutil"
        "net/http"
        "os"
@@ -526,3 +528,56 @@ func TestRunDatamanagerAsNonAdminUser(t *testing.T) {
                t.Fatalf("Expected error during singlerun as non-admin user")
        }
 }
+
+func TestPutAndGetBlocks_NoErrorDuringSingleRun(t *testing.T) {
+       testOldBlocksNotDeletedOnDataManagerError(t, "", "", false, false)
+}
+
+func TestPutAndGetBlocks_ErrorDuringGetCollectionsBadWriteTo(t *testing.T) {
+       testOldBlocksNotDeletedOnDataManagerError(t, "/badwritetofile", "", true, true)
+}
+
+func TestPutAndGetBlocks_ErrorDuringGetCollectionsBadHeapProfileFilename(t *testing.T) {
+       testOldBlocksNotDeletedOnDataManagerError(t, "", "/badheapprofilefile", false, true)
+}
+
+/*
+  Create some blocks and backdate some of them.
+  Run datamanager while producing an error condition.
+  Verify that the blocks are hence not deleted.
+*/
+func testOldBlocksNotDeletedOnDataManagerError(t *testing.T, writeDataTo string, heapProfileFile string, expectError bool, expectOldBlocks bool) {
+       defer TearDownDataManagerTest(t)
+       SetupDataManagerTest(t)
+
+       // Put some blocks and backdate them.
+       var oldUnusedBlockLocators []string
+       oldUnusedBlockData := "this block will have older mtime"
+       for i := 0; i < 5; i++ {
+               oldUnusedBlockLocators = append(oldUnusedBlockLocators, putBlock(t, fmt.Sprintf("%s%d", oldUnusedBlockData, i)))
+       }
+       backdateBlocks(t, oldUnusedBlockLocators)
+
+       // Run data manager
+       summary.WriteDataTo = writeDataTo
+       collection.HeapProfileFilename = heapProfileFile
+
+       err := singlerun(arv)
+       if !expectError {
+               if err != nil {
+                       t.Fatalf("Got an error during datamanager singlerun: %v", err)
+               }
+       } else {
+               if err == nil {
+                       t.Fatalf("Expected error during datamanager singlerun")
+               }
+       }
+       waitUntilQueuesFinishWork(t)
+
+       // Get block indexes and verify that all backdated blocks are not/deleted as expected
+       if expectOldBlocks {
+               verifyBlocks(t, nil, oldUnusedBlockLocators, 2)
+       } else {
+               verifyBlocks(t, oldUnusedBlockLocators, nil, 2)
+       }
+}