+ return nil
+ }
+
+ // First set: EmptyTrash before reaching the trash deadline.
+
+ s.cluster.Collections.BlobTrashLifetime.Set("1h")
+
+ v.BlockWrite(context.Background(), TestHash, TestBlock)
+ v.TouchWithDate(TestHash, time.Now().Add(-2*s.cluster.Collections.BlobSigningTTL.Duration()))
+
+ err := checkGet()
+ if err != nil {
+ t.Error(err)
+ }
+
+ // Trash the block
+ err = v.BlockTrash(TestHash)
+ if err != nil {
+ t.Error(err)
+ }
+
+ err = checkGet()
+ if err == nil || !os.IsNotExist(err) {
+ t.Errorf("os.IsNotExist(%v) should have been true", err)
+ }
+
+ err = v.BlockTouch(TestHash)
+ if err == nil || !os.IsNotExist(err) {
+ t.Errorf("os.IsNotExist(%v) should have been true", err)
+ }
+
+ v.EmptyTrash()
+
+ // Even after emptying the trash, we can untrash our block
+ // because the deadline hasn't been reached.
+ err = v.BlockUntrash(TestHash)
+ if err != nil {
+ t.Error(err)
+ }
+
+ err = checkGet()
+ if err != nil {
+ t.Error(err)
+ }
+
+ err = v.BlockTouch(TestHash)
+ if err != nil {
+ t.Error(err)
+ }
+
+ // Because we Touch'ed, need to backdate again for next set of tests
+ v.TouchWithDate(TestHash, time.Now().Add(-2*s.cluster.Collections.BlobSigningTTL.Duration()))
+
+ // If the only block in the trash has already been untrashed,
+ // most volumes will fail a subsequent Untrash with a 404, but
+ // it's also acceptable for Untrash to succeed.
+ err = v.BlockUntrash(TestHash)
+ if err != nil && !os.IsNotExist(err) {
+ t.Errorf("Expected success or os.IsNotExist(), but got: %v", err)
+ }
+
+ // The additional Untrash should not interfere with our
+ // already-untrashed copy.
+ err = checkGet()
+ if err != nil {
+ t.Error(err)
+ }
+
+ // Untrash might have updated the timestamp, so backdate again
+ v.TouchWithDate(TestHash, time.Now().Add(-2*s.cluster.Collections.BlobSigningTTL.Duration()))
+
+ // Second set: EmptyTrash after the trash deadline has passed.
+
+ s.cluster.Collections.BlobTrashLifetime.Set("1ns")
+
+ err = v.BlockTrash(TestHash)
+ if err != nil {
+ t.Error(err)
+ }
+ err = checkGet()
+ if err == nil || !os.IsNotExist(err) {
+ t.Errorf("os.IsNotExist(%v) should have been true", err)
+ }
+
+ // Even though 1ns has passed, we can untrash because we
+ // haven't called EmptyTrash yet.
+ err = v.BlockUntrash(TestHash)
+ if err != nil {
+ t.Error(err)
+ }
+ err = checkGet()
+ if err != nil {
+ t.Error(err)
+ }
+
+ // Trash it again, and this time call EmptyTrash so it really
+ // goes away.
+ // (In Azure volumes, un/trash changes Mtime, so first backdate again)
+ v.TouchWithDate(TestHash, time.Now().Add(-2*s.cluster.Collections.BlobSigningTTL.Duration()))
+ _ = v.BlockTrash(TestHash)
+ err = checkGet()
+ if err == nil || !os.IsNotExist(err) {
+ t.Errorf("os.IsNotExist(%v) should have been true", err)