7159: Omit non-Keep blobs from index
[arvados.git] / services / keepstore / azure_blob_volume_test.go
index 889a0260290020a786a01deb6c66ed7c6f204c85..24790c25d2956cf204fc2bf8cd4de3e9d6e61fa5 100644 (file)
@@ -1,6 +1,7 @@
 package main
 
 import (
+       "bytes"
        "encoding/base64"
        "encoding/xml"
        "flag"
@@ -338,6 +339,8 @@ func TestAzureBlobVolumeWithGeneric(t *testing.T) {
        http.DefaultTransport = &http.Transport{
                Dial: (&azStubDialer{}).Dial,
        }
+       azureWriteRaceInterval = time.Millisecond
+       azureWriteRacePollTime = time.Nanosecond
        DoGenericVolumeTests(t, func(t *testing.T) TestableVolume {
                return NewTestableAzureBlobVolume(t, false, azureStorageReplication)
        })
@@ -350,6 +353,8 @@ func TestReadonlyAzureBlobVolumeWithGeneric(t *testing.T) {
        http.DefaultTransport = &http.Transport{
                Dial: (&azStubDialer{}).Dial,
        }
+       azureWriteRaceInterval = time.Millisecond
+       azureWriteRacePollTime = time.Nanosecond
        DoGenericVolumeTests(t, func(t *testing.T) TestableVolume {
                return NewTestableAzureBlobVolume(t, true, azureStorageReplication)
        })
@@ -408,6 +413,56 @@ func TestAzureBlobVolumeCreateBlobRace(t *testing.T) {
        <-allDone
 }
 
+func TestAzureBlobVolumeCreateBlobRaceDeadline(t *testing.T) {
+       defer func(t http.RoundTripper) {
+               http.DefaultTransport = t
+       }(http.DefaultTransport)
+       http.DefaultTransport = &http.Transport{
+               Dial: (&azStubDialer{}).Dial,
+       }
+
+       v := NewTestableAzureBlobVolume(t, false, 3)
+       defer v.Teardown()
+
+       azureWriteRaceInterval = 2 * time.Second
+       azureWriteRacePollTime = 5 * time.Millisecond
+
+       v.PutRaw(TestHash, nil)
+
+       buf := new(bytes.Buffer)
+       v.IndexTo("", buf)
+       if buf.Len() != 0 {
+               t.Errorf("Index %+q should be empty", buf.Bytes())
+       }
+
+       v.TouchWithDate(TestHash, time.Now().Add(-1982 * time.Millisecond))
+
+       allDone := make(chan struct{})
+       go func() {
+               defer close(allDone)
+               buf, err := v.Get(TestHash)
+               if err != nil {
+                       t.Error(err)
+                       return
+               }
+               if len(buf) != 0 {
+                       t.Errorf("Got %+q, expected empty buf", buf)
+               }
+               bufs.Put(buf)
+       }()
+       select {
+       case <-allDone:
+       case <-time.After(time.Second):
+               t.Error("Get should have stopped waiting for race when block was 2s old")
+       }
+
+       buf.Reset()
+       v.IndexTo("", buf)
+       if !bytes.HasPrefix(buf.Bytes(), []byte(TestHash+"+0")) {
+               t.Errorf("Index %+q should have %+q", buf.Bytes(), TestHash+"+0")
+       }
+}
+
 func (v *TestableAzureBlobVolume) PutRaw(locator string, data []byte) {
        v.azHandler.PutRaw(v.containerName, locator, data)
 }