Avoid http client race in test case.
authorTom Clegg <tclegg@veritasgenetics.com>
Wed, 9 May 2018 17:11:55 +0000 (13:11 -0400)
committerTom Clegg <tclegg@veritasgenetics.com>
Wed, 9 May 2018 17:11:55 +0000 (13:11 -0400)
If we don't wait for Put() to return before returning from the test
case, CloseIdleConnections can cause Put() to fail, and the resulting
call to t.Error() panics the testing package.

"errType *url.Error, err Put
http://fakeaccountname.blob.127.0.0.1:42861/fakecontainername/e4d909c290d0fb1ca068ffaddf22cbd0:
net/http: HTTP/1.x transport connection broken: http:
CloseIdleConnections called"

"panic: Fail in goroutine after TestAzureBlobVolumeCreateBlobRace has completed"

No issue #

Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tclegg@veritasgenetics.com>

services/keepstore/azure_blob_volume_test.go

index 60a7911768f009ef6209292d6c1e04b6cccbe6e7..1cb6dc380d0a24a002072b1a7465ef640882dd6c 100644 (file)
@@ -536,9 +536,13 @@ func TestAzureBlobVolumeCreateBlobRace(t *testing.T) {
        azureWriteRaceInterval = time.Second
        azureWriteRacePollTime = time.Millisecond
 
-       allDone := make(chan struct{})
+       var wg sync.WaitGroup
+
        v.azHandler.race = make(chan chan struct{})
+
+       wg.Add(1)
        go func() {
+               defer wg.Done()
                err := v.Put(context.Background(), TestHash, TestBlock)
                if err != nil {
                        t.Error(err)
@@ -547,21 +551,22 @@ func TestAzureBlobVolumeCreateBlobRace(t *testing.T) {
        continuePut := make(chan struct{})
        // Wait for the stub's Put to create the empty blob
        v.azHandler.race <- continuePut
+       wg.Add(1)
        go func() {
+               defer wg.Done()
                buf := make([]byte, len(TestBlock))
                _, err := v.Get(context.Background(), TestHash, buf)
                if err != nil {
                        t.Error(err)
                }
-               close(allDone)
        }()
        // Wait for the stub's Get to get the empty blob
        close(v.azHandler.race)
        // Allow stub's Put to continue, so the real data is ready
        // when the volume's Get retries
        <-continuePut
-       // Wait for volume's Get to return the real data
-       <-allDone
+       // Wait for Get() and Put() to finish
+       wg.Wait()
 }
 
 func TestAzureBlobVolumeCreateBlobRaceDeadline(t *testing.T) {