Merge branch 'master' into 5534-limit-log-lines
[arvados.git] / services / keepstore / trash_worker_test.go
index e4f7fb3a0bbba60b16cdea6c165e3a6bda1c216b..3031c2582d57c1e9afa1a1e3fdd9c1fbed6d8a0d 100644 (file)
@@ -19,6 +19,8 @@ type TrashWorkerTestData struct {
        CreateInVolume1  bool
        UseDelayToCreate bool
 
+       UseTrashLifeTime bool
+
        DeleteLocator string
 
        ExpectLocator1 bool
@@ -154,20 +156,40 @@ func TestTrashWorkerIntegration_TwoDifferentLocatorsInVolume1(t *testing.T) {
        performTrashWorkerTest(testData, t)
 }
 
+/* Allow default Trash Life time to be used. Thus, the newly created block
+   will not be deleted becuase its Mtime is within the trash life time.
+*/
+func TestTrashWorkerIntegration_SameLocatorInTwoVolumesWithDefaultTrashLifeTime(t *testing.T) {
+       testData := TrashWorkerTestData{
+               Locator1: TEST_HASH,
+               Block1:   TEST_BLOCK,
+
+               Locator2: TEST_HASH_2,
+               Block2:   TEST_BLOCK_2,
+
+               CreateData:      true,
+               CreateInVolume1: true,
+
+               UseTrashLifeTime: true,
+
+               DeleteLocator: TEST_HASH, // locator 1
+
+               // Since trash life time is in effect, block won't be deleted.
+               ExpectLocator1: true,
+               ExpectLocator2: true,
+       }
+       performTrashWorkerTest(testData, t)
+}
+
 /* Perform the test */
 func performTrashWorkerTest(testData TrashWorkerTestData, t *testing.T) {
+       actual_permission_ttl := permission_ttl
+
        // Create Keep Volumes
        KeepVM = MakeTestVolumeManager(2)
 
-       // Set trash life time delta to 0 so that the test can delete the blocks right after create
-       DEFAULT_TRASH_LIFE_TIME = 0
-
-       // Delete from volume will not take place if the block MTime is within permission_ttl
-       permission_ttl = time.Duration(1) * time.Second
-
-       vols := KeepVM.Volumes()
-
        // Put test content
+       vols := KeepVM.Volumes()
        if testData.CreateData {
                vols[0].Put(testData.Locator1, testData.Block1)
                vols[0].Put(testData.Locator1+".meta", []byte("metadata"))
@@ -199,9 +221,16 @@ func performTrashWorkerTest(testData TrashWorkerTestData, t *testing.T) {
        trashList := list.New()
        trashList.PushBack(trashRequest)
        trashq = NewWorkQueue()
+
+       // Trash worker would not delete block if its Mtime is within trash life time.
+       // Hence, we will have to bypass it to allow the deletion to succeed.
+       if !testData.UseTrashLifeTime {
+               permission_ttl = time.Duration(1) * time.Second
+       }
        go RunTrashWorker(trashq)
+
        trashq.ReplaceQueue(trashList)
-       time.Sleep(10 * time.Millisecond) // give it a moment to finish processing the trash list
+       time.Sleep(10 * time.Millisecond) // give a moment to finish processing the list
 
        // Verify Locator1 to be un/deleted as expected
        data, _ := GetBlock(testData.Locator1, false)
@@ -245,6 +274,7 @@ func performTrashWorkerTest(testData TrashWorkerTestData, t *testing.T) {
        }
 
        // Done
+       permission_ttl = actual_permission_ttl
        trashq.Close()
        KeepVM.Quit()
 }