projects
/
arvados.git
/ blobdiff
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
9956: Remove obsolete TODO comment.
[arvados.git]
/
services
/
keepstore
/
volume_generic_test.go
diff --git
a/services/keepstore/volume_generic_test.go
b/services/keepstore/volume_generic_test.go
index f8fe0d0ebce719c6c823fe9caa9fcce12324eb49..1738fe9b513bb4d86482ceede86a04539d29d418 100644
(file)
--- a/
services/keepstore/volume_generic_test.go
+++ b/
services/keepstore/volume_generic_test.go
@@
-7,9
+7,11
@@
import (
"os"
"regexp"
"sort"
"os"
"regexp"
"sort"
+ "strconv"
"strings"
"time"
"strings"
"time"
+ "git.curoverse.com/arvados.git/sdk/go/arvados"
"git.curoverse.com/arvados.git/sdk/go/arvadostest"
)
"git.curoverse.com/arvados.git/sdk/go/arvadostest"
)
@@
-355,10
+357,22
@@
func testIndexTo(t TB, factory TestableVolumeFactory) {
v := factory(t)
defer v.Teardown()
v := factory(t)
defer v.Teardown()
+ // minMtime and maxMtime are the minimum and maximum
+ // acceptable values the index can report for our test
+ // blocks. 1-second precision is acceptable.
+ minMtime := time.Now().UTC().UnixNano()
+ minMtime -= minMtime % 1e9
+
v.PutRaw(TestHash, TestBlock)
v.PutRaw(TestHash2, TestBlock2)
v.PutRaw(TestHash3, TestBlock3)
v.PutRaw(TestHash, TestBlock)
v.PutRaw(TestHash2, TestBlock2)
v.PutRaw(TestHash3, TestBlock3)
+ maxMtime := time.Now().UTC().UnixNano()
+ if maxMtime%1e9 > 0 {
+ maxMtime -= maxMtime % 1e9
+ maxMtime += 1e9
+ }
+
// Blocks whose names aren't Keep hashes should be omitted from
// index
v.PutRaw("fffffffffnotreallyahashfffffffff", nil)
// Blocks whose names aren't Keep hashes should be omitted from
// index
v.PutRaw("fffffffffnotreallyahashfffffffff", nil)
@@
-371,15
+385,21
@@
func testIndexTo(t TB, factory TestableVolumeFactory) {
indexRows := strings.Split(string(buf.Bytes()), "\n")
sort.Strings(indexRows)
sortedIndex := strings.Join(indexRows, "\n")
indexRows := strings.Split(string(buf.Bytes()), "\n")
sort.Strings(indexRows)
sortedIndex := strings.Join(indexRows, "\n")
- m, err := regexp.MatchString(
- `^\n`+TestHash+`\+\d+ \d+\n`+
- TestHash3+`\+\d+ \d+\n`+
- TestHash2+`\+\d+ \d+$`,
- sortedIndex)
- if err != nil {
- t.Error(err)
- } else if !m {
+ m := regexp.MustCompile(
+ `^\n` + TestHash + `\+\d+ (\d+)\n` +
+ TestHash3 + `\+\d+ \d+\n` +
+ TestHash2 + `\+\d+ \d+$`,
+ ).FindStringSubmatch(sortedIndex)
+ if m == nil {
t.Errorf("Got index %q for empty prefix", sortedIndex)
t.Errorf("Got index %q for empty prefix", sortedIndex)
+ } else {
+ mtime, err := strconv.ParseInt(m[1], 10, 64)
+ if err != nil {
+ t.Error(err)
+ } else if mtime < minMtime || mtime > maxMtime {
+ t.Errorf("got %d for TestHash timestamp, expected %d <= t <= %d",
+ mtime, minMtime, maxMtime)
+ }
}
for _, prefix := range []string{"f", "f15", "f15ac"} {
}
for _, prefix := range []string{"f", "f15", "f15ac"} {
@@
-396,7
+416,7
@@
func testIndexTo(t TB, factory TestableVolumeFactory) {
for _, prefix := range []string{"zero", "zip", "zilch"} {
buf = new(bytes.Buffer)
for _, prefix := range []string{"zero", "zip", "zilch"} {
buf = new(bytes.Buffer)
- v.IndexTo(prefix, buf)
+
err :=
v.IndexTo(prefix, buf)
if err != nil {
t.Errorf("Got error on IndexTo with no such prefix %v", err.Error())
} else if buf.Len() != 0 {
if err != nil {
t.Errorf("Got error on IndexTo with no such prefix %v", err.Error())
} else if buf.Len() != 0 {
@@
-411,7
+431,7
@@
func testIndexTo(t TB, factory TestableVolumeFactory) {
func testDeleteNewBlock(t TB, factory TestableVolumeFactory) {
v := factory(t)
defer v.Teardown()
func testDeleteNewBlock(t TB, factory TestableVolumeFactory) {
v := factory(t)
defer v.Teardown()
- blobSignatureTTL = 300 * time.Second
+ theConfig.BlobSignatureTTL.Set("5m")
if v.Writable() == false {
return
if v.Writable() == false {
return
@@
-432,19
+452,19
@@
func testDeleteNewBlock(t TB, factory TestableVolumeFactory) {
}
// Calling Delete() for a block with a timestamp older than
}
// Calling Delete() for a block with a timestamp older than
-//
b
lobSignatureTTL seconds in the past should delete the data.
+//
B
lobSignatureTTL seconds in the past should delete the data.
// Test is intended for only writable volumes
func testDeleteOldBlock(t TB, factory TestableVolumeFactory) {
v := factory(t)
defer v.Teardown()
// Test is intended for only writable volumes
func testDeleteOldBlock(t TB, factory TestableVolumeFactory) {
v := factory(t)
defer v.Teardown()
- blobSignatureTTL = 300 * time.Second
+ theConfig.BlobSignatureTTL.Set("5m")
if v.Writable() == false {
return
}
v.Put(TestHash, TestBlock)
if v.Writable() == false {
return
}
v.Put(TestHash, TestBlock)
- v.TouchWithDate(TestHash, time.Now().Add(-2*
blobSignatureTTL
))
+ v.TouchWithDate(TestHash, time.Now().Add(-2*
theConfig.BlobSignatureTTL.Duration()
))
if err := v.Trash(TestHash); err != nil {
t.Error(err)
if err := v.Trash(TestHash); err != nil {
t.Error(err)
@@
-714,7
+734,7
@@
func testPutFullBlock(t TB, factory TestableVolumeFactory) {
}
}
}
}
-// With
t
rashLifetime != 0, perform:
+// With
T
rashLifetime != 0, perform:
// Trash an old block - which either raises ErrNotImplemented or succeeds
// Untrash - which either raises ErrNotImplemented or succeeds
// Get - which must succeed
// Trash an old block - which either raises ErrNotImplemented or succeeds
// Untrash - which either raises ErrNotImplemented or succeeds
// Get - which must succeed
@@
-722,14
+742,14
@@
func testTrashUntrash(t TB, factory TestableVolumeFactory) {
v := factory(t)
defer v.Teardown()
defer func() {
v := factory(t)
defer v.Teardown()
defer func() {
- t
rashLifetime = 0 * time.Second
+ t
heConfig.TrashLifetime = 0
}()
}()
- t
rashLifetime = 3600 * time.Second
+ t
heConfig.TrashLifetime.Set("1h")
// put block and backdate it
v.PutRaw(TestHash, TestBlock)
// put block and backdate it
v.PutRaw(TestHash, TestBlock)
- v.TouchWithDate(TestHash, time.Now().Add(-2*
blobSignatureTTL
))
+ v.TouchWithDate(TestHash, time.Now().Add(-2*
theConfig.BlobSignatureTTL.Duration()
))
buf := make([]byte, BlockSize)
n, err := v.Get(TestHash, buf)
buf := make([]byte, BlockSize)
n, err := v.Get(TestHash, buf)
@@
-776,9
+796,9
@@
func testTrashUntrash(t TB, factory TestableVolumeFactory) {
func testTrashEmptyTrashUntrash(t TB, factory TestableVolumeFactory) {
v := factory(t)
defer v.Teardown()
func testTrashEmptyTrashUntrash(t TB, factory TestableVolumeFactory) {
v := factory(t)
defer v.Teardown()
- defer func(orig
time
.Duration) {
- trashLifetime = orig
- }(trashLifetime)
+ defer func(orig
arvados
.Duration) {
+ t
heConfig.T
rashLifetime = orig
+ }(t
heConfig.T
rashLifetime)
checkGet := func() error {
buf := make([]byte, BlockSize)
checkGet := func() error {
buf := make([]byte, BlockSize)
@@
-811,10
+831,10
@@
func testTrashEmptyTrashUntrash(t TB, factory TestableVolumeFactory) {
// First set: EmptyTrash before reaching the trash deadline.
// First set: EmptyTrash before reaching the trash deadline.
- t
rashLifetime = 1 * time.Hour
+ t
heConfig.TrashLifetime.Set("1h")
v.PutRaw(TestHash, TestBlock)
v.PutRaw(TestHash, TestBlock)
- v.TouchWithDate(TestHash, time.Now().Add(-2*
blobSignatureTTL
))
+ v.TouchWithDate(TestHash, time.Now().Add(-2*
theConfig.BlobSignatureTTL.Duration()
))
err := checkGet()
if err != nil {
err := checkGet()
if err != nil {
@@
-825,7
+845,7
@@
func testTrashEmptyTrashUntrash(t TB, factory TestableVolumeFactory) {
err = v.Trash(TestHash)
if err == MethodDisabledError || err == ErrNotImplemented {
// Skip the trash tests for read-only volumes, and
err = v.Trash(TestHash)
if err == MethodDisabledError || err == ErrNotImplemented {
// Skip the trash tests for read-only volumes, and
- // volume types that don't support
t
rashLifetime>0.
+ // volume types that don't support
T
rashLifetime>0.
return
}
return
}
@@
-859,25
+879,29
@@
func testTrashEmptyTrashUntrash(t TB, factory TestableVolumeFactory) {
}
// Because we Touch'ed, need to backdate again for next set of tests
}
// Because we Touch'ed, need to backdate again for next set of tests
- v.TouchWithDate(TestHash, time.Now().Add(-2*
blobSignatureTTL
))
+ v.TouchWithDate(TestHash, time.Now().Add(-2*
theConfig.BlobSignatureTTL.Duration()
))
- // Untrash should fail if the only block in the trash has
- // already been untrashed.
+ // 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.Untrash(TestHash)
err = v.Untrash(TestHash)
- if err
== nil ||
!os.IsNotExist(err) {
- t.Fatalf("
os.IsNotExist(%v) should have been true
", err)
+ if err
!= nil &&
!os.IsNotExist(err) {
+ t.Fatalf("
Expected success or os.IsNotExist(), but got: %v
", err)
}
}
- // The
failed
Untrash should not interfere with our
+ // The
additional
Untrash should not interfere with our
// already-untrashed copy.
err = checkGet()
if err != nil {
t.Fatal(err)
}
// already-untrashed copy.
err = checkGet()
if err != nil {
t.Fatal(err)
}
+ // Untrash might have updated the timestamp, so backdate again
+ v.TouchWithDate(TestHash, time.Now().Add(-2*theConfig.BlobSignatureTTL.Duration()))
+
// Second set: EmptyTrash after the trash deadline has passed.
// Second set: EmptyTrash after the trash deadline has passed.
- t
rashLifetime = 1 * time.Nanosecond
+ t
heConfig.TrashLifetime.Set("1ns")
err = v.Trash(TestHash)
if err != nil {
err = v.Trash(TestHash)
if err != nil {
@@
-902,13
+926,12
@@
func testTrashEmptyTrashUntrash(t TB, factory TestableVolumeFactory) {
// Trash it again, and this time call EmptyTrash so it really
// goes away.
// (In Azure volumes, un/trash changes Mtime, so first backdate again)
// 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*
blobSignatureTTL
))
+ v.TouchWithDate(TestHash, time.Now().Add(-2*
theConfig.BlobSignatureTTL.Duration()
))
err = v.Trash(TestHash)
err = checkGet()
if err == nil || !os.IsNotExist(err) {
t.Fatalf("os.IsNotExist(%v) should have been true", err)
}
err = v.Trash(TestHash)
err = checkGet()
if err == nil || !os.IsNotExist(err) {
t.Fatalf("os.IsNotExist(%v) should have been true", err)
}
- // EmptryTrash
v.EmptyTrash()
// Untrash won't find it
v.EmptyTrash()
// Untrash won't find it
@@
-928,9
+951,9
@@
func testTrashEmptyTrashUntrash(t TB, factory TestableVolumeFactory) {
// un-trashed copy doesn't get deleted along with it.
v.PutRaw(TestHash, TestBlock)
// un-trashed copy doesn't get deleted along with it.
v.PutRaw(TestHash, TestBlock)
- v.TouchWithDate(TestHash, time.Now().Add(-2*
blobSignatureTTL
))
+ v.TouchWithDate(TestHash, time.Now().Add(-2*
theConfig.BlobSignatureTTL.Duration()
))
- t
rashLifetime = time.Nanosecond
+ t
heConfig.TrashLifetime.Set("1ns")
err = v.Trash(TestHash)
if err != nil {
t.Fatal(err)
err = v.Trash(TestHash)
if err != nil {
t.Fatal(err)
@@
-941,7
+964,7
@@
func testTrashEmptyTrashUntrash(t TB, factory TestableVolumeFactory) {
}
v.PutRaw(TestHash, TestBlock)
}
v.PutRaw(TestHash, TestBlock)
- v.TouchWithDate(TestHash, time.Now().Add(-2*
blobSignatureTTL
))
+ v.TouchWithDate(TestHash, time.Now().Add(-2*
theConfig.BlobSignatureTTL.Duration()
))
// EmptyTrash should not delete the untrashed copy.
v.EmptyTrash()
// EmptyTrash should not delete the untrashed copy.
v.EmptyTrash()
@@
-956,18
+979,18
@@
func testTrashEmptyTrashUntrash(t TB, factory TestableVolumeFactory) {
// untrash the block whose deadline is "C".
v.PutRaw(TestHash, TestBlock)
// untrash the block whose deadline is "C".
v.PutRaw(TestHash, TestBlock)
- v.TouchWithDate(TestHash, time.Now().Add(-2*
blobSignatureTTL
))
+ v.TouchWithDate(TestHash, time.Now().Add(-2*
theConfig.BlobSignatureTTL.Duration()
))
- t
rashLifetime = time.Nanosecond
+ t
heConfig.TrashLifetime.Set("1ns")
err = v.Trash(TestHash)
if err != nil {
t.Fatal(err)
}
v.PutRaw(TestHash, TestBlock)
err = v.Trash(TestHash)
if err != nil {
t.Fatal(err)
}
v.PutRaw(TestHash, TestBlock)
- v.TouchWithDate(TestHash, time.Now().Add(-2*
blobSignatureTTL
))
+ v.TouchWithDate(TestHash, time.Now().Add(-2*
theConfig.BlobSignatureTTL.Duration()
))
- t
rashLifetime = time.Hour
+ t
heConfig.TrashLifetime.Set("1h")
err = v.Trash(TestHash)
if err != nil {
t.Fatal(err)
err = v.Trash(TestHash)
if err != nil {
t.Fatal(err)