15 "git.curoverse.com/arvados.git/sdk/go/arvados"
16 "git.curoverse.com/arvados.git/sdk/go/arvadostest"
20 Error(args ...interface{})
21 Errorf(format string, args ...interface{})
25 Fatal(args ...interface{})
26 Fatalf(format string, args ...interface{})
27 Log(args ...interface{})
28 Logf(format string, args ...interface{})
31 // A TestableVolumeFactory returns a new TestableVolume. The factory
32 // function, and the TestableVolume it returns, can use "t" to write
33 // logs, fail the current test, etc.
34 type TestableVolumeFactory func(t TB) TestableVolume
36 // DoGenericVolumeTests runs a set of tests that every TestableVolume
37 // is expected to pass. It calls factory to create a new TestableVolume
38 // for each test case, to avoid leaking state between tests.
39 func DoGenericVolumeTests(t TB, factory TestableVolumeFactory) {
41 testGetNoSuchBlock(t, factory)
43 testCompareNonexistent(t, factory)
44 testCompareSameContent(t, factory, TestHash, TestBlock)
45 testCompareSameContent(t, factory, EmptyHash, EmptyBlock)
46 testCompareWithCollision(t, factory, TestHash, TestBlock, []byte("baddata"))
47 testCompareWithCollision(t, factory, TestHash, TestBlock, EmptyBlock)
48 testCompareWithCollision(t, factory, EmptyHash, EmptyBlock, TestBlock)
49 testCompareWithCorruptStoredData(t, factory, TestHash, TestBlock, []byte("baddata"))
50 testCompareWithCorruptStoredData(t, factory, TestHash, TestBlock, EmptyBlock)
51 testCompareWithCorruptStoredData(t, factory, EmptyHash, EmptyBlock, []byte("baddata"))
53 testPutBlockWithSameContent(t, factory, TestHash, TestBlock)
54 testPutBlockWithSameContent(t, factory, EmptyHash, EmptyBlock)
55 testPutBlockWithDifferentContent(t, factory, arvadostest.MD5CollisionMD5, arvadostest.MD5CollisionData[0], arvadostest.MD5CollisionData[1])
56 testPutBlockWithDifferentContent(t, factory, arvadostest.MD5CollisionMD5, EmptyBlock, arvadostest.MD5CollisionData[0])
57 testPutBlockWithDifferentContent(t, factory, arvadostest.MD5CollisionMD5, arvadostest.MD5CollisionData[0], EmptyBlock)
58 testPutBlockWithDifferentContent(t, factory, EmptyHash, EmptyBlock, arvadostest.MD5CollisionData[0])
59 testPutMultipleBlocks(t, factory)
61 testPutAndTouch(t, factory)
62 testTouchNoSuchBlock(t, factory)
64 testMtimeNoSuchBlock(t, factory)
66 testIndexTo(t, factory)
68 testDeleteNewBlock(t, factory)
69 testDeleteOldBlock(t, factory)
70 testDeleteNoSuchBlock(t, factory)
72 testStatus(t, factory)
74 testString(t, factory)
76 testUpdateReadOnly(t, factory)
78 testGetConcurrent(t, factory)
79 testPutConcurrent(t, factory)
81 testPutFullBlock(t, factory)
83 testTrashUntrash(t, factory)
84 testTrashEmptyTrashUntrash(t, factory)
87 // Put a test block, get it and verify content
88 // Test should pass for both writable and read-only volumes
89 func testGet(t TB, factory TestableVolumeFactory) {
93 v.PutRaw(TestHash, TestBlock)
95 buf := make([]byte, BlockSize)
96 n, err := v.Get(context.Background(), TestHash, buf)
101 if bytes.Compare(buf[:n], TestBlock) != 0 {
102 t.Errorf("expected %s, got %s", string(TestBlock), string(buf))
106 // Invoke get on a block that does not exist in volume; should result in error
107 // Test should pass for both writable and read-only volumes
108 func testGetNoSuchBlock(t TB, factory TestableVolumeFactory) {
112 buf := make([]byte, BlockSize)
113 if _, err := v.Get(context.Background(), TestHash2, buf); err == nil {
114 t.Errorf("Expected error while getting non-existing block %v", TestHash2)
118 // Compare() should return os.ErrNotExist if the block does not exist.
119 // Otherwise, writing new data causes CompareAndTouch() to generate
120 // error logs even though everything is working fine.
121 func testCompareNonexistent(t TB, factory TestableVolumeFactory) {
125 err := v.Compare(context.Background(), TestHash, TestBlock)
126 if err != os.ErrNotExist {
127 t.Errorf("Got err %T %q, expected os.ErrNotExist", err, err)
131 // Put a test block and compare the locator with same content
132 // Test should pass for both writable and read-only volumes
133 func testCompareSameContent(t TB, factory TestableVolumeFactory, testHash string, testData []byte) {
137 v.PutRaw(testHash, testData)
139 // Compare the block locator with same content
140 err := v.Compare(context.Background(), testHash, testData)
142 t.Errorf("Got err %q, expected nil", err)
146 // Test behavior of Compare() when stored data matches expected
147 // checksum but differs from new data we need to store. Requires
148 // testHash = md5(testDataA).
150 // Test should pass for both writable and read-only volumes
151 func testCompareWithCollision(t TB, factory TestableVolumeFactory, testHash string, testDataA, testDataB []byte) {
155 v.PutRaw(testHash, testDataA)
157 // Compare the block locator with different content; collision
158 err := v.Compare(context.Background(), TestHash, testDataB)
160 t.Errorf("Got err nil, expected error due to collision")
164 // Test behavior of Compare() when stored data has become
165 // corrupted. Requires testHash = md5(testDataA) != md5(testDataB).
167 // Test should pass for both writable and read-only volumes
168 func testCompareWithCorruptStoredData(t TB, factory TestableVolumeFactory, testHash string, testDataA, testDataB []byte) {
172 v.PutRaw(TestHash, testDataB)
174 err := v.Compare(context.Background(), testHash, testDataA)
175 if err == nil || err == CollisionError {
176 t.Errorf("Got err %+v, expected non-collision error", err)
180 // Put a block and put again with same content
181 // Test is intended for only writable volumes
182 func testPutBlockWithSameContent(t TB, factory TestableVolumeFactory, testHash string, testData []byte) {
186 if v.Writable() == false {
190 err := v.Put(context.Background(), testHash, testData)
192 t.Errorf("Got err putting block %q: %q, expected nil", TestBlock, err)
195 err = v.Put(context.Background(), testHash, testData)
197 t.Errorf("Got err putting block second time %q: %q, expected nil", TestBlock, err)
201 // Put a block and put again with different content
202 // Test is intended for only writable volumes
203 func testPutBlockWithDifferentContent(t TB, factory TestableVolumeFactory, testHash string, testDataA, testDataB []byte) {
207 if v.Writable() == false {
211 v.PutRaw(testHash, testDataA)
213 putErr := v.Put(context.Background(), testHash, testDataB)
214 buf := make([]byte, BlockSize)
215 n, getErr := v.Get(context.Background(), testHash, buf)
217 // Put must not return a nil error unless it has
218 // overwritten the existing data.
219 if bytes.Compare(buf[:n], testDataB) != 0 {
220 t.Errorf("Put succeeded but Get returned %+q, expected %+q", buf[:n], testDataB)
223 // It is permissible for Put to fail, but it must
224 // leave us with either the original data, the new
225 // data, or nothing at all.
226 if getErr == nil && bytes.Compare(buf[:n], testDataA) != 0 && bytes.Compare(buf[:n], testDataB) != 0 {
227 t.Errorf("Put failed but Get returned %+q, which is neither %+q nor %+q", buf[:n], testDataA, testDataB)
232 // Put and get multiple blocks
233 // Test is intended for only writable volumes
234 func testPutMultipleBlocks(t TB, factory TestableVolumeFactory) {
238 if v.Writable() == false {
242 err := v.Put(context.Background(), TestHash, TestBlock)
244 t.Errorf("Got err putting block %q: %q, expected nil", TestBlock, err)
247 err = v.Put(context.Background(), TestHash2, TestBlock2)
249 t.Errorf("Got err putting block %q: %q, expected nil", TestBlock2, err)
252 err = v.Put(context.Background(), TestHash3, TestBlock3)
254 t.Errorf("Got err putting block %q: %q, expected nil", TestBlock3, err)
257 data := make([]byte, BlockSize)
258 n, err := v.Get(context.Background(), TestHash, data)
262 if bytes.Compare(data[:n], TestBlock) != 0 {
263 t.Errorf("Block present, but got %+q, expected %+q", data[:n], TestBlock)
267 n, err = v.Get(context.Background(), TestHash2, data)
271 if bytes.Compare(data[:n], TestBlock2) != 0 {
272 t.Errorf("Block present, but got %+q, expected %+q", data[:n], TestBlock2)
276 n, err = v.Get(context.Background(), TestHash3, data)
280 if bytes.Compare(data[:n], TestBlock3) != 0 {
281 t.Errorf("Block present, but to %+q, expected %+q", data[:n], TestBlock3)
287 // Test that when applying PUT to a block that already exists,
288 // the block's modification time is updated.
289 // Test is intended for only writable volumes
290 func testPutAndTouch(t TB, factory TestableVolumeFactory) {
294 if v.Writable() == false {
298 if err := v.Put(context.Background(), TestHash, TestBlock); err != nil {
302 // We'll verify { t0 < threshold < t1 }, where t0 is the
303 // existing block's timestamp on disk before Put() and t1 is
304 // its timestamp after Put().
305 threshold := time.Now().Add(-time.Second)
307 // Set the stored block's mtime far enough in the past that we
308 // can see the difference between "timestamp didn't change"
309 // and "timestamp granularity is too low".
310 v.TouchWithDate(TestHash, time.Now().Add(-20*time.Second))
312 // Make sure v.Mtime() agrees the above Utime really worked.
313 if t0, err := v.Mtime(TestHash); err != nil || t0.IsZero() || !t0.Before(threshold) {
314 t.Errorf("Setting mtime failed: %v, %v", t0, err)
317 // Write the same block again.
318 if err := v.Put(context.Background(), TestHash, TestBlock); err != nil {
322 // Verify threshold < t1
323 if t1, err := v.Mtime(TestHash); err != nil {
325 } else if t1.Before(threshold) {
326 t.Errorf("t1 %v should be >= threshold %v after v.Put ", t1, threshold)
330 // Touching a non-existing block should result in error.
331 // Test should pass for both writable and read-only volumes
332 func testTouchNoSuchBlock(t TB, factory TestableVolumeFactory) {
336 if err := v.Touch(TestHash); err == nil {
337 t.Error("Expected error when attempted to touch a non-existing block")
341 // Invoking Mtime on a non-existing block should result in error.
342 // Test should pass for both writable and read-only volumes
343 func testMtimeNoSuchBlock(t TB, factory TestableVolumeFactory) {
347 if _, err := v.Mtime("12345678901234567890123456789012"); err == nil {
348 t.Error("Expected error when updating Mtime on a non-existing block")
352 // Put a few blocks and invoke IndexTo with:
355 // * with no such prefix
356 // Test should pass for both writable and read-only volumes
357 func testIndexTo(t TB, factory TestableVolumeFactory) {
361 // minMtime and maxMtime are the minimum and maximum
362 // acceptable values the index can report for our test
363 // blocks. 1-second precision is acceptable.
364 minMtime := time.Now().UTC().UnixNano()
365 minMtime -= minMtime % 1e9
367 v.PutRaw(TestHash, TestBlock)
368 v.PutRaw(TestHash2, TestBlock2)
369 v.PutRaw(TestHash3, TestBlock3)
371 maxMtime := time.Now().UTC().UnixNano()
372 if maxMtime%1e9 > 0 {
373 maxMtime -= maxMtime % 1e9
377 // Blocks whose names aren't Keep hashes should be omitted from
379 v.PutRaw("fffffffffnotreallyahashfffffffff", nil)
380 v.PutRaw("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", nil)
381 v.PutRaw("f0000000000000000000000000000000f", nil)
384 buf := new(bytes.Buffer)
386 indexRows := strings.Split(string(buf.Bytes()), "\n")
387 sort.Strings(indexRows)
388 sortedIndex := strings.Join(indexRows, "\n")
389 m := regexp.MustCompile(
390 `^\n` + TestHash + `\+\d+ (\d+)\n` +
391 TestHash3 + `\+\d+ \d+\n` +
392 TestHash2 + `\+\d+ \d+$`,
393 ).FindStringSubmatch(sortedIndex)
395 t.Errorf("Got index %q for empty prefix", sortedIndex)
397 mtime, err := strconv.ParseInt(m[1], 10, 64)
400 } else if mtime < minMtime || mtime > maxMtime {
401 t.Errorf("got %d for TestHash timestamp, expected %d <= t <= %d",
402 mtime, minMtime, maxMtime)
406 for _, prefix := range []string{"f", "f15", "f15ac"} {
407 buf = new(bytes.Buffer)
408 v.IndexTo(prefix, buf)
410 m, err := regexp.MatchString(`^`+TestHash2+`\+\d+ \d+\n$`, string(buf.Bytes()))
414 t.Errorf("Got index %q for prefix %s", string(buf.Bytes()), prefix)
418 for _, prefix := range []string{"zero", "zip", "zilch"} {
419 buf = new(bytes.Buffer)
420 err := v.IndexTo(prefix, buf)
422 t.Errorf("Got error on IndexTo with no such prefix %v", err.Error())
423 } else if buf.Len() != 0 {
424 t.Errorf("Expected empty list for IndexTo with no such prefix %s", prefix)
429 // Calling Delete() for a block immediately after writing it (not old enough)
430 // should neither delete the data nor return an error.
431 // Test is intended for only writable volumes
432 func testDeleteNewBlock(t TB, factory TestableVolumeFactory) {
435 theConfig.BlobSignatureTTL.Set("5m")
437 if v.Writable() == false {
441 v.Put(context.Background(), TestHash, TestBlock)
443 if err := v.Trash(TestHash); err != nil {
446 data := make([]byte, BlockSize)
447 n, err := v.Get(context.Background(), TestHash, data)
450 } else if bytes.Compare(data[:n], TestBlock) != 0 {
451 t.Errorf("Got data %+q, expected %+q", data[:n], TestBlock)
455 // Calling Delete() for a block with a timestamp older than
456 // BlobSignatureTTL seconds in the past should delete the data.
457 // Test is intended for only writable volumes
458 func testDeleteOldBlock(t TB, factory TestableVolumeFactory) {
461 theConfig.BlobSignatureTTL.Set("5m")
463 if v.Writable() == false {
467 v.Put(context.Background(), TestHash, TestBlock)
468 v.TouchWithDate(TestHash, time.Now().Add(-2*theConfig.BlobSignatureTTL.Duration()))
470 if err := v.Trash(TestHash); err != nil {
473 data := make([]byte, BlockSize)
474 if _, err := v.Get(context.Background(), TestHash, data); err == nil || !os.IsNotExist(err) {
475 t.Errorf("os.IsNotExist(%v) should have been true", err)
478 _, err := v.Mtime(TestHash)
479 if err == nil || !os.IsNotExist(err) {
480 t.Fatalf("os.IsNotExist(%v) should have been true", err)
483 err = v.Compare(context.Background(), TestHash, TestBlock)
484 if err == nil || !os.IsNotExist(err) {
485 t.Fatalf("os.IsNotExist(%v) should have been true", err)
488 indexBuf := new(bytes.Buffer)
489 v.IndexTo("", indexBuf)
490 if strings.Contains(string(indexBuf.Bytes()), TestHash) {
491 t.Fatalf("Found trashed block in IndexTo")
494 err = v.Touch(TestHash)
495 if err == nil || !os.IsNotExist(err) {
496 t.Fatalf("os.IsNotExist(%v) should have been true", err)
500 // Calling Delete() for a block that does not exist should result in error.
501 // Test should pass for both writable and read-only volumes
502 func testDeleteNoSuchBlock(t TB, factory TestableVolumeFactory) {
506 if err := v.Trash(TestHash2); err == nil {
507 t.Errorf("Expected error when attempting to delete a non-existing block")
511 // Invoke Status and verify that VolumeStatus is returned
512 // Test should pass for both writable and read-only volumes
513 func testStatus(t TB, factory TestableVolumeFactory) {
517 // Get node status and make a basic sanity check.
519 if status.DeviceNum == 0 {
520 t.Errorf("uninitialized device_num in %v", status)
523 if status.BytesFree == 0 {
524 t.Errorf("uninitialized bytes_free in %v", status)
527 if status.BytesUsed == 0 {
528 t.Errorf("uninitialized bytes_used in %v", status)
532 // Invoke String for the volume; expect non-empty result
533 // Test should pass for both writable and read-only volumes
534 func testString(t TB, factory TestableVolumeFactory) {
538 if id := v.String(); len(id) == 0 {
539 t.Error("Got empty string for v.String()")
543 // Putting, updating, touching, and deleting blocks from a read-only volume result in error.
544 // Test is intended for only read-only volumes
545 func testUpdateReadOnly(t TB, factory TestableVolumeFactory) {
549 if v.Writable() == true {
553 v.PutRaw(TestHash, TestBlock)
554 buf := make([]byte, BlockSize)
556 // Get from read-only volume should succeed
557 _, err := v.Get(context.Background(), TestHash, buf)
559 t.Errorf("got err %v, expected nil", err)
562 // Put a new block to read-only volume should result in error
563 err = v.Put(context.Background(), TestHash2, TestBlock2)
565 t.Errorf("Expected error when putting block in a read-only volume")
567 _, err = v.Get(context.Background(), TestHash2, buf)
569 t.Errorf("Expected error when getting block whose put in read-only volume failed")
572 // Touch a block in read-only volume should result in error
573 err = v.Touch(TestHash)
575 t.Errorf("Expected error when touching block in a read-only volume")
578 // Delete a block from a read-only volume should result in error
579 err = v.Trash(TestHash)
581 t.Errorf("Expected error when deleting block from a read-only volume")
584 // Overwriting an existing block in read-only volume should result in error
585 err = v.Put(context.Background(), TestHash, TestBlock)
587 t.Errorf("Expected error when putting block in a read-only volume")
591 // Launch concurrent Gets
592 // Test should pass for both writable and read-only volumes
593 func testGetConcurrent(t TB, factory TestableVolumeFactory) {
597 v.PutRaw(TestHash, TestBlock)
598 v.PutRaw(TestHash2, TestBlock2)
599 v.PutRaw(TestHash3, TestBlock3)
601 sem := make(chan int)
603 buf := make([]byte, BlockSize)
604 n, err := v.Get(context.Background(), TestHash, buf)
606 t.Errorf("err1: %v", err)
608 if bytes.Compare(buf[:n], TestBlock) != 0 {
609 t.Errorf("buf should be %s, is %s", string(TestBlock), string(buf[:n]))
615 buf := make([]byte, BlockSize)
616 n, err := v.Get(context.Background(), TestHash2, buf)
618 t.Errorf("err2: %v", err)
620 if bytes.Compare(buf[:n], TestBlock2) != 0 {
621 t.Errorf("buf should be %s, is %s", string(TestBlock2), string(buf[:n]))
627 buf := make([]byte, BlockSize)
628 n, err := v.Get(context.Background(), TestHash3, buf)
630 t.Errorf("err3: %v", err)
632 if bytes.Compare(buf[:n], TestBlock3) != 0 {
633 t.Errorf("buf should be %s, is %s", string(TestBlock3), string(buf[:n]))
638 // Wait for all goroutines to finish
639 for done := 0; done < 3; done++ {
644 // Launch concurrent Puts
645 // Test is intended for only writable volumes
646 func testPutConcurrent(t TB, factory TestableVolumeFactory) {
650 if v.Writable() == false {
654 sem := make(chan int)
655 go func(sem chan int) {
656 err := v.Put(context.Background(), TestHash, TestBlock)
658 t.Errorf("err1: %v", err)
663 go func(sem chan int) {
664 err := v.Put(context.Background(), TestHash2, TestBlock2)
666 t.Errorf("err2: %v", err)
671 go func(sem chan int) {
672 err := v.Put(context.Background(), TestHash3, TestBlock3)
674 t.Errorf("err3: %v", err)
679 // Wait for all goroutines to finish
680 for done := 0; done < 3; done++ {
684 // Double check that we actually wrote the blocks we expected to write.
685 buf := make([]byte, BlockSize)
686 n, err := v.Get(context.Background(), TestHash, buf)
688 t.Errorf("Get #1: %v", err)
690 if bytes.Compare(buf[:n], TestBlock) != 0 {
691 t.Errorf("Get #1: expected %s, got %s", string(TestBlock), string(buf[:n]))
694 n, err = v.Get(context.Background(), TestHash2, buf)
696 t.Errorf("Get #2: %v", err)
698 if bytes.Compare(buf[:n], TestBlock2) != 0 {
699 t.Errorf("Get #2: expected %s, got %s", string(TestBlock2), string(buf[:n]))
702 n, err = v.Get(context.Background(), TestHash3, buf)
704 t.Errorf("Get #3: %v", err)
706 if bytes.Compare(buf[:n], TestBlock3) != 0 {
707 t.Errorf("Get #3: expected %s, got %s", string(TestBlock3), string(buf[:n]))
711 // Write and read back a full size block
712 func testPutFullBlock(t TB, factory TestableVolumeFactory) {
720 wdata := make([]byte, BlockSize)
722 wdata[BlockSize-1] = 'z'
723 hash := fmt.Sprintf("%x", md5.Sum(wdata))
724 err := v.Put(context.Background(), hash, wdata)
728 buf := make([]byte, BlockSize)
729 n, err := v.Get(context.Background(), hash, buf)
733 if bytes.Compare(buf[:n], wdata) != 0 {
734 t.Error("buf %+q != wdata %+q", buf[:n], wdata)
738 // With TrashLifetime != 0, perform:
739 // Trash an old block - which either raises ErrNotImplemented or succeeds
740 // Untrash - which either raises ErrNotImplemented or succeeds
741 // Get - which must succeed
742 func testTrashUntrash(t TB, factory TestableVolumeFactory) {
746 theConfig.TrashLifetime = 0
749 theConfig.TrashLifetime.Set("1h")
751 // put block and backdate it
752 v.PutRaw(TestHash, TestBlock)
753 v.TouchWithDate(TestHash, time.Now().Add(-2*theConfig.BlobSignatureTTL.Duration()))
755 buf := make([]byte, BlockSize)
756 n, err := v.Get(context.Background(), TestHash, buf)
760 if bytes.Compare(buf[:n], TestBlock) != 0 {
761 t.Errorf("Got data %+q, expected %+q", buf[:n], TestBlock)
765 err = v.Trash(TestHash)
766 if v.Writable() == false {
767 if err != MethodDisabledError {
770 } else if err != nil {
771 if err != ErrNotImplemented {
775 _, err = v.Get(context.Background(), TestHash, buf)
776 if err == nil || !os.IsNotExist(err) {
777 t.Errorf("os.IsNotExist(%v) should have been true", err)
781 err = v.Untrash(TestHash)
787 // Get the block - after trash and untrash sequence
788 n, err = v.Get(context.Background(), TestHash, buf)
792 if bytes.Compare(buf[:n], TestBlock) != 0 {
793 t.Errorf("Got data %+q, expected %+q", buf[:n], TestBlock)
797 func testTrashEmptyTrashUntrash(t TB, factory TestableVolumeFactory) {
800 defer func(orig arvados.Duration) {
801 theConfig.TrashLifetime = orig
802 }(theConfig.TrashLifetime)
804 checkGet := func() error {
805 buf := make([]byte, BlockSize)
806 n, err := v.Get(context.Background(), TestHash, buf)
810 if bytes.Compare(buf[:n], TestBlock) != 0 {
811 t.Fatalf("Got data %+q, expected %+q", buf[:n], TestBlock)
814 _, err = v.Mtime(TestHash)
819 err = v.Compare(context.Background(), TestHash, TestBlock)
824 indexBuf := new(bytes.Buffer)
825 v.IndexTo("", indexBuf)
826 if !strings.Contains(string(indexBuf.Bytes()), TestHash) {
827 return os.ErrNotExist
833 // First set: EmptyTrash before reaching the trash deadline.
835 theConfig.TrashLifetime.Set("1h")
837 v.PutRaw(TestHash, TestBlock)
838 v.TouchWithDate(TestHash, time.Now().Add(-2*theConfig.BlobSignatureTTL.Duration()))
846 err = v.Trash(TestHash)
847 if err == MethodDisabledError || err == ErrNotImplemented {
848 // Skip the trash tests for read-only volumes, and
849 // volume types that don't support TrashLifetime>0.
854 if err == nil || !os.IsNotExist(err) {
855 t.Fatalf("os.IsNotExist(%v) should have been true", err)
858 err = v.Touch(TestHash)
859 if err == nil || !os.IsNotExist(err) {
860 t.Fatalf("os.IsNotExist(%v) should have been true", err)
865 // Even after emptying the trash, we can untrash our block
866 // because the deadline hasn't been reached.
867 err = v.Untrash(TestHash)
877 err = v.Touch(TestHash)
882 // Because we Touch'ed, need to backdate again for next set of tests
883 v.TouchWithDate(TestHash, time.Now().Add(-2*theConfig.BlobSignatureTTL.Duration()))
885 // If the only block in the trash has already been untrashed,
886 // most volumes will fail a subsequent Untrash with a 404, but
887 // it's also acceptable for Untrash to succeed.
888 err = v.Untrash(TestHash)
889 if err != nil && !os.IsNotExist(err) {
890 t.Fatalf("Expected success or os.IsNotExist(), but got: %v", err)
893 // The additional Untrash should not interfere with our
894 // already-untrashed copy.
900 // Untrash might have updated the timestamp, so backdate again
901 v.TouchWithDate(TestHash, time.Now().Add(-2*theConfig.BlobSignatureTTL.Duration()))
903 // Second set: EmptyTrash after the trash deadline has passed.
905 theConfig.TrashLifetime.Set("1ns")
907 err = v.Trash(TestHash)
912 if err == nil || !os.IsNotExist(err) {
913 t.Fatalf("os.IsNotExist(%v) should have been true", err)
916 // Even though 1ns has passed, we can untrash because we
917 // haven't called EmptyTrash yet.
918 err = v.Untrash(TestHash)
927 // Trash it again, and this time call EmptyTrash so it really
929 // (In Azure volumes, un/trash changes Mtime, so first backdate again)
930 v.TouchWithDate(TestHash, time.Now().Add(-2*theConfig.BlobSignatureTTL.Duration()))
931 err = v.Trash(TestHash)
933 if err == nil || !os.IsNotExist(err) {
934 t.Fatalf("os.IsNotExist(%v) should have been true", err)
938 // Untrash won't find it
939 err = v.Untrash(TestHash)
940 if err == nil || !os.IsNotExist(err) {
941 t.Fatalf("os.IsNotExist(%v) should have been true", err)
944 // Get block won't find it
946 if err == nil || !os.IsNotExist(err) {
947 t.Fatalf("os.IsNotExist(%v) should have been true", err)
950 // Third set: If the same data block gets written again after
951 // being trashed, and then the trash gets emptied, the newer
952 // un-trashed copy doesn't get deleted along with it.
954 v.PutRaw(TestHash, TestBlock)
955 v.TouchWithDate(TestHash, time.Now().Add(-2*theConfig.BlobSignatureTTL.Duration()))
957 theConfig.TrashLifetime.Set("1ns")
958 err = v.Trash(TestHash)
963 if err == nil || !os.IsNotExist(err) {
964 t.Fatalf("os.IsNotExist(%v) should have been true", err)
967 v.PutRaw(TestHash, TestBlock)
968 v.TouchWithDate(TestHash, time.Now().Add(-2*theConfig.BlobSignatureTTL.Duration()))
970 // EmptyTrash should not delete the untrashed copy.
977 // Fourth set: If the same data block gets trashed twice with
978 // different deadlines A and C, and then the trash is emptied
979 // at intermediate time B (A < B < C), it is still possible to
980 // untrash the block whose deadline is "C".
982 v.PutRaw(TestHash, TestBlock)
983 v.TouchWithDate(TestHash, time.Now().Add(-2*theConfig.BlobSignatureTTL.Duration()))
985 theConfig.TrashLifetime.Set("1ns")
986 err = v.Trash(TestHash)
991 v.PutRaw(TestHash, TestBlock)
992 v.TouchWithDate(TestHash, time.Now().Add(-2*theConfig.BlobSignatureTTL.Duration()))
994 theConfig.TrashLifetime.Set("1h")
995 err = v.Trash(TestHash)
1000 // EmptyTrash should not prevent us from recovering the
1001 // time.Hour ("C") trash
1003 err = v.Untrash(TestHash)