14 "git.curoverse.com/arvados.git/sdk/go/arvadostest"
18 Error(args ...interface{})
19 Errorf(format string, args ...interface{})
23 Fatal(args ...interface{})
24 Fatalf(format string, args ...interface{})
25 Log(args ...interface{})
26 Logf(format string, args ...interface{})
29 // A TestableVolumeFactory returns a new TestableVolume. The factory
30 // function, and the TestableVolume it returns, can use "t" to write
31 // logs, fail the current test, etc.
32 type TestableVolumeFactory func(t TB) TestableVolume
34 // DoGenericVolumeTests runs a set of tests that every TestableVolume
35 // is expected to pass. It calls factory to create a new TestableVolume
36 // for each test case, to avoid leaking state between tests.
37 func DoGenericVolumeTests(t TB, factory TestableVolumeFactory) {
39 testGetNoSuchBlock(t, factory)
41 testCompareNonexistent(t, factory)
42 testCompareSameContent(t, factory, TestHash, TestBlock)
43 testCompareSameContent(t, factory, EmptyHash, EmptyBlock)
44 testCompareWithCollision(t, factory, TestHash, TestBlock, []byte("baddata"))
45 testCompareWithCollision(t, factory, TestHash, TestBlock, EmptyBlock)
46 testCompareWithCollision(t, factory, EmptyHash, EmptyBlock, TestBlock)
47 testCompareWithCorruptStoredData(t, factory, TestHash, TestBlock, []byte("baddata"))
48 testCompareWithCorruptStoredData(t, factory, TestHash, TestBlock, EmptyBlock)
49 testCompareWithCorruptStoredData(t, factory, EmptyHash, EmptyBlock, []byte("baddata"))
51 testPutBlockWithSameContent(t, factory, TestHash, TestBlock)
52 testPutBlockWithSameContent(t, factory, EmptyHash, EmptyBlock)
53 testPutBlockWithDifferentContent(t, factory, arvadostest.MD5CollisionMD5, arvadostest.MD5CollisionData[0], arvadostest.MD5CollisionData[1])
54 testPutBlockWithDifferentContent(t, factory, arvadostest.MD5CollisionMD5, EmptyBlock, arvadostest.MD5CollisionData[0])
55 testPutBlockWithDifferentContent(t, factory, arvadostest.MD5CollisionMD5, arvadostest.MD5CollisionData[0], EmptyBlock)
56 testPutBlockWithDifferentContent(t, factory, EmptyHash, EmptyBlock, arvadostest.MD5CollisionData[0])
57 testPutMultipleBlocks(t, factory)
59 testPutAndTouch(t, factory)
60 testTouchNoSuchBlock(t, factory)
62 testMtimeNoSuchBlock(t, factory)
64 testIndexTo(t, factory)
66 testDeleteNewBlock(t, factory)
67 testDeleteOldBlock(t, factory)
68 testDeleteNoSuchBlock(t, factory)
70 testStatus(t, factory)
72 testString(t, factory)
74 testUpdateReadOnly(t, factory)
76 testGetConcurrent(t, factory)
77 testPutConcurrent(t, factory)
79 testPutFullBlock(t, factory)
81 testTrashUntrash(t, factory)
82 testTrashEmptyTrashUntrash(t, factory)
85 // Put a test block, get it and verify content
86 // Test should pass for both writable and read-only volumes
87 func testGet(t TB, factory TestableVolumeFactory) {
91 v.PutRaw(TestHash, TestBlock)
93 buf := make([]byte, BlockSize)
94 n, err := v.Get(TestHash, buf)
99 if bytes.Compare(buf[:n], TestBlock) != 0 {
100 t.Errorf("expected %s, got %s", string(TestBlock), string(buf))
104 // Invoke get on a block that does not exist in volume; should result in error
105 // Test should pass for both writable and read-only volumes
106 func testGetNoSuchBlock(t TB, factory TestableVolumeFactory) {
110 buf := make([]byte, BlockSize)
111 if _, err := v.Get(TestHash2, buf); err == nil {
112 t.Errorf("Expected error while getting non-existing block %v", TestHash2)
116 // Compare() should return os.ErrNotExist if the block does not exist.
117 // Otherwise, writing new data causes CompareAndTouch() to generate
118 // error logs even though everything is working fine.
119 func testCompareNonexistent(t TB, factory TestableVolumeFactory) {
123 err := v.Compare(TestHash, TestBlock)
124 if err != os.ErrNotExist {
125 t.Errorf("Got err %T %q, expected os.ErrNotExist", err, err)
129 // Put a test block and compare the locator with same content
130 // Test should pass for both writable and read-only volumes
131 func testCompareSameContent(t TB, factory TestableVolumeFactory, testHash string, testData []byte) {
135 v.PutRaw(testHash, testData)
137 // Compare the block locator with same content
138 err := v.Compare(testHash, testData)
140 t.Errorf("Got err %q, expected nil", err)
144 // Test behavior of Compare() when stored data matches expected
145 // checksum but differs from new data we need to store. Requires
146 // testHash = md5(testDataA).
148 // Test should pass for both writable and read-only volumes
149 func testCompareWithCollision(t TB, factory TestableVolumeFactory, testHash string, testDataA, testDataB []byte) {
153 v.PutRaw(testHash, testDataA)
155 // Compare the block locator with different content; collision
156 err := v.Compare(TestHash, testDataB)
158 t.Errorf("Got err nil, expected error due to collision")
162 // Test behavior of Compare() when stored data has become
163 // corrupted. Requires testHash = md5(testDataA) != md5(testDataB).
165 // Test should pass for both writable and read-only volumes
166 func testCompareWithCorruptStoredData(t TB, factory TestableVolumeFactory, testHash string, testDataA, testDataB []byte) {
170 v.PutRaw(TestHash, testDataB)
172 err := v.Compare(testHash, testDataA)
173 if err == nil || err == CollisionError {
174 t.Errorf("Got err %+v, expected non-collision error", err)
178 // Put a block and put again with same content
179 // Test is intended for only writable volumes
180 func testPutBlockWithSameContent(t TB, factory TestableVolumeFactory, testHash string, testData []byte) {
184 if v.Writable() == false {
188 err := v.Put(testHash, testData)
190 t.Errorf("Got err putting block %q: %q, expected nil", TestBlock, err)
193 err = v.Put(testHash, testData)
195 t.Errorf("Got err putting block second time %q: %q, expected nil", TestBlock, err)
199 // Put a block and put again with different content
200 // Test is intended for only writable volumes
201 func testPutBlockWithDifferentContent(t TB, factory TestableVolumeFactory, testHash string, testDataA, testDataB []byte) {
205 if v.Writable() == false {
209 v.PutRaw(testHash, testDataA)
211 putErr := v.Put(testHash, testDataB)
212 buf := make([]byte, BlockSize)
213 n, getErr := v.Get(testHash, buf)
215 // Put must not return a nil error unless it has
216 // overwritten the existing data.
217 if bytes.Compare(buf[:n], testDataB) != 0 {
218 t.Errorf("Put succeeded but Get returned %+q, expected %+q", buf[:n], testDataB)
221 // It is permissible for Put to fail, but it must
222 // leave us with either the original data, the new
223 // data, or nothing at all.
224 if getErr == nil && bytes.Compare(buf[:n], testDataA) != 0 && bytes.Compare(buf[:n], testDataB) != 0 {
225 t.Errorf("Put failed but Get returned %+q, which is neither %+q nor %+q", buf[:n], testDataA, testDataB)
230 // Put and get multiple blocks
231 // Test is intended for only writable volumes
232 func testPutMultipleBlocks(t TB, factory TestableVolumeFactory) {
236 if v.Writable() == false {
240 err := v.Put(TestHash, TestBlock)
242 t.Errorf("Got err putting block %q: %q, expected nil", TestBlock, err)
245 err = v.Put(TestHash2, TestBlock2)
247 t.Errorf("Got err putting block %q: %q, expected nil", TestBlock2, err)
250 err = v.Put(TestHash3, TestBlock3)
252 t.Errorf("Got err putting block %q: %q, expected nil", TestBlock3, err)
255 data := make([]byte, BlockSize)
256 n, err := v.Get(TestHash, data)
260 if bytes.Compare(data[:n], TestBlock) != 0 {
261 t.Errorf("Block present, but got %+q, expected %+q", data[:n], TestBlock)
265 n, err = v.Get(TestHash2, data)
269 if bytes.Compare(data[:n], TestBlock2) != 0 {
270 t.Errorf("Block present, but got %+q, expected %+q", data[:n], TestBlock2)
274 n, err = v.Get(TestHash3, data)
278 if bytes.Compare(data[:n], TestBlock3) != 0 {
279 t.Errorf("Block present, but to %+q, expected %+q", data[:n], TestBlock3)
285 // Test that when applying PUT to a block that already exists,
286 // the block's modification time is updated.
287 // Test is intended for only writable volumes
288 func testPutAndTouch(t TB, factory TestableVolumeFactory) {
292 if v.Writable() == false {
296 if err := v.Put(TestHash, TestBlock); err != nil {
300 // We'll verify { t0 < threshold < t1 }, where t0 is the
301 // existing block's timestamp on disk before Put() and t1 is
302 // its timestamp after Put().
303 threshold := time.Now().Add(-time.Second)
305 // Set the stored block's mtime far enough in the past that we
306 // can see the difference between "timestamp didn't change"
307 // and "timestamp granularity is too low".
308 v.TouchWithDate(TestHash, time.Now().Add(-20*time.Second))
310 // Make sure v.Mtime() agrees the above Utime really worked.
311 if t0, err := v.Mtime(TestHash); err != nil || t0.IsZero() || !t0.Before(threshold) {
312 t.Errorf("Setting mtime failed: %v, %v", t0, err)
315 // Write the same block again.
316 if err := v.Put(TestHash, TestBlock); err != nil {
320 // Verify threshold < t1
321 if t1, err := v.Mtime(TestHash); err != nil {
323 } else if t1.Before(threshold) {
324 t.Errorf("t1 %v should be >= threshold %v after v.Put ", t1, threshold)
328 // Touching a non-existing block should result in error.
329 // Test should pass for both writable and read-only volumes
330 func testTouchNoSuchBlock(t TB, factory TestableVolumeFactory) {
334 if err := v.Touch(TestHash); err == nil {
335 t.Error("Expected error when attempted to touch a non-existing block")
339 // Invoking Mtime on a non-existing block should result in error.
340 // Test should pass for both writable and read-only volumes
341 func testMtimeNoSuchBlock(t TB, factory TestableVolumeFactory) {
345 if _, err := v.Mtime("12345678901234567890123456789012"); err == nil {
346 t.Error("Expected error when updating Mtime on a non-existing block")
350 // Put a few blocks and invoke IndexTo with:
353 // * with no such prefix
354 // Test should pass for both writable and read-only volumes
355 func testIndexTo(t TB, factory TestableVolumeFactory) {
359 // minMtime and maxMtime are the minimum and maximum
360 // acceptable values the index can report for our test
361 // blocks. 1-second precision is acceptable.
362 minMtime := time.Now().UTC().UnixNano()
363 minMtime -= minMtime % 1e9
365 v.PutRaw(TestHash, TestBlock)
366 v.PutRaw(TestHash2, TestBlock2)
367 v.PutRaw(TestHash3, TestBlock3)
369 maxMtime := time.Now().UTC().UnixNano()
370 if maxMtime%1e9 > 0 {
371 maxMtime -= maxMtime % 1e9
375 // Blocks whose names aren't Keep hashes should be omitted from
377 v.PutRaw("fffffffffnotreallyahashfffffffff", nil)
378 v.PutRaw("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", nil)
379 v.PutRaw("f0000000000000000000000000000000f", nil)
382 buf := new(bytes.Buffer)
384 indexRows := strings.Split(string(buf.Bytes()), "\n")
385 sort.Strings(indexRows)
386 sortedIndex := strings.Join(indexRows, "\n")
387 m := regexp.MustCompile(
388 `^\n` + TestHash + `\+\d+ (\d+)\n` +
389 TestHash3 + `\+\d+ \d+\n` +
390 TestHash2 + `\+\d+ \d+$`,
391 ).FindStringSubmatch(sortedIndex)
393 t.Errorf("Got index %q for empty prefix", sortedIndex)
395 mtime, err := strconv.ParseInt(m[1], 10, 64)
398 } else if mtime < minMtime || mtime > maxMtime {
399 t.Errorf("got %d for TestHash timestamp, expected %d <= t <= %d",
400 mtime, minMtime, maxMtime)
404 for _, prefix := range []string{"f", "f15", "f15ac"} {
405 buf = new(bytes.Buffer)
406 v.IndexTo(prefix, buf)
408 m, err := regexp.MatchString(`^`+TestHash2+`\+\d+ \d+\n$`, string(buf.Bytes()))
412 t.Errorf("Got index %q for prefix %s", string(buf.Bytes()), prefix)
416 for _, prefix := range []string{"zero", "zip", "zilch"} {
417 buf = new(bytes.Buffer)
418 err := v.IndexTo(prefix, buf)
420 t.Errorf("Got error on IndexTo with no such prefix %v", err.Error())
421 } else if buf.Len() != 0 {
422 t.Errorf("Expected empty list for IndexTo with no such prefix %s", prefix)
427 // Calling Delete() for a block immediately after writing it (not old enough)
428 // should neither delete the data nor return an error.
429 // Test is intended for only writable volumes
430 func testDeleteNewBlock(t TB, factory TestableVolumeFactory) {
433 blobSignatureTTL = 300 * time.Second
435 if v.Writable() == false {
439 v.Put(TestHash, TestBlock)
441 if err := v.Trash(TestHash); err != nil {
444 data := make([]byte, BlockSize)
445 n, err := v.Get(TestHash, data)
448 } else if bytes.Compare(data[:n], TestBlock) != 0 {
449 t.Errorf("Got data %+q, expected %+q", data[:n], TestBlock)
453 // Calling Delete() for a block with a timestamp older than
454 // blobSignatureTTL seconds in the past should delete the data.
455 // Test is intended for only writable volumes
456 func testDeleteOldBlock(t TB, factory TestableVolumeFactory) {
459 blobSignatureTTL = 300 * time.Second
461 if v.Writable() == false {
465 v.Put(TestHash, TestBlock)
466 v.TouchWithDate(TestHash, time.Now().Add(-2*blobSignatureTTL))
468 if err := v.Trash(TestHash); err != nil {
471 data := make([]byte, BlockSize)
472 if _, err := v.Get(TestHash, data); err == nil || !os.IsNotExist(err) {
473 t.Errorf("os.IsNotExist(%v) should have been true", err)
476 _, err := v.Mtime(TestHash)
477 if err == nil || !os.IsNotExist(err) {
478 t.Fatalf("os.IsNotExist(%v) should have been true", err)
481 err = v.Compare(TestHash, TestBlock)
482 if err == nil || !os.IsNotExist(err) {
483 t.Fatalf("os.IsNotExist(%v) should have been true", err)
486 indexBuf := new(bytes.Buffer)
487 v.IndexTo("", indexBuf)
488 if strings.Contains(string(indexBuf.Bytes()), TestHash) {
489 t.Fatalf("Found trashed block in IndexTo")
492 err = v.Touch(TestHash)
493 if err == nil || !os.IsNotExist(err) {
494 t.Fatalf("os.IsNotExist(%v) should have been true", err)
498 // Calling Delete() for a block that does not exist should result in error.
499 // Test should pass for both writable and read-only volumes
500 func testDeleteNoSuchBlock(t TB, factory TestableVolumeFactory) {
504 if err := v.Trash(TestHash2); err == nil {
505 t.Errorf("Expected error when attempting to delete a non-existing block")
509 // Invoke Status and verify that VolumeStatus is returned
510 // Test should pass for both writable and read-only volumes
511 func testStatus(t TB, factory TestableVolumeFactory) {
515 // Get node status and make a basic sanity check.
517 if status.DeviceNum == 0 {
518 t.Errorf("uninitialized device_num in %v", status)
521 if status.BytesFree == 0 {
522 t.Errorf("uninitialized bytes_free in %v", status)
525 if status.BytesUsed == 0 {
526 t.Errorf("uninitialized bytes_used in %v", status)
530 // Invoke String for the volume; expect non-empty result
531 // Test should pass for both writable and read-only volumes
532 func testString(t TB, factory TestableVolumeFactory) {
536 if id := v.String(); len(id) == 0 {
537 t.Error("Got empty string for v.String()")
541 // Putting, updating, touching, and deleting blocks from a read-only volume result in error.
542 // Test is intended for only read-only volumes
543 func testUpdateReadOnly(t TB, factory TestableVolumeFactory) {
547 if v.Writable() == true {
551 v.PutRaw(TestHash, TestBlock)
552 buf := make([]byte, BlockSize)
554 // Get from read-only volume should succeed
555 _, err := v.Get(TestHash, buf)
557 t.Errorf("got err %v, expected nil", err)
560 // Put a new block to read-only volume should result in error
561 err = v.Put(TestHash2, TestBlock2)
563 t.Errorf("Expected error when putting block in a read-only volume")
565 _, err = v.Get(TestHash2, buf)
567 t.Errorf("Expected error when getting block whose put in read-only volume failed")
570 // Touch a block in read-only volume should result in error
571 err = v.Touch(TestHash)
573 t.Errorf("Expected error when touching block in a read-only volume")
576 // Delete a block from a read-only volume should result in error
577 err = v.Trash(TestHash)
579 t.Errorf("Expected error when deleting block from a read-only volume")
582 // Overwriting an existing block in read-only volume should result in error
583 err = v.Put(TestHash, TestBlock)
585 t.Errorf("Expected error when putting block in a read-only volume")
589 // Launch concurrent Gets
590 // Test should pass for both writable and read-only volumes
591 func testGetConcurrent(t TB, factory TestableVolumeFactory) {
595 v.PutRaw(TestHash, TestBlock)
596 v.PutRaw(TestHash2, TestBlock2)
597 v.PutRaw(TestHash3, TestBlock3)
599 sem := make(chan int)
601 buf := make([]byte, BlockSize)
602 n, err := v.Get(TestHash, buf)
604 t.Errorf("err1: %v", err)
606 if bytes.Compare(buf[:n], TestBlock) != 0 {
607 t.Errorf("buf should be %s, is %s", string(TestBlock), string(buf[:n]))
613 buf := make([]byte, BlockSize)
614 n, err := v.Get(TestHash2, buf)
616 t.Errorf("err2: %v", err)
618 if bytes.Compare(buf[:n], TestBlock2) != 0 {
619 t.Errorf("buf should be %s, is %s", string(TestBlock2), string(buf[:n]))
625 buf := make([]byte, BlockSize)
626 n, err := v.Get(TestHash3, buf)
628 t.Errorf("err3: %v", err)
630 if bytes.Compare(buf[:n], TestBlock3) != 0 {
631 t.Errorf("buf should be %s, is %s", string(TestBlock3), string(buf[:n]))
636 // Wait for all goroutines to finish
637 for done := 0; done < 3; done++ {
642 // Launch concurrent Puts
643 // Test is intended for only writable volumes
644 func testPutConcurrent(t TB, factory TestableVolumeFactory) {
648 if v.Writable() == false {
652 sem := make(chan int)
653 go func(sem chan int) {
654 err := v.Put(TestHash, TestBlock)
656 t.Errorf("err1: %v", err)
661 go func(sem chan int) {
662 err := v.Put(TestHash2, TestBlock2)
664 t.Errorf("err2: %v", err)
669 go func(sem chan int) {
670 err := v.Put(TestHash3, TestBlock3)
672 t.Errorf("err3: %v", err)
677 // Wait for all goroutines to finish
678 for done := 0; done < 3; done++ {
682 // Double check that we actually wrote the blocks we expected to write.
683 buf := make([]byte, BlockSize)
684 n, err := v.Get(TestHash, buf)
686 t.Errorf("Get #1: %v", err)
688 if bytes.Compare(buf[:n], TestBlock) != 0 {
689 t.Errorf("Get #1: expected %s, got %s", string(TestBlock), string(buf[:n]))
692 n, err = v.Get(TestHash2, buf)
694 t.Errorf("Get #2: %v", err)
696 if bytes.Compare(buf[:n], TestBlock2) != 0 {
697 t.Errorf("Get #2: expected %s, got %s", string(TestBlock2), string(buf[:n]))
700 n, err = v.Get(TestHash3, buf)
702 t.Errorf("Get #3: %v", err)
704 if bytes.Compare(buf[:n], TestBlock3) != 0 {
705 t.Errorf("Get #3: expected %s, got %s", string(TestBlock3), string(buf[:n]))
709 // Write and read back a full size block
710 func testPutFullBlock(t TB, factory TestableVolumeFactory) {
718 wdata := make([]byte, BlockSize)
720 wdata[BlockSize-1] = 'z'
721 hash := fmt.Sprintf("%x", md5.Sum(wdata))
722 err := v.Put(hash, wdata)
726 buf := make([]byte, BlockSize)
727 n, err := v.Get(hash, buf)
731 if bytes.Compare(buf[:n], wdata) != 0 {
732 t.Error("buf %+q != wdata %+q", buf[:n], wdata)
736 // With trashLifetime != 0, perform:
737 // Trash an old block - which either raises ErrNotImplemented or succeeds
738 // Untrash - which either raises ErrNotImplemented or succeeds
739 // Get - which must succeed
740 func testTrashUntrash(t TB, factory TestableVolumeFactory) {
747 trashLifetime = 3600 * time.Second
749 // put block and backdate it
750 v.PutRaw(TestHash, TestBlock)
751 v.TouchWithDate(TestHash, time.Now().Add(-2*blobSignatureTTL))
753 buf := make([]byte, BlockSize)
754 n, err := v.Get(TestHash, buf)
758 if bytes.Compare(buf[:n], TestBlock) != 0 {
759 t.Errorf("Got data %+q, expected %+q", buf[:n], TestBlock)
763 err = v.Trash(TestHash)
764 if v.Writable() == false {
765 if err != MethodDisabledError {
768 } else if err != nil {
769 if err != ErrNotImplemented {
773 _, err = v.Get(TestHash, buf)
774 if err == nil || !os.IsNotExist(err) {
775 t.Errorf("os.IsNotExist(%v) should have been true", err)
779 err = v.Untrash(TestHash)
785 // Get the block - after trash and untrash sequence
786 n, err = v.Get(TestHash, buf)
790 if bytes.Compare(buf[:n], TestBlock) != 0 {
791 t.Errorf("Got data %+q, expected %+q", buf[:n], TestBlock)
795 func testTrashEmptyTrashUntrash(t TB, factory TestableVolumeFactory) {
798 defer func(orig time.Duration) {
802 checkGet := func() error {
803 buf := make([]byte, BlockSize)
804 n, err := v.Get(TestHash, buf)
808 if bytes.Compare(buf[:n], TestBlock) != 0 {
809 t.Fatalf("Got data %+q, expected %+q", buf[:n], TestBlock)
812 _, err = v.Mtime(TestHash)
817 err = v.Compare(TestHash, TestBlock)
822 indexBuf := new(bytes.Buffer)
823 v.IndexTo("", indexBuf)
824 if !strings.Contains(string(indexBuf.Bytes()), TestHash) {
825 return os.ErrNotExist
831 // First set: EmptyTrash before reaching the trash deadline.
833 trashLifetime = time.Hour
835 v.PutRaw(TestHash, TestBlock)
836 v.TouchWithDate(TestHash, time.Now().Add(-2*blobSignatureTTL))
844 err = v.Trash(TestHash)
845 if err == MethodDisabledError || err == ErrNotImplemented {
846 // Skip the trash tests for read-only volumes, and
847 // volume types that don't support trashLifetime>0.
852 if err == nil || !os.IsNotExist(err) {
853 t.Fatalf("os.IsNotExist(%v) should have been true", err)
856 err = v.Touch(TestHash)
857 if err == nil || !os.IsNotExist(err) {
858 t.Fatalf("os.IsNotExist(%v) should have been true", err)
863 // Even after emptying the trash, we can untrash our block
864 // because the deadline hasn't been reached.
865 err = v.Untrash(TestHash)
875 err = v.Touch(TestHash)
880 // Because we Touch'ed, need to backdate again for next set of tests
881 v.TouchWithDate(TestHash, time.Now().Add(-2*blobSignatureTTL))
883 // If the only block in the trash has already been untrashed,
884 // most volumes will fail a subsequent Untrash with a 404, but
885 // it's also acceptable for Untrash to succeed.
886 err = v.Untrash(TestHash)
887 if err != nil && !os.IsNotExist(err) {
888 t.Fatalf("Expected success or os.IsNotExist(), but got: %v", err)
891 // The additional Untrash should not interfere with our
892 // already-untrashed copy.
898 // Untrash might have updated the timestamp, so backdate again
899 v.TouchWithDate(TestHash, time.Now().Add(-2*blobSignatureTTL))
901 // Second set: EmptyTrash after the trash deadline has passed.
903 trashLifetime = time.Nanosecond
905 err = v.Trash(TestHash)
910 if err == nil || !os.IsNotExist(err) {
911 t.Fatalf("os.IsNotExist(%v) should have been true", err)
914 // Even though 1ns has passed, we can untrash because we
915 // haven't called EmptyTrash yet.
916 err = v.Untrash(TestHash)
925 // Trash it again, and this time call EmptyTrash so it really
927 // (In Azure volumes, un/trash changes Mtime, so first backdate again)
928 v.TouchWithDate(TestHash, time.Now().Add(-2*blobSignatureTTL))
929 err = v.Trash(TestHash)
931 if err == nil || !os.IsNotExist(err) {
932 t.Fatalf("os.IsNotExist(%v) should have been true", err)
936 // Untrash won't find it
937 err = v.Untrash(TestHash)
938 if err == nil || !os.IsNotExist(err) {
939 t.Fatalf("os.IsNotExist(%v) should have been true", err)
942 // Get block won't find it
944 if err == nil || !os.IsNotExist(err) {
945 t.Fatalf("os.IsNotExist(%v) should have been true", err)
948 // Third set: If the same data block gets written again after
949 // being trashed, and then the trash gets emptied, the newer
950 // un-trashed copy doesn't get deleted along with it.
952 v.PutRaw(TestHash, TestBlock)
953 v.TouchWithDate(TestHash, time.Now().Add(-2*blobSignatureTTL))
955 trashLifetime = time.Nanosecond
956 err = v.Trash(TestHash)
961 if err == nil || !os.IsNotExist(err) {
962 t.Fatalf("os.IsNotExist(%v) should have been true", err)
965 v.PutRaw(TestHash, TestBlock)
966 v.TouchWithDate(TestHash, time.Now().Add(-2*blobSignatureTTL))
968 // EmptyTrash should not delete the untrashed copy.
975 // Fourth set: If the same data block gets trashed twice with
976 // different deadlines A and C, and then the trash is emptied
977 // at intermediate time B (A < B < C), it is still possible to
978 // untrash the block whose deadline is "C".
980 v.PutRaw(TestHash, TestBlock)
981 v.TouchWithDate(TestHash, time.Now().Add(-2*blobSignatureTTL))
983 trashLifetime = time.Nanosecond
984 err = v.Trash(TestHash)
989 v.PutRaw(TestHash, TestBlock)
990 v.TouchWithDate(TestHash, time.Now().Add(-2*blobSignatureTTL))
992 trashLifetime = time.Hour
993 err = v.Trash(TestHash)
998 // EmptyTrash should not prevent us from recovering the
999 // time.Hour ("C") trash
1001 err = v.Untrash(TestHash)