X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/7e5b8ba9e260669bc6fd85c201c4f771bceaa1b0..7bedb6e68dc97a4e081217c9a8901c31b7f9e13f:/services/keepstore/volume_unix_test.go diff --git a/services/keepstore/volume_unix_test.go b/services/keepstore/volume_unix_test.go index 6bafa7c1ca..ebb8421d9e 100644 --- a/services/keepstore/volume_unix_test.go +++ b/services/keepstore/volume_unix_test.go @@ -5,6 +5,9 @@ import ( "fmt" "io/ioutil" "os" + "regexp" + "sort" + "strings" "syscall" "testing" "time" @@ -74,6 +77,42 @@ func TestGetNotFound(t *testing.T) { } } +func TestIndexTo(t *testing.T) { + v := TempUnixVolume(t, false, false) + defer _teardown(v) + + _store(t, v, TEST_HASH, TEST_BLOCK) + _store(t, v, TEST_HASH_2, TEST_BLOCK_2) + _store(t, v, TEST_HASH_3, TEST_BLOCK_3) + + buf := new(bytes.Buffer) + v.IndexTo("", buf) + index_rows := strings.Split(string(buf.Bytes()), "\n") + sort.Strings(index_rows) + sorted_index := strings.Join(index_rows, "\n") + m, err := regexp.MatchString( + `^\n`+TEST_HASH+`\+\d+ \d+\n`+ + TEST_HASH_3+`\+\d+ \d+\n`+ + TEST_HASH_2+`\+\d+ \d+$`, + sorted_index) + if err != nil { + t.Error(err) + } else if !m { + t.Errorf("Got index %q for empty prefix", sorted_index) + } + + for _, prefix := range []string{"f", "f15", "f15ac"} { + buf = new(bytes.Buffer) + v.IndexTo(prefix, buf) + m, err := regexp.MatchString(`^`+TEST_HASH_2+`\+\d+ \d+\n$`, string(buf.Bytes())) + if err != nil { + t.Error(err) + } else if !m { + t.Errorf("Got index %q for prefix %q", string(buf.Bytes()), prefix) + } + } +} + func TestPut(t *testing.T) { v := TempUnixVolume(t, false, false) defer _teardown(v) @@ -277,7 +316,7 @@ func TestPutSerialized(t *testing.T) { }(sem) // Wait for all goroutines to finish - for done := 0; done < 2; { + for done := 0; done < 3; { done += <-sem }