14 "git.curoverse.com/arvados.git/sdk/go/arvados"
15 "git.curoverse.com/arvados.git/sdk/go/arvadostest"
19 Error(args ...interface{})
20 Errorf(format string, args ...interface{})
24 Fatal(args ...interface{})
25 Fatalf(format string, args ...interface{})
26 Log(args ...interface{})
27 Logf(format string, args ...interface{})
30 // A TestableVolumeFactory returns a new TestableVolume. The factory
31 // function, and the TestableVolume it returns, can use "t" to write
32 // logs, fail the current test, etc.
33 type TestableVolumeFactory func(t TB) TestableVolume
35 // DoGenericVolumeTests runs a set of tests that every TestableVolume
36 // is expected to pass. It calls factory to create a new TestableVolume
37 // for each test case, to avoid leaking state between tests.
38 func DoGenericVolumeTests(t TB, factory TestableVolumeFactory) {
40 testGetNoSuchBlock(t, factory)
42 testCompareNonexistent(t, factory)
43 testCompareSameContent(t, factory, TestHash, TestBlock)
44 testCompareSameContent(t, factory, EmptyHash, EmptyBlock)
45 testCompareWithCollision(t, factory, TestHash, TestBlock, []byte("baddata"))
46 testCompareWithCollision(t, factory, TestHash, TestBlock, EmptyBlock)
47 testCompareWithCollision(t, factory, EmptyHash, EmptyBlock, TestBlock)
48 testCompareWithCorruptStoredData(t, factory, TestHash, TestBlock, []byte("baddata"))
49 testCompareWithCorruptStoredData(t, factory, TestHash, TestBlock, EmptyBlock)
50 testCompareWithCorruptStoredData(t, factory, EmptyHash, EmptyBlock, []byte("baddata"))
52 testPutBlockWithSameContent(t, factory, TestHash, TestBlock)
53 testPutBlockWithSameContent(t, factory, EmptyHash, EmptyBlock)
54 testPutBlockWithDifferentContent(t, factory, arvadostest.MD5CollisionMD5, arvadostest.MD5CollisionData[0], arvadostest.MD5CollisionData[1])
55 testPutBlockWithDifferentContent(t, factory, arvadostest.MD5CollisionMD5, EmptyBlock, arvadostest.MD5CollisionData[0])
56 testPutBlockWithDifferentContent(t, factory, arvadostest.MD5CollisionMD5, arvadostest.MD5CollisionData[0], EmptyBlock)
57 testPutBlockWithDifferentContent(t, factory, EmptyHash, EmptyBlock, arvadostest.MD5CollisionData[0])
58 testPutMultipleBlocks(t, factory)
60 testPutAndTouch(t, factory)
61 testTouchNoSuchBlock(t, factory)
63 testMtimeNoSuchBlock(t, factory)
65 testIndexTo(t, factory)
67 testDeleteNewBlock(t, factory)
68 testDeleteOldBlock(t, factory)
69 testDeleteNoSuchBlock(t, factory)
71 testStatus(t, factory)
73 testString(t, factory)
75 testUpdateReadOnly(t, factory)
77 testGetConcurrent(t, factory)
78 testPutConcurrent(t, factory)
80 testPutFullBlock(t, factory)
82 testTrashUntrash(t, factory)
83 testTrashEmptyTrashUntrash(t, factory)
86 // Put a test block, get it and verify content
87 // Test should pass for both writable and read-only volumes
88 func testGet(t TB, factory TestableVolumeFactory) {
92 v.PutRaw(TestHash, TestBlock)
94 buf := make([]byte, BlockSize)
95 n, err := v.Get(TestHash, buf)
100 if bytes.Compare(buf[:n], TestBlock) != 0 {
101 t.Errorf("expected %s, got %s", string(TestBlock), string(buf))
105 // Invoke get on a block that does not exist in volume; should result in error
106 // Test should pass for both writable and read-only volumes
107 func testGetNoSuchBlock(t TB, factory TestableVolumeFactory) {
111 buf := make([]byte, BlockSize)
112 if _, err := v.Get(TestHash2, buf); err == nil {
113 t.Errorf("Expected error while getting non-existing block %v", TestHash2)
117 // Compare() should return os.ErrNotExist if the block does not exist.
118 // Otherwise, writing new data causes CompareAndTouch() to generate
119 // error logs even though everything is working fine.
120 func testCompareNonexistent(t TB, factory TestableVolumeFactory) {
124 err := v.Compare(TestHash, TestBlock)
125 if err != os.ErrNotExist {
126 t.Errorf("Got err %T %q, expected os.ErrNotExist", err, err)
130 // Put a test block and compare the locator with same content
131 // Test should pass for both writable and read-only volumes
132 func testCompareSameContent(t TB, factory TestableVolumeFactory, testHash string, testData []byte) {
136 v.PutRaw(testHash, testData)
138 // Compare the block locator with same content
139 err := v.Compare(testHash, testData)
141 t.Errorf("Got err %q, expected nil", err)
145 // Test behavior of Compare() when stored data matches expected
146 // checksum but differs from new data we need to store. Requires
147 // testHash = md5(testDataA).
149 // Test should pass for both writable and read-only volumes
150 func testCompareWithCollision(t TB, factory TestableVolumeFactory, testHash string, testDataA, testDataB []byte) {
154 v.PutRaw(testHash, testDataA)
156 // Compare the block locator with different content; collision
157 err := v.Compare(TestHash, testDataB)
159 t.Errorf("Got err nil, expected error due to collision")
163 // Test behavior of Compare() when stored data has become
164 // corrupted. Requires testHash = md5(testDataA) != md5(testDataB).
166 // Test should pass for both writable and read-only volumes
167 func testCompareWithCorruptStoredData(t TB, factory TestableVolumeFactory, testHash string, testDataA, testDataB []byte) {
171 v.PutRaw(TestHash, testDataB)
173 err := v.Compare(testHash, testDataA)
174 if err == nil || err == CollisionError {
175 t.Errorf("Got err %+v, expected non-collision error", err)
179 // Put a block and put again with same content
180 // Test is intended for only writable volumes
181 func testPutBlockWithSameContent(t TB, factory TestableVolumeFactory, testHash string, testData []byte) {
185 if v.Writable() == false {
189 err := v.Put(testHash, testData)
191 t.Errorf("Got err putting block %q: %q, expected nil", TestBlock, err)
194 err = v.Put(testHash, testData)
196 t.Errorf("Got err putting block second time %q: %q, expected nil", TestBlock, err)
200 // Put a block and put again with different content
201 // Test is intended for only writable volumes
202 func testPutBlockWithDifferentContent(t TB, factory TestableVolumeFactory, testHash string, testDataA, testDataB []byte) {
206 if v.Writable() == false {
210 v.PutRaw(testHash, testDataA)
212 putErr := v.Put(testHash, testDataB)
213 buf := make([]byte, BlockSize)
214 n, getErr := v.Get(testHash, buf)
216 // Put must not return a nil error unless it has
217 // overwritten the existing data.
218 if bytes.Compare(buf[:n], testDataB) != 0 {
219 t.Errorf("Put succeeded but Get returned %+q, expected %+q", buf[:n], testDataB)
222 // It is permissible for Put to fail, but it must
223 // leave us with either the original data, the new
224 // data, or nothing at all.
225 if getErr == nil && bytes.Compare(buf[:n], testDataA) != 0 && bytes.Compare(buf[:n], testDataB) != 0 {
226 t.Errorf("Put failed but Get returned %+q, which is neither %+q nor %+q", buf[:n], testDataA, testDataB)
231 // Put and get multiple blocks
232 // Test is intended for only writable volumes
233 func testPutMultipleBlocks(t TB, factory TestableVolumeFactory) {
237 if v.Writable() == false {
241 err := v.Put(TestHash, TestBlock)
243 t.Errorf("Got err putting block %q: %q, expected nil", TestBlock, err)
246 err = v.Put(TestHash2, TestBlock2)
248 t.Errorf("Got err putting block %q: %q, expected nil", TestBlock2, err)
251 err = v.Put(TestHash3, TestBlock3)
253 t.Errorf("Got err putting block %q: %q, expected nil", TestBlock3, err)
256 data := make([]byte, BlockSize)
257 n, err := v.Get(TestHash, data)
261 if bytes.Compare(data[:n], TestBlock) != 0 {
262 t.Errorf("Block present, but got %+q, expected %+q", data[:n], TestBlock)
266 n, err = v.Get(TestHash2, data)
270 if bytes.Compare(data[:n], TestBlock2) != 0 {
271 t.Errorf("Block present, but got %+q, expected %+q", data[:n], TestBlock2)
275 n, err = v.Get(TestHash3, data)
279 if bytes.Compare(data[:n], TestBlock3) != 0 {
280 t.Errorf("Block present, but to %+q, expected %+q", data[:n], TestBlock3)
286 // Test that when applying PUT to a block that already exists,
287 // the block's modification time is updated.
288 // Test is intended for only writable volumes
289 func testPutAndTouch(t TB, factory TestableVolumeFactory) {
293 if v.Writable() == false {
297 if err := v.Put(TestHash, TestBlock); err != nil {
301 // We'll verify { t0 < threshold < t1 }, where t0 is the
302 // existing block's timestamp on disk before Put() and t1 is
303 // its timestamp after Put().
304 threshold := time.Now().Add(-time.Second)
306 // Set the stored block's mtime far enough in the past that we
307 // can see the difference between "timestamp didn't change"
308 // and "timestamp granularity is too low".
309 v.TouchWithDate(TestHash, time.Now().Add(-20*time.Second))
311 // Make sure v.Mtime() agrees the above Utime really worked.
312 if t0, err := v.Mtime(TestHash); err != nil || t0.IsZero() || !t0.Before(threshold) {
313 t.Errorf("Setting mtime failed: %v, %v", t0, err)
316 // Write the same block again.
317 if err := v.Put(TestHash, TestBlock); err != nil {
321 // Verify threshold < t1
322 if t1, err := v.Mtime(TestHash); err != nil {
324 } else if t1.Before(threshold) {
325 t.Errorf("t1 %v should be >= threshold %v after v.Put ", t1, threshold)
329 // Touching a non-existing block should result in error.
330 // Test should pass for both writable and read-only volumes
331 func testTouchNoSuchBlock(t TB, factory TestableVolumeFactory) {
335 if err := v.Touch(TestHash); err == nil {
336 t.Error("Expected error when attempted to touch a non-existing block")
340 // Invoking Mtime on a non-existing block should result in error.
341 // Test should pass for both writable and read-only volumes
342 func testMtimeNoSuchBlock(t TB, factory TestableVolumeFactory) {
346 if _, err := v.Mtime("12345678901234567890123456789012"); err == nil {
347 t.Error("Expected error when updating Mtime on a non-existing block")
351 // Put a few blocks and invoke IndexTo with:
354 // * with no such prefix
355 // Test should pass for both writable and read-only volumes
356 func testIndexTo(t TB, factory TestableVolumeFactory) {
360 // minMtime and maxMtime are the minimum and maximum
361 // acceptable values the index can report for our test
362 // blocks. 1-second precision is acceptable.
363 minMtime := time.Now().UTC().UnixNano()
364 minMtime -= minMtime % 1e9
366 v.PutRaw(TestHash, TestBlock)
367 v.PutRaw(TestHash2, TestBlock2)
368 v.PutRaw(TestHash3, TestBlock3)
370 maxMtime := time.Now().UTC().UnixNano()
371 if maxMtime%1e9 > 0 {
372 maxMtime -= maxMtime % 1e9
376 // Blocks whose names aren't Keep hashes should be omitted from
378 v.PutRaw("fffffffffnotreallyahashfffffffff", nil)
379 v.PutRaw("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", nil)
380 v.PutRaw("f0000000000000000000000000000000f", nil)
383 buf := new(bytes.Buffer)
385 indexRows := strings.Split(string(buf.Bytes()), "\n")
386 sort.Strings(indexRows)
387 sortedIndex := strings.Join(indexRows, "\n")
388 m := regexp.MustCompile(
389 `^\n` + TestHash + `\+\d+ (\d+)\n` +
390 TestHash3 + `\+\d+ \d+\n` +
391 TestHash2 + `\+\d+ \d+$`,
392 ).FindStringSubmatch(sortedIndex)
394 t.Errorf("Got index %q for empty prefix", sortedIndex)
396 mtime, err := strconv.ParseInt(m[1], 10, 64)
399 } else if mtime < minMtime || mtime > maxMtime {
400 t.Errorf("got %d for TestHash timestamp, expected %d <= t <= %d",
401 mtime, minMtime, maxMtime)
405 for _, prefix := range []string{"f", "f15", "f15ac"} {
406 buf = new(bytes.Buffer)
407 v.IndexTo(prefix, buf)
409 m, err := regexp.MatchString(`^`+TestHash2+`\+\d+ \d+\n$`, string(buf.Bytes()))
413 t.Errorf("Got index %q for prefix %s", string(buf.Bytes()), prefix)
417 for _, prefix := range []string{"zero", "zip", "zilch"} {
418 buf = new(bytes.Buffer)
419 err := v.IndexTo(prefix, buf)
421 t.Errorf("Got error on IndexTo with no such prefix %v", err.Error())
422 } else if buf.Len() != 0 {
423 t.Errorf("Expected empty list for IndexTo with no such prefix %s", prefix)
428 // Calling Delete() for a block immediately after writing it (not old enough)
429 // should neither delete the data nor return an error.
430 // Test is intended for only writable volumes
431 func testDeleteNewBlock(t TB, factory TestableVolumeFactory) {
434 theConfig.BlobSignatureTTL.Set("5m")
436 if v.Writable() == false {
440 v.Put(TestHash, TestBlock)
442 if err := v.Trash(TestHash); err != nil {
445 data := make([]byte, BlockSize)
446 n, err := v.Get(TestHash, data)
449 } else if bytes.Compare(data[:n], TestBlock) != 0 {
450 t.Errorf("Got data %+q, expected %+q", data[:n], TestBlock)
454 // Calling Delete() for a block with a timestamp older than
455 // BlobSignatureTTL seconds in the past should delete the data.
456 // Test is intended for only writable volumes
457 func testDeleteOldBlock(t TB, factory TestableVolumeFactory) {
460 theConfig.BlobSignatureTTL.Set("5m")
462 if v.Writable() == false {
466 v.Put(TestHash, TestBlock)
467 v.TouchWithDate(TestHash, time.Now().Add(-2*theConfig.BlobSignatureTTL.Duration()))
469 if err := v.Trash(TestHash); err != nil {
472 data := make([]byte, BlockSize)
473 if _, err := v.Get(TestHash, data); err == nil || !os.IsNotExist(err) {
474 t.Errorf("os.IsNotExist(%v) should have been true", err)
477 _, err := v.Mtime(TestHash)
478 if err == nil || !os.IsNotExist(err) {
479 t.Fatalf("os.IsNotExist(%v) should have been true", err)
482 err = v.Compare(TestHash, TestBlock)
483 if err == nil || !os.IsNotExist(err) {
484 t.Fatalf("os.IsNotExist(%v) should have been true", err)
487 indexBuf := new(bytes.Buffer)
488 v.IndexTo("", indexBuf)
489 if strings.Contains(string(indexBuf.Bytes()), TestHash) {
490 t.Fatalf("Found trashed block in IndexTo")
493 err = v.Touch(TestHash)
494 if err == nil || !os.IsNotExist(err) {
495 t.Fatalf("os.IsNotExist(%v) should have been true", err)
499 // Calling Delete() for a block that does not exist should result in error.
500 // Test should pass for both writable and read-only volumes
501 func testDeleteNoSuchBlock(t TB, factory TestableVolumeFactory) {
505 if err := v.Trash(TestHash2); err == nil {
506 t.Errorf("Expected error when attempting to delete a non-existing block")
510 // Invoke Status and verify that VolumeStatus is returned
511 // Test should pass for both writable and read-only volumes
512 func testStatus(t TB, factory TestableVolumeFactory) {
516 // Get node status and make a basic sanity check.
518 if status.DeviceNum == 0 {
519 t.Errorf("uninitialized device_num in %v", status)
522 if status.BytesFree == 0 {
523 t.Errorf("uninitialized bytes_free in %v", status)
526 if status.BytesUsed == 0 {
527 t.Errorf("uninitialized bytes_used in %v", status)
531 // Invoke String for the volume; expect non-empty result
532 // Test should pass for both writable and read-only volumes
533 func testString(t TB, factory TestableVolumeFactory) {
537 if id := v.String(); len(id) == 0 {
538 t.Error("Got empty string for v.String()")
542 // Putting, updating, touching, and deleting blocks from a read-only volume result in error.
543 // Test is intended for only read-only volumes
544 func testUpdateReadOnly(t TB, factory TestableVolumeFactory) {
548 if v.Writable() == true {
552 v.PutRaw(TestHash, TestBlock)
553 buf := make([]byte, BlockSize)
555 // Get from read-only volume should succeed
556 _, err := v.Get(TestHash, buf)
558 t.Errorf("got err %v, expected nil", err)
561 // Put a new block to read-only volume should result in error
562 err = v.Put(TestHash2, TestBlock2)
564 t.Errorf("Expected error when putting block in a read-only volume")
566 _, err = v.Get(TestHash2, buf)
568 t.Errorf("Expected error when getting block whose put in read-only volume failed")
571 // Touch a block in read-only volume should result in error
572 err = v.Touch(TestHash)
574 t.Errorf("Expected error when touching block in a read-only volume")
577 // Delete a block from a read-only volume should result in error
578 err = v.Trash(TestHash)
580 t.Errorf("Expected error when deleting block from a read-only volume")
583 // Overwriting an existing block in read-only volume should result in error
584 err = v.Put(TestHash, TestBlock)
586 t.Errorf("Expected error when putting block in a read-only volume")
590 // Launch concurrent Gets
591 // Test should pass for both writable and read-only volumes
592 func testGetConcurrent(t TB, factory TestableVolumeFactory) {
596 v.PutRaw(TestHash, TestBlock)
597 v.PutRaw(TestHash2, TestBlock2)
598 v.PutRaw(TestHash3, TestBlock3)
600 sem := make(chan int)
602 buf := make([]byte, BlockSize)
603 n, err := v.Get(TestHash, buf)
605 t.Errorf("err1: %v", err)
607 if bytes.Compare(buf[:n], TestBlock) != 0 {
608 t.Errorf("buf should be %s, is %s", string(TestBlock), string(buf[:n]))
614 buf := make([]byte, BlockSize)
615 n, err := v.Get(TestHash2, buf)
617 t.Errorf("err2: %v", err)
619 if bytes.Compare(buf[:n], TestBlock2) != 0 {
620 t.Errorf("buf should be %s, is %s", string(TestBlock2), string(buf[:n]))
626 buf := make([]byte, BlockSize)
627 n, err := v.Get(TestHash3, buf)
629 t.Errorf("err3: %v", err)
631 if bytes.Compare(buf[:n], TestBlock3) != 0 {
632 t.Errorf("buf should be %s, is %s", string(TestBlock3), string(buf[:n]))
637 // Wait for all goroutines to finish
638 for done := 0; done < 3; done++ {
643 // Launch concurrent Puts
644 // Test is intended for only writable volumes
645 func testPutConcurrent(t TB, factory TestableVolumeFactory) {
649 if v.Writable() == false {
653 sem := make(chan int)
654 go func(sem chan int) {
655 err := v.Put(TestHash, TestBlock)
657 t.Errorf("err1: %v", err)
662 go func(sem chan int) {
663 err := v.Put(TestHash2, TestBlock2)
665 t.Errorf("err2: %v", err)
670 go func(sem chan int) {
671 err := v.Put(TestHash3, TestBlock3)
673 t.Errorf("err3: %v", err)
678 // Wait for all goroutines to finish
679 for done := 0; done < 3; done++ {
683 // Double check that we actually wrote the blocks we expected to write.
684 buf := make([]byte, BlockSize)
685 n, err := v.Get(TestHash, buf)
687 t.Errorf("Get #1: %v", err)
689 if bytes.Compare(buf[:n], TestBlock) != 0 {
690 t.Errorf("Get #1: expected %s, got %s", string(TestBlock), string(buf[:n]))
693 n, err = v.Get(TestHash2, buf)
695 t.Errorf("Get #2: %v", err)
697 if bytes.Compare(buf[:n], TestBlock2) != 0 {
698 t.Errorf("Get #2: expected %s, got %s", string(TestBlock2), string(buf[:n]))
701 n, err = v.Get(TestHash3, buf)
703 t.Errorf("Get #3: %v", err)
705 if bytes.Compare(buf[:n], TestBlock3) != 0 {
706 t.Errorf("Get #3: expected %s, got %s", string(TestBlock3), string(buf[:n]))
710 // Write and read back a full size block
711 func testPutFullBlock(t TB, factory TestableVolumeFactory) {
719 wdata := make([]byte, BlockSize)
721 wdata[BlockSize-1] = 'z'
722 hash := fmt.Sprintf("%x", md5.Sum(wdata))
723 err := v.Put(hash, wdata)
727 buf := make([]byte, BlockSize)
728 n, err := v.Get(hash, buf)
732 if bytes.Compare(buf[:n], wdata) != 0 {
733 t.Error("buf %+q != wdata %+q", buf[:n], wdata)
737 // With TrashLifetime != 0, perform:
738 // Trash an old block - which either raises ErrNotImplemented or succeeds
739 // Untrash - which either raises ErrNotImplemented or succeeds
740 // Get - which must succeed
741 func testTrashUntrash(t TB, factory TestableVolumeFactory) {
745 theConfig.TrashLifetime = 0
748 theConfig.TrashLifetime.Set("1h")
750 // put block and backdate it
751 v.PutRaw(TestHash, TestBlock)
752 v.TouchWithDate(TestHash, time.Now().Add(-2*theConfig.BlobSignatureTTL.Duration()))
754 buf := make([]byte, BlockSize)
755 n, err := v.Get(TestHash, buf)
759 if bytes.Compare(buf[:n], TestBlock) != 0 {
760 t.Errorf("Got data %+q, expected %+q", buf[:n], TestBlock)
764 err = v.Trash(TestHash)
765 if v.Writable() == false {
766 if err != MethodDisabledError {
769 } else if err != nil {
770 if err != ErrNotImplemented {
774 _, err = v.Get(TestHash, buf)
775 if err == nil || !os.IsNotExist(err) {
776 t.Errorf("os.IsNotExist(%v) should have been true", err)
780 err = v.Untrash(TestHash)
786 // Get the block - after trash and untrash sequence
787 n, err = v.Get(TestHash, buf)
791 if bytes.Compare(buf[:n], TestBlock) != 0 {
792 t.Errorf("Got data %+q, expected %+q", buf[:n], TestBlock)
796 func testTrashEmptyTrashUntrash(t TB, factory TestableVolumeFactory) {
799 defer func(orig arvados.Duration) {
800 theConfig.TrashLifetime = orig
801 }(theConfig.TrashLifetime)
803 checkGet := func() error {
804 buf := make([]byte, BlockSize)
805 n, err := v.Get(TestHash, buf)
809 if bytes.Compare(buf[:n], TestBlock) != 0 {
810 t.Fatalf("Got data %+q, expected %+q", buf[:n], TestBlock)
813 _, err = v.Mtime(TestHash)
818 err = v.Compare(TestHash, TestBlock)
823 indexBuf := new(bytes.Buffer)
824 v.IndexTo("", indexBuf)
825 if !strings.Contains(string(indexBuf.Bytes()), TestHash) {
826 return os.ErrNotExist
832 // First set: EmptyTrash before reaching the trash deadline.
834 theConfig.TrashLifetime.Set("1h")
836 v.PutRaw(TestHash, TestBlock)
837 v.TouchWithDate(TestHash, time.Now().Add(-2*theConfig.BlobSignatureTTL.Duration()))
845 err = v.Trash(TestHash)
846 if err == MethodDisabledError || err == ErrNotImplemented {
847 // Skip the trash tests for read-only volumes, and
848 // volume types that don't support TrashLifetime>0.
853 if err == nil || !os.IsNotExist(err) {
854 t.Fatalf("os.IsNotExist(%v) should have been true", err)
857 err = v.Touch(TestHash)
858 if err == nil || !os.IsNotExist(err) {
859 t.Fatalf("os.IsNotExist(%v) should have been true", err)
864 // Even after emptying the trash, we can untrash our block
865 // because the deadline hasn't been reached.
866 err = v.Untrash(TestHash)
876 err = v.Touch(TestHash)
881 // Because we Touch'ed, need to backdate again for next set of tests
882 v.TouchWithDate(TestHash, time.Now().Add(-2*theConfig.BlobSignatureTTL.Duration()))
884 // If the only block in the trash has already been untrashed,
885 // most volumes will fail a subsequent Untrash with a 404, but
886 // it's also acceptable for Untrash to succeed.
887 err = v.Untrash(TestHash)
888 if err != nil && !os.IsNotExist(err) {
889 t.Fatalf("Expected success or os.IsNotExist(), but got: %v", err)
892 // The additional Untrash should not interfere with our
893 // already-untrashed copy.
899 // Untrash might have updated the timestamp, so backdate again
900 v.TouchWithDate(TestHash, time.Now().Add(-2*theConfig.BlobSignatureTTL.Duration()))
902 // Second set: EmptyTrash after the trash deadline has passed.
904 theConfig.TrashLifetime.Set("1ns")
906 err = v.Trash(TestHash)
911 if err == nil || !os.IsNotExist(err) {
912 t.Fatalf("os.IsNotExist(%v) should have been true", err)
915 // Even though 1ns has passed, we can untrash because we
916 // haven't called EmptyTrash yet.
917 err = v.Untrash(TestHash)
926 // Trash it again, and this time call EmptyTrash so it really
928 // (In Azure volumes, un/trash changes Mtime, so first backdate again)
929 v.TouchWithDate(TestHash, time.Now().Add(-2*theConfig.BlobSignatureTTL.Duration()))
930 err = v.Trash(TestHash)
932 if err == nil || !os.IsNotExist(err) {
933 t.Fatalf("os.IsNotExist(%v) should have been true", err)
937 // Untrash won't find it
938 err = v.Untrash(TestHash)
939 if err == nil || !os.IsNotExist(err) {
940 t.Fatalf("os.IsNotExist(%v) should have been true", err)
943 // Get block won't find it
945 if err == nil || !os.IsNotExist(err) {
946 t.Fatalf("os.IsNotExist(%v) should have been true", err)
949 // Third set: If the same data block gets written again after
950 // being trashed, and then the trash gets emptied, the newer
951 // un-trashed copy doesn't get deleted along with it.
953 v.PutRaw(TestHash, TestBlock)
954 v.TouchWithDate(TestHash, time.Now().Add(-2*theConfig.BlobSignatureTTL.Duration()))
956 theConfig.TrashLifetime.Set("1ns")
957 err = v.Trash(TestHash)
962 if err == nil || !os.IsNotExist(err) {
963 t.Fatalf("os.IsNotExist(%v) should have been true", err)
966 v.PutRaw(TestHash, TestBlock)
967 v.TouchWithDate(TestHash, time.Now().Add(-2*theConfig.BlobSignatureTTL.Duration()))
969 // EmptyTrash should not delete the untrashed copy.
976 // Fourth set: If the same data block gets trashed twice with
977 // different deadlines A and C, and then the trash is emptied
978 // at intermediate time B (A < B < C), it is still possible to
979 // untrash the block whose deadline is "C".
981 v.PutRaw(TestHash, TestBlock)
982 v.TouchWithDate(TestHash, time.Now().Add(-2*theConfig.BlobSignatureTTL.Duration()))
984 theConfig.TrashLifetime.Set("1ns")
985 err = v.Trash(TestHash)
990 v.PutRaw(TestHash, TestBlock)
991 v.TouchWithDate(TestHash, time.Now().Add(-2*theConfig.BlobSignatureTTL.Duration()))
993 theConfig.TrashLifetime.Set("1h")
994 err = v.Trash(TestHash)
999 // EmptyTrash should not prevent us from recovering the
1000 // time.Hour ("C") trash
1002 err = v.Untrash(TestHash)