13 "git.curoverse.com/arvados.git/sdk/go/arvadostest"
17 Error(args ...interface{})
18 Errorf(format string, args ...interface{})
22 Fatal(args ...interface{})
23 Fatalf(format string, args ...interface{})
24 Log(args ...interface{})
25 Logf(format string, args ...interface{})
28 // A TestableVolumeFactory returns a new TestableVolume. The factory
29 // function, and the TestableVolume it returns, can use "t" to write
30 // logs, fail the current test, etc.
31 type TestableVolumeFactory func(t TB) TestableVolume
33 // DoGenericVolumeTests runs a set of tests that every TestableVolume
34 // is expected to pass. It calls factory to create a new TestableVolume
35 // for each test case, to avoid leaking state between tests.
36 func DoGenericVolumeTests(t TB, factory TestableVolumeFactory) {
38 testGetNoSuchBlock(t, factory)
40 testCompareNonexistent(t, factory)
41 testCompareSameContent(t, factory, TestHash, TestBlock)
42 testCompareSameContent(t, factory, EmptyHash, EmptyBlock)
43 testCompareWithCollision(t, factory, TestHash, TestBlock, []byte("baddata"))
44 testCompareWithCollision(t, factory, TestHash, TestBlock, EmptyBlock)
45 testCompareWithCollision(t, factory, EmptyHash, EmptyBlock, TestBlock)
46 testCompareWithCorruptStoredData(t, factory, TestHash, TestBlock, []byte("baddata"))
47 testCompareWithCorruptStoredData(t, factory, TestHash, TestBlock, EmptyBlock)
48 testCompareWithCorruptStoredData(t, factory, EmptyHash, EmptyBlock, []byte("baddata"))
50 testPutBlockWithSameContent(t, factory, TestHash, TestBlock)
51 testPutBlockWithSameContent(t, factory, EmptyHash, EmptyBlock)
52 testPutBlockWithDifferentContent(t, factory, arvadostest.MD5CollisionMD5, arvadostest.MD5CollisionData[0], arvadostest.MD5CollisionData[1])
53 testPutBlockWithDifferentContent(t, factory, arvadostest.MD5CollisionMD5, EmptyBlock, arvadostest.MD5CollisionData[0])
54 testPutBlockWithDifferentContent(t, factory, arvadostest.MD5CollisionMD5, arvadostest.MD5CollisionData[0], EmptyBlock)
55 testPutBlockWithDifferentContent(t, factory, EmptyHash, EmptyBlock, arvadostest.MD5CollisionData[0])
56 testPutMultipleBlocks(t, factory)
58 testPutAndTouch(t, factory)
59 testTouchNoSuchBlock(t, factory)
61 testMtimeNoSuchBlock(t, factory)
63 testIndexTo(t, factory)
65 testDeleteNewBlock(t, factory)
66 testDeleteOldBlock(t, factory)
67 testDeleteNoSuchBlock(t, factory)
69 testStatus(t, factory)
71 testString(t, factory)
73 testUpdateReadOnly(t, factory)
75 testGetConcurrent(t, factory)
76 testPutConcurrent(t, factory)
78 testPutFullBlock(t, factory)
80 testTrashUntrash(t, factory)
81 testTrashEmptyTrashUntrash(t, factory)
82 testTrashUntrashWithEmptyTrashGoroutine(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, err := v.Get(TestHash)
100 if bytes.Compare(buf, 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 if _, err := v.Get(TestHash2); 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, getErr := v.Get(testHash)
214 // Put must not return a nil error unless it has
215 // overwritten the existing data.
216 if bytes.Compare(buf, testDataB) != 0 {
217 t.Errorf("Put succeeded but Get returned %+q, expected %+q", buf, testDataB)
220 // It is permissible for Put to fail, but it must
221 // leave us with either the original data, the new
222 // data, or nothing at all.
223 if getErr == nil && bytes.Compare(buf, testDataA) != 0 && bytes.Compare(buf, testDataB) != 0 {
224 t.Errorf("Put failed but Get returned %+q, which is neither %+q nor %+q", buf, 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(TestHash, TestBlock)
244 t.Errorf("Got err putting block %q: %q, expected nil", TestBlock, err)
247 err = v.Put(TestHash2, TestBlock2)
249 t.Errorf("Got err putting block %q: %q, expected nil", TestBlock2, err)
252 err = v.Put(TestHash3, TestBlock3)
254 t.Errorf("Got err putting block %q: %q, expected nil", TestBlock3, err)
257 data, err := v.Get(TestHash)
261 if bytes.Compare(data, TestBlock) != 0 {
262 t.Errorf("Block present, but got %+q, expected %+q", data, TestBlock)
267 data, err = v.Get(TestHash2)
271 if bytes.Compare(data, TestBlock2) != 0 {
272 t.Errorf("Block present, but got %+q, expected %+q", data, TestBlock2)
277 data, err = v.Get(TestHash3)
281 if bytes.Compare(data, TestBlock3) != 0 {
282 t.Errorf("Block present, but to %+q, expected %+q", data, TestBlock3)
289 // Test that when applying PUT to a block that already exists,
290 // the block's modification time is updated.
291 // Test is intended for only writable volumes
292 func testPutAndTouch(t TB, factory TestableVolumeFactory) {
296 if v.Writable() == false {
300 if err := v.Put(TestHash, TestBlock); err != nil {
304 // We'll verify { t0 < threshold < t1 }, where t0 is the
305 // existing block's timestamp on disk before Put() and t1 is
306 // its timestamp after Put().
307 threshold := time.Now().Add(-time.Second)
309 // Set the stored block's mtime far enough in the past that we
310 // can see the difference between "timestamp didn't change"
311 // and "timestamp granularity is too low".
312 v.TouchWithDate(TestHash, time.Now().Add(-20*time.Second))
314 // Make sure v.Mtime() agrees the above Utime really worked.
315 if t0, err := v.Mtime(TestHash); err != nil || t0.IsZero() || !t0.Before(threshold) {
316 t.Errorf("Setting mtime failed: %v, %v", t0, err)
319 // Write the same block again.
320 if err := v.Put(TestHash, TestBlock); err != nil {
324 // Verify threshold < t1
325 if t1, err := v.Mtime(TestHash); err != nil {
327 } else if t1.Before(threshold) {
328 t.Errorf("t1 %v should be >= threshold %v after v.Put ", t1, threshold)
332 // Touching a non-existing block should result in error.
333 // Test should pass for both writable and read-only volumes
334 func testTouchNoSuchBlock(t TB, factory TestableVolumeFactory) {
338 if err := v.Touch(TestHash); err == nil {
339 t.Error("Expected error when attempted to touch a non-existing block")
343 // Invoking Mtime on a non-existing block should result in error.
344 // Test should pass for both writable and read-only volumes
345 func testMtimeNoSuchBlock(t TB, factory TestableVolumeFactory) {
349 if _, err := v.Mtime("12345678901234567890123456789012"); err == nil {
350 t.Error("Expected error when updating Mtime on a non-existing block")
354 // Put a few blocks and invoke IndexTo with:
357 // * with no such prefix
358 // Test should pass for both writable and read-only volumes
359 func testIndexTo(t TB, factory TestableVolumeFactory) {
363 v.PutRaw(TestHash, TestBlock)
364 v.PutRaw(TestHash2, TestBlock2)
365 v.PutRaw(TestHash3, TestBlock3)
367 // Blocks whose names aren't Keep hashes should be omitted from
369 v.PutRaw("fffffffffnotreallyahashfffffffff", nil)
370 v.PutRaw("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", nil)
371 v.PutRaw("f0000000000000000000000000000000f", nil)
374 buf := new(bytes.Buffer)
376 indexRows := strings.Split(string(buf.Bytes()), "\n")
377 sort.Strings(indexRows)
378 sortedIndex := strings.Join(indexRows, "\n")
379 m, err := regexp.MatchString(
380 `^\n`+TestHash+`\+\d+ \d+\n`+
381 TestHash3+`\+\d+ \d+\n`+
382 TestHash2+`\+\d+ \d+$`,
387 t.Errorf("Got index %q for empty prefix", sortedIndex)
390 for _, prefix := range []string{"f", "f15", "f15ac"} {
391 buf = new(bytes.Buffer)
392 v.IndexTo(prefix, buf)
394 m, err := regexp.MatchString(`^`+TestHash2+`\+\d+ \d+\n$`, string(buf.Bytes()))
398 t.Errorf("Got index %q for prefix %s", string(buf.Bytes()), prefix)
402 for _, prefix := range []string{"zero", "zip", "zilch"} {
403 buf = new(bytes.Buffer)
404 v.IndexTo(prefix, buf)
406 t.Errorf("Got error on IndexTo with no such prefix %v", err.Error())
407 } else if buf.Len() != 0 {
408 t.Errorf("Expected empty list for IndexTo with no such prefix %s", prefix)
413 // Calling Delete() for a block immediately after writing it (not old enough)
414 // should neither delete the data nor return an error.
415 // Test is intended for only writable volumes
416 func testDeleteNewBlock(t TB, factory TestableVolumeFactory) {
419 blobSignatureTTL = 300 * time.Second
421 if v.Writable() == false {
425 v.Put(TestHash, TestBlock)
427 if err := v.Trash(TestHash); err != nil {
430 data, err := v.Get(TestHash)
434 if bytes.Compare(data, TestBlock) != 0 {
435 t.Errorf("Got data %+q, expected %+q", data, TestBlock)
441 // Calling Delete() for a block with a timestamp older than
442 // blobSignatureTTL seconds in the past should delete the data.
443 // Test is intended for only writable volumes
444 func testDeleteOldBlock(t TB, factory TestableVolumeFactory) {
447 blobSignatureTTL = 300 * time.Second
449 if v.Writable() == false {
453 v.Put(TestHash, TestBlock)
454 v.TouchWithDate(TestHash, time.Now().Add(-2*blobSignatureTTL))
456 if err := v.Trash(TestHash); err != nil {
459 if _, err := v.Get(TestHash); err == nil || !os.IsNotExist(err) {
460 t.Errorf("os.IsNotExist(%v) should have been true", err)
464 // Calling Delete() for a block that does not exist should result in error.
465 // Test should pass for both writable and read-only volumes
466 func testDeleteNoSuchBlock(t TB, factory TestableVolumeFactory) {
470 if err := v.Trash(TestHash2); err == nil {
471 t.Errorf("Expected error when attempting to delete a non-existing block")
475 // Invoke Status and verify that VolumeStatus is returned
476 // Test should pass for both writable and read-only volumes
477 func testStatus(t TB, factory TestableVolumeFactory) {
481 // Get node status and make a basic sanity check.
483 if status.DeviceNum == 0 {
484 t.Errorf("uninitialized device_num in %v", status)
487 if status.BytesFree == 0 {
488 t.Errorf("uninitialized bytes_free in %v", status)
491 if status.BytesUsed == 0 {
492 t.Errorf("uninitialized bytes_used in %v", status)
496 // Invoke String for the volume; expect non-empty result
497 // Test should pass for both writable and read-only volumes
498 func testString(t TB, factory TestableVolumeFactory) {
502 if id := v.String(); len(id) == 0 {
503 t.Error("Got empty string for v.String()")
507 // Putting, updating, touching, and deleting blocks from a read-only volume result in error.
508 // Test is intended for only read-only volumes
509 func testUpdateReadOnly(t TB, factory TestableVolumeFactory) {
513 if v.Writable() == true {
517 v.PutRaw(TestHash, TestBlock)
519 // Get from read-only volume should succeed
520 _, err := v.Get(TestHash)
522 t.Errorf("got err %v, expected nil", err)
525 // Put a new block to read-only volume should result in error
526 err = v.Put(TestHash2, TestBlock2)
528 t.Errorf("Expected error when putting block in a read-only volume")
530 _, err = v.Get(TestHash2)
532 t.Errorf("Expected error when getting block whose put in read-only volume failed")
535 // Touch a block in read-only volume should result in error
536 err = v.Touch(TestHash)
538 t.Errorf("Expected error when touching block in a read-only volume")
541 // Delete a block from a read-only volume should result in error
542 err = v.Trash(TestHash)
544 t.Errorf("Expected error when deleting block from a read-only volume")
547 // Overwriting an existing block in read-only volume should result in error
548 err = v.Put(TestHash, TestBlock)
550 t.Errorf("Expected error when putting block in a read-only volume")
554 // Launch concurrent Gets
555 // Test should pass for both writable and read-only volumes
556 func testGetConcurrent(t TB, factory TestableVolumeFactory) {
560 v.PutRaw(TestHash, TestBlock)
561 v.PutRaw(TestHash2, TestBlock2)
562 v.PutRaw(TestHash3, TestBlock3)
564 sem := make(chan int)
565 go func(sem chan int) {
566 buf, err := v.Get(TestHash)
568 t.Errorf("err1: %v", err)
571 if bytes.Compare(buf, TestBlock) != 0 {
572 t.Errorf("buf should be %s, is %s", string(TestBlock), string(buf))
577 go func(sem chan int) {
578 buf, err := v.Get(TestHash2)
580 t.Errorf("err2: %v", err)
583 if bytes.Compare(buf, TestBlock2) != 0 {
584 t.Errorf("buf should be %s, is %s", string(TestBlock2), string(buf))
589 go func(sem chan int) {
590 buf, err := v.Get(TestHash3)
592 t.Errorf("err3: %v", err)
595 if bytes.Compare(buf, TestBlock3) != 0 {
596 t.Errorf("buf should be %s, is %s", string(TestBlock3), string(buf))
601 // Wait for all goroutines to finish
602 for done := 0; done < 3; {
607 // Launch concurrent Puts
608 // Test is intended for only writable volumes
609 func testPutConcurrent(t TB, factory TestableVolumeFactory) {
613 if v.Writable() == false {
617 sem := make(chan int)
618 go func(sem chan int) {
619 err := v.Put(TestHash, TestBlock)
621 t.Errorf("err1: %v", err)
626 go func(sem chan int) {
627 err := v.Put(TestHash2, TestBlock2)
629 t.Errorf("err2: %v", err)
634 go func(sem chan int) {
635 err := v.Put(TestHash3, TestBlock3)
637 t.Errorf("err3: %v", err)
642 // Wait for all goroutines to finish
643 for done := 0; done < 3; {
647 // Double check that we actually wrote the blocks we expected to write.
648 buf, err := v.Get(TestHash)
650 t.Errorf("Get #1: %v", err)
653 if bytes.Compare(buf, TestBlock) != 0 {
654 t.Errorf("Get #1: expected %s, got %s", string(TestBlock), string(buf))
657 buf, err = v.Get(TestHash2)
659 t.Errorf("Get #2: %v", err)
662 if bytes.Compare(buf, TestBlock2) != 0 {
663 t.Errorf("Get #2: expected %s, got %s", string(TestBlock2), string(buf))
666 buf, err = v.Get(TestHash3)
668 t.Errorf("Get #3: %v", err)
671 if bytes.Compare(buf, TestBlock3) != 0 {
672 t.Errorf("Get #3: expected %s, got %s", string(TestBlock3), string(buf))
676 // Write and read back a full size block
677 func testPutFullBlock(t TB, factory TestableVolumeFactory) {
685 wdata := make([]byte, BlockSize)
687 wdata[BlockSize-1] = 'z'
688 hash := fmt.Sprintf("%x", md5.Sum(wdata))
689 err := v.Put(hash, wdata)
693 rdata, err := v.Get(hash)
697 defer bufs.Put(rdata)
699 if bytes.Compare(rdata, wdata) != 0 {
700 t.Error("rdata != wdata")
704 // With trashLifetime != 0, perform:
705 // Trash an old block - which either raises ErrNotImplemented or succeeds
706 // Untrash - which either raises ErrNotImplemented or succeeds
707 // Get - which must succeed
708 func testTrashUntrash(t TB, factory TestableVolumeFactory) {
712 trashLifetime = 0 * time.Second
715 trashLifetime = 3600 * time.Second
717 // put block and backdate it
718 v.PutRaw(TestHash, TestBlock)
719 v.TouchWithDate(TestHash, time.Now().Add(-2*blobSignatureTTL))
721 buf, err := v.Get(TestHash)
725 if bytes.Compare(buf, TestBlock) != 0 {
726 t.Errorf("Got data %+q, expected %+q", buf, TestBlock)
731 err = v.Trash(TestHash)
732 if v.Writable() == false {
733 if err != MethodDisabledError {
736 } else if err != nil {
737 if err != ErrNotImplemented {
741 _, err = v.Get(TestHash)
742 if err == nil || !os.IsNotExist(err) {
743 t.Errorf("os.IsNotExist(%v) should have been true", err)
747 err = v.Untrash(TestHash)
753 // Get the block - after trash and untrash sequence
754 buf, err = v.Get(TestHash)
758 if bytes.Compare(buf, TestBlock) != 0 {
759 t.Errorf("Got data %+q, expected %+q", buf, TestBlock)
764 func testTrashEmptyTrashUntrash(t TB, factory TestableVolumeFactory) {
768 trashLifetime = 0 * time.Second
771 // First set of tests
773 // With trashLifetime = 1h, test trash/untrash cycle.
774 trashLifetime = 1 * time.Hour
776 // put block and backdate it
777 v.PutRaw(TestHash, TestBlock)
778 v.TouchWithDate(TestHash, time.Now().Add(-2*blobSignatureTTL))
780 buf, err := v.Get(TestHash)
784 if bytes.Compare(buf, TestBlock) != 0 {
785 t.Fatalf("Got data %+q, expected %+q", buf, TestBlock)
790 err = v.Trash(TestHash)
791 if err == MethodDisabledError || err == ErrNotImplemented {
795 buf, err = v.Get(TestHash)
796 if err == nil || !os.IsNotExist(err) {
797 t.Fatalf("os.IsNotExist(%v) should have been true", err)
800 // Empty trash; the block is still within trashLifetime and hence is not emptied
803 // Untrash will hence rescue it
804 err = v.Untrash(TestHash)
809 // Get block will find it
810 buf, err = v.Get(TestHash)
814 if bytes.Compare(buf, TestBlock) != 0 {
815 t.Fatalf("Got data %+q, expected %+q", buf, TestBlock)
819 // Untrash again; should fail
820 err = v.Untrash(TestHash)
821 if err == nil || !os.IsNotExist(err) {
822 t.Fatalf("os.IsNotExist(%v) should have been true", err)
825 buf, err = v.Get(TestHash)
829 if bytes.Compare(buf, TestBlock) != 0 {
830 t.Fatalf("Got data %+q, expected %+q", buf, TestBlock)
834 // Second set of tests
836 // With trashLifetime = 1ns, test trash/untrash cycle.
837 trashLifetime = 1 * time.Nanosecond
840 err = v.Trash(TestHash)
844 buf, err = v.Get(TestHash)
845 if err == nil || !os.IsNotExist(err) {
846 t.Fatalf("os.IsNotExist(%v) should have been true", err)
850 err = v.Untrash(TestHash)
855 // Get block will find it
856 buf, err = v.Get(TestHash)
860 if bytes.Compare(buf, TestBlock) != 0 {
861 t.Fatalf("Got data %+q, expected %+q", buf, TestBlock)
866 err = v.Trash(TestHash)
867 if err == MethodDisabledError || err == ErrNotImplemented {
870 buf, err = v.Get(TestHash)
871 if err == nil || !os.IsNotExist(err) {
872 t.Errorf("os.IsNotExist(%v) should have been true", err)
875 // Empty trash will empty it
878 // Untrash won't find it
879 err = v.Untrash(TestHash)
880 if err == nil || !os.IsNotExist(err) {
881 t.Fatalf("os.IsNotExist(%v) should have been true", err)
884 // Get block won't find it
885 buf, err = v.Get(TestHash)
886 if err == nil || !os.IsNotExist(err) {
887 t.Fatalf("os.IsNotExist(%v) should have been true", err)
890 // Third set of tests
892 // Still with trashLifetime = 1ns: put, trash, put one more, trash etc
893 // put block and backdate it
894 v.PutRaw(TestHash, TestBlock)
895 v.TouchWithDate(TestHash, time.Now().Add(-2*blobSignatureTTL))
898 err = v.Trash(TestHash)
899 if err == MethodDisabledError || err == ErrNotImplemented {
902 buf, err = v.Get(TestHash)
903 if err == nil || !os.IsNotExist(err) {
904 t.Fatalf("os.IsNotExist(%v) should have been true", err)
908 err = v.Put(TestHash, TestBlock)
912 v.TouchWithDate(TestHash, time.Now().Add(-2*blobSignatureTTL))
914 // Empty trash will empty the trashed block but the second one is untouched
917 // Get block should work because of the second block
918 buf, err = v.Get(TestHash)
922 if bytes.Compare(buf, TestBlock) != 0 {
923 t.Fatalf("Got data %+q, expected %+q", buf, TestBlock)
927 // set trashLifetime to one hour
928 trashLifetime = 1 * time.Hour
931 err = v.Trash(TestHash)
936 // Empty trash won't empty this second block which is still within trashLifetime
939 // Untrash; the second block which is still within trashLifetime will be rescued
940 err = v.Untrash(TestHash)
945 // Get block should work because of the second block
946 buf, err = v.Get(TestHash)
950 if bytes.Compare(buf, TestBlock) != 0 {
951 t.Fatalf("Got data %+q, expected %+q", buf, TestBlock)
956 // With trashLifetime = 1ns, perform:
957 // Run emptyTrash goroutine
958 // Trash an old block - which either raises ErrNotImplemented or succeeds
959 // Untrash - after emptyTrash goroutine ticks, and hence does not actually untrash
960 // Get - which must fail to find the block
961 func testTrashUntrashWithEmptyTrashGoroutine(t TB, factory TestableVolumeFactory) {
965 doneEmptyingTrash := make(chan bool)
967 trashLifetime = 0 * time.Second
968 doneEmptyingTrash <- true
971 volumes = append(volumes, v)
973 trashLifetime = 1 * time.Nanosecond
974 trashCheckInterval = 1 * time.Nanosecond
976 go emptyTrash(doneEmptyingTrash, trashCheckInterval)
978 // Trash old block and untrash a little after first trashCheckInterval
979 v.PutRaw(TestHash, TestBlock)
980 v.TouchWithDate(TestHash, time.Now().Add(-2*blobSignatureTTL))
982 buf, err := v.Get(TestHash)
986 if bytes.Compare(buf, TestBlock) != 0 {
987 t.Fatalf("Got data %+q, expected %+q", buf, TestBlock)
992 err = v.Trash(TestHash)
993 if err == MethodDisabledError || err == ErrNotImplemented {
997 _, err = v.Get(TestHash)
998 if err == nil || !os.IsNotExist(err) {
999 t.Fatalf("os.IsNotExist(%v) should have been true", err)
1002 time.Sleep(2 * time.Nanosecond)
1005 err = v.Untrash(TestHash)
1010 // Get is expected to fail due to EmptyTrash before Untrash
1011 // It is still found on readonly volumes
1012 buf, err = v.Get(TestHash)
1014 if !os.IsNotExist(err) {
1015 t.Errorf("os.IsNotExist(%v) should have been true", err)
1018 if bytes.Compare(buf, TestBlock) != 0 {
1019 t.Errorf("Got data %+q, expected %+q", buf, TestBlock)