10467: Use context.Background() for tests and background processes.
authorTom Clegg <tom@curoverse.com>
Tue, 8 Nov 2016 19:07:46 +0000 (14:07 -0500)
committerTom Clegg <tom@curoverse.com>
Tue, 8 Nov 2016 19:07:46 +0000 (14:07 -0500)
services/keepstore/azure_blob_volume_test.go
services/keepstore/handler_test.go
services/keepstore/handlers_with_generic_volume_test.go
services/keepstore/keepstore_test.go
services/keepstore/pull_worker.go
services/keepstore/s3_volume_test.go
services/keepstore/trash_worker_test.go
services/keepstore/volume_generic_test.go
services/keepstore/volume_unix_test.go

index 0123bfba5de4457aa9d1d8353e5363477b517fed..d636a5ee86887806372a14e2f291e5c4f2c11b33 100644 (file)
@@ -455,12 +455,12 @@ func TestAzureBlobVolumeRangeFenceposts(t *testing.T) {
                        data[i] = byte((i + 7) & 0xff)
                }
                hash := fmt.Sprintf("%x", md5.Sum(data))
-               err := v.Put(context.TODO(), hash, data)
+               err := v.Put(context.Background(), hash, data)
                if err != nil {
                        t.Error(err)
                }
                gotData := make([]byte, len(data))
-               gotLen, err := v.Get(context.TODO(), hash, gotData)
+               gotLen, err := v.Get(context.Background(), hash, gotData)
                if err != nil {
                        t.Error(err)
                }
@@ -501,7 +501,7 @@ func TestAzureBlobVolumeCreateBlobRace(t *testing.T) {
        allDone := make(chan struct{})
        v.azHandler.race = make(chan chan struct{})
        go func() {
-               err := v.Put(context.TODO(), TestHash, TestBlock)
+               err := v.Put(context.Background(), TestHash, TestBlock)
                if err != nil {
                        t.Error(err)
                }
@@ -511,7 +511,7 @@ func TestAzureBlobVolumeCreateBlobRace(t *testing.T) {
        v.azHandler.race <- continuePut
        go func() {
                buf := make([]byte, len(TestBlock))
-               _, err := v.Get(context.TODO(), TestHash, buf)
+               _, err := v.Get(context.Background(), TestHash, buf)
                if err != nil {
                        t.Error(err)
                }
@@ -554,7 +554,7 @@ func TestAzureBlobVolumeCreateBlobRaceDeadline(t *testing.T) {
        go func() {
                defer close(allDone)
                buf := make([]byte, BlockSize)
-               n, err := v.Get(context.TODO(), TestHash, buf)
+               n, err := v.Get(context.Background(), TestHash, buf)
                if err != nil {
                        t.Error(err)
                        return
index 1821383c852517ee17cb84fec7977eb4182b31b6..9708b4e6be32f96645d500dfcd4319972f213d47 100644 (file)
@@ -49,7 +49,7 @@ func TestGetHandler(t *testing.T) {
        defer KeepVM.Close()
 
        vols := KeepVM.AllWritable()
-       if err := vols[0].Put(context.TODO(), TestHash, TestBlock); err != nil {
+       if err := vols[0].Put(context.Background(), TestHash, TestBlock); err != nil {
                t.Error(err)
        }
 
@@ -289,10 +289,10 @@ func TestIndexHandler(t *testing.T) {
        defer KeepVM.Close()
 
        vols := KeepVM.AllWritable()
-       vols[0].Put(context.TODO(), TestHash, TestBlock)
-       vols[1].Put(context.TODO(), TestHash2, TestBlock2)
-       vols[0].Put(context.TODO(), TestHash+".meta", []byte("metadata"))
-       vols[1].Put(context.TODO(), TestHash2+".meta", []byte("metadata"))
+       vols[0].Put(context.Background(), TestHash, TestBlock)
+       vols[1].Put(context.Background(), TestHash2, TestBlock2)
+       vols[0].Put(context.Background(), TestHash+".meta", []byte("metadata"))
+       vols[1].Put(context.Background(), TestHash2+".meta", []byte("metadata"))
 
        theConfig.systemAuthToken = "DATA MANAGER TOKEN"
 
@@ -478,7 +478,7 @@ func TestDeleteHandler(t *testing.T) {
        defer KeepVM.Close()
 
        vols := KeepVM.AllWritable()
-       vols[0].Put(context.TODO(), TestHash, TestBlock)
+       vols[0].Put(context.Background(), TestHash, TestBlock)
 
        // Explicitly set the BlobSignatureTTL to 0 for these
        // tests, to ensure the MockVolume deletes the blocks
@@ -565,7 +565,7 @@ func TestDeleteHandler(t *testing.T) {
        }
        // Confirm the block has been deleted
        buf := make([]byte, BlockSize)
-       _, err := vols[0].Get(context.TODO(), TestHash, buf)
+       _, err := vols[0].Get(context.Background(), TestHash, buf)
        var blockDeleted = os.IsNotExist(err)
        if !blockDeleted {
                t.Error("superuserExistingBlockReq: block not deleted")
@@ -573,7 +573,7 @@ func TestDeleteHandler(t *testing.T) {
 
        // A DELETE request on a block newer than BlobSignatureTTL
        // should return success but leave the block on the volume.
-       vols[0].Put(context.TODO(), TestHash, TestBlock)
+       vols[0].Put(context.Background(), TestHash, TestBlock)
        theConfig.BlobSignatureTTL = arvados.Duration(time.Hour)
 
        response = IssueRequest(superuserExistingBlockReq)
@@ -589,7 +589,7 @@ func TestDeleteHandler(t *testing.T) {
                        expectedDc, responseDc)
        }
        // Confirm the block has NOT been deleted.
-       _, err = vols[0].Get(context.TODO(), TestHash, buf)
+       _, err = vols[0].Get(context.Background(), TestHash, buf)
        if err != nil {
                t.Errorf("testing delete on new block: %s\n", err)
        }
@@ -941,7 +941,7 @@ func TestGetHandlerClientDisconnect(t *testing.T) {
        KeepVM = MakeTestVolumeManager(2)
        defer KeepVM.Close()
 
-       if err := KeepVM.AllWritable()[0].Put(context.TODO(), TestHash, TestBlock); err != nil {
+       if err := KeepVM.AllWritable()[0].Put(context.Background(), TestHash, TestBlock); err != nil {
                t.Error(err)
        }
 
@@ -986,7 +986,7 @@ func TestGetHandlerNoBufferLeak(t *testing.T) {
        defer KeepVM.Close()
 
        vols := KeepVM.AllWritable()
-       if err := vols[0].Put(context.TODO(), TestHash, TestBlock); err != nil {
+       if err := vols[0].Put(context.Background(), TestHash, TestBlock); err != nil {
                t.Error(err)
        }
 
@@ -1041,7 +1041,7 @@ func TestUntrashHandler(t *testing.T) {
        KeepVM = MakeTestVolumeManager(2)
        defer KeepVM.Close()
        vols := KeepVM.AllWritable()
-       vols[0].Put(context.TODO(), TestHash, TestBlock)
+       vols[0].Put(context.Background(), TestHash, TestBlock)
 
        theConfig.systemAuthToken = "DATA MANAGER TOKEN"
 
index 2c273aec383f1f4fb3085ab9cf9cc76aa2f2bf19..181e651d3b4bbef40fa146b8fe06e6b93c206b05 100644 (file)
@@ -47,7 +47,7 @@ func testGetBlock(t TB, factory TestableVolumeManagerFactory, testHash string, t
 
        // Get should pass
        buf := make([]byte, len(testBlock))
-       n, err := GetBlock(context.TODO(), testHash, buf, nil)
+       n, err := GetBlock(context.Background(), testHash, buf, nil)
        if err != nil {
                t.Fatalf("Error while getting block %s", err)
        }
@@ -67,7 +67,7 @@ func testPutRawBadDataGetBlock(t TB, factory TestableVolumeManagerFactory,
 
        // Get should fail
        buf := make([]byte, BlockSize)
-       size, err := GetBlock(context.TODO(), testHash, buf, nil)
+       size, err := GetBlock(context.Background(), testHash, buf, nil)
        if err == nil {
                t.Fatalf("Got %+q, expected error while getting corrupt block %v", buf[:size], testHash)
        }
@@ -78,18 +78,18 @@ func testPutBlock(t TB, factory TestableVolumeManagerFactory, testHash string, t
        setupHandlersWithGenericVolumeTest(t, factory)
 
        // PutBlock
-       if _, err := PutBlock(context.TODO(), testBlock, testHash); err != nil {
+       if _, err := PutBlock(context.Background(), testBlock, testHash); err != nil {
                t.Fatalf("Error during PutBlock: %s", err)
        }
 
        // Check that PutBlock succeeds again even after CompareAndTouch
-       if _, err := PutBlock(context.TODO(), testBlock, testHash); err != nil {
+       if _, err := PutBlock(context.Background(), testBlock, testHash); err != nil {
                t.Fatalf("Error during PutBlock: %s", err)
        }
 
        // Check that PutBlock stored the data as expected
        buf := make([]byte, BlockSize)
-       size, err := GetBlock(context.TODO(), testHash, buf, nil)
+       size, err := GetBlock(context.Background(), testHash, buf, nil)
        if err != nil {
                t.Fatalf("Error during GetBlock for %q: %s", testHash, err)
        } else if bytes.Compare(buf[:size], testBlock) != 0 {
@@ -107,14 +107,14 @@ func testPutBlockCorrupt(t TB, factory TestableVolumeManagerFactory,
        testableVolumes[1].PutRaw(testHash, badData)
 
        // Check that PutBlock with good data succeeds
-       if _, err := PutBlock(context.TODO(), testBlock, testHash); err != nil {
+       if _, err := PutBlock(context.Background(), testBlock, testHash); err != nil {
                t.Fatalf("Error during PutBlock for %q: %s", testHash, err)
        }
 
        // Put succeeded and overwrote the badData in one volume,
        // and Get should return the testBlock now, ignoring the bad data.
        buf := make([]byte, BlockSize)
-       size, err := GetBlock(context.TODO(), testHash, buf, nil)
+       size, err := GetBlock(context.Background(), testHash, buf, nil)
        if err != nil {
                t.Fatalf("Error during GetBlock for %q: %s", testHash, err)
        } else if bytes.Compare(buf[:size], testBlock) != 0 {
index a2e804483766b0391c67345ac9f2653af4881d2f..e1d1dc5cb3cf2eb6ed3bf0b1da0a18b154f03328 100644 (file)
@@ -62,13 +62,13 @@ func TestGetBlock(t *testing.T) {
        defer KeepVM.Close()
 
        vols := KeepVM.AllReadable()
-       if err := vols[1].Put(context.TODO(), TestHash, TestBlock); err != nil {
+       if err := vols[1].Put(context.Background(), TestHash, TestBlock); err != nil {
                t.Error(err)
        }
 
        // Check that GetBlock returns success.
        buf := make([]byte, BlockSize)
-       size, err := GetBlock(context.TODO(), TestHash, buf, nil)
+       size, err := GetBlock(context.Background(), TestHash, buf, nil)
        if err != nil {
                t.Errorf("GetBlock error: %s", err)
        }
@@ -89,7 +89,7 @@ func TestGetBlockMissing(t *testing.T) {
 
        // Check that GetBlock returns failure.
        buf := make([]byte, BlockSize)
-       size, err := GetBlock(context.TODO(), TestHash, buf, nil)
+       size, err := GetBlock(context.Background(), TestHash, buf, nil)
        if err != NotFoundError {
                t.Errorf("Expected NotFoundError, got %v, err %v", buf[:size], err)
        }
@@ -107,11 +107,11 @@ func TestGetBlockCorrupt(t *testing.T) {
        defer KeepVM.Close()
 
        vols := KeepVM.AllReadable()
-       vols[0].Put(context.TODO(), TestHash, BadBlock)
+       vols[0].Put(context.Background(), TestHash, BadBlock)
 
        // Check that GetBlock returns failure.
        buf := make([]byte, BlockSize)
-       size, err := GetBlock(context.TODO(), TestHash, buf, nil)
+       size, err := GetBlock(context.Background(), TestHash, buf, nil)
        if err != DiskHashError {
                t.Errorf("Expected DiskHashError, got %v (buf: %v)", err, buf[:size])
        }
@@ -132,13 +132,13 @@ func TestPutBlockOK(t *testing.T) {
        defer KeepVM.Close()
 
        // Check that PutBlock stores the data as expected.
-       if n, err := PutBlock(context.TODO(), TestBlock, TestHash); err != nil || n < 1 {
+       if n, err := PutBlock(context.Background(), TestBlock, TestHash); err != nil || n < 1 {
                t.Fatalf("PutBlock: n %d err %v", n, err)
        }
 
        vols := KeepVM.AllReadable()
        buf := make([]byte, BlockSize)
-       n, err := vols[1].Get(context.TODO(), TestHash, buf)
+       n, err := vols[1].Get(context.Background(), TestHash, buf)
        if err != nil {
                t.Fatalf("Volume #0 Get returned error: %v", err)
        }
@@ -163,12 +163,12 @@ func TestPutBlockOneVol(t *testing.T) {
        vols[0].(*MockVolume).Bad = true
 
        // Check that PutBlock stores the data as expected.
-       if n, err := PutBlock(context.TODO(), TestBlock, TestHash); err != nil || n < 1 {
+       if n, err := PutBlock(context.Background(), TestBlock, TestHash); err != nil || n < 1 {
                t.Fatalf("PutBlock: n %d err %v", n, err)
        }
 
        buf := make([]byte, BlockSize)
-       size, err := GetBlock(context.TODO(), TestHash, buf, nil)
+       size, err := GetBlock(context.Background(), TestHash, buf, nil)
        if err != nil {
                t.Fatalf("GetBlock: %v", err)
        }
@@ -191,12 +191,12 @@ func TestPutBlockMD5Fail(t *testing.T) {
 
        // Check that PutBlock returns the expected error when the hash does
        // not match the block.
-       if _, err := PutBlock(context.TODO(), BadBlock, TestHash); err != RequestHashError {
+       if _, err := PutBlock(context.Background(), BadBlock, TestHash); err != RequestHashError {
                t.Errorf("Expected RequestHashError, got %v", err)
        }
 
        // Confirm that GetBlock fails to return anything.
-       if result, err := GetBlock(context.TODO(), TestHash, make([]byte, BlockSize), nil); err != NotFoundError {
+       if result, err := GetBlock(context.Background(), TestHash, make([]byte, BlockSize), nil); err != NotFoundError {
                t.Errorf("GetBlock succeeded after a corrupt block store (result = %s, err = %v)",
                        string(result), err)
        }
@@ -215,14 +215,14 @@ func TestPutBlockCorrupt(t *testing.T) {
 
        // Store a corrupted block under TestHash.
        vols := KeepVM.AllWritable()
-       vols[0].Put(context.TODO(), TestHash, BadBlock)
-       if n, err := PutBlock(context.TODO(), TestBlock, TestHash); err != nil || n < 1 {
+       vols[0].Put(context.Background(), TestHash, BadBlock)
+       if n, err := PutBlock(context.Background(), TestBlock, TestHash); err != nil || n < 1 {
                t.Errorf("PutBlock: n %d err %v", n, err)
        }
 
        // The block on disk should now match TestBlock.
        buf := make([]byte, BlockSize)
-       if size, err := GetBlock(context.TODO(), TestHash, buf, nil); err != nil {
+       if size, err := GetBlock(context.Background(), TestHash, buf, nil); err != nil {
                t.Errorf("GetBlock: %v", err)
        } else if bytes.Compare(buf[:size], TestBlock) != 0 {
                t.Errorf("Got %+q, expected %+q", buf[:size], TestBlock)
@@ -247,10 +247,10 @@ func TestPutBlockCollision(t *testing.T) {
 
        // Store one block, then attempt to store the other. Confirm that
        // PutBlock reported a CollisionError.
-       if _, err := PutBlock(context.TODO(), b1, locator); err != nil {
+       if _, err := PutBlock(context.Background(), b1, locator); err != nil {
                t.Error(err)
        }
-       if _, err := PutBlock(context.TODO(), b2, locator); err == nil {
+       if _, err := PutBlock(context.Background(), b2, locator); err == nil {
                t.Error("PutBlock did not report a collision")
        } else if err != CollisionError {
                t.Errorf("PutBlock returned %v", err)
@@ -272,7 +272,7 @@ func TestPutBlockTouchFails(t *testing.T) {
        // Store a block and then make the underlying volume bad,
        // so a subsequent attempt to update the file timestamp
        // will fail.
-       vols[0].Put(context.TODO(), TestHash, BadBlock)
+       vols[0].Put(context.Background(), TestHash, BadBlock)
        oldMtime, err := vols[0].Mtime(TestHash)
        if err != nil {
                t.Fatalf("vols[0].Mtime(%s): %s\n", TestHash, err)
@@ -281,7 +281,7 @@ func TestPutBlockTouchFails(t *testing.T) {
        // vols[0].Touch will fail on the next call, so the volume
        // manager will store a copy on vols[1] instead.
        vols[0].(*MockVolume).Touchable = false
-       if n, err := PutBlock(context.TODO(), TestBlock, TestHash); err != nil || n < 1 {
+       if n, err := PutBlock(context.Background(), TestBlock, TestHash); err != nil || n < 1 {
                t.Fatalf("PutBlock: n %d err %v", n, err)
        }
        vols[0].(*MockVolume).Touchable = true
@@ -297,7 +297,7 @@ func TestPutBlockTouchFails(t *testing.T) {
                        oldMtime, newMtime)
        }
        buf := make([]byte, BlockSize)
-       n, err := vols[1].Get(context.TODO(), TestHash, buf)
+       n, err := vols[1].Get(context.Background(), TestHash, buf)
        if err != nil {
                t.Fatalf("vols[1]: %v", err)
        }
@@ -401,11 +401,11 @@ func TestIndex(t *testing.T) {
        defer KeepVM.Close()
 
        vols := KeepVM.AllReadable()
-       vols[0].Put(context.TODO(), TestHash, TestBlock)
-       vols[1].Put(context.TODO(), TestHash2, TestBlock2)
-       vols[0].Put(context.TODO(), TestHash3, TestBlock3)
-       vols[0].Put(context.TODO(), TestHash+".meta", []byte("metadata"))
-       vols[1].Put(context.TODO(), TestHash2+".meta", []byte("metadata"))
+       vols[0].Put(context.Background(), TestHash, TestBlock)
+       vols[1].Put(context.Background(), TestHash2, TestBlock2)
+       vols[0].Put(context.Background(), TestHash3, TestBlock3)
+       vols[0].Put(context.Background(), TestHash+".meta", []byte("metadata"))
+       vols[1].Put(context.Background(), TestHash2+".meta", []byte("metadata"))
 
        buf := new(bytes.Buffer)
        vols[0].IndexTo("", buf)
index e42b6e4b89230cdbe4a40a99fc803044febe421c..12860bb662d91a1e31191fed2bccace97bc2ac30 100644 (file)
@@ -95,6 +95,6 @@ func GenerateRandomAPIToken() string {
 
 // Put block
 var PutContent = func(content []byte, locator string) (err error) {
-       _, err = PutBlock(context.TODO(), content, locator)
+       _, err = PutBlock(context.Background(), content, locator)
        return
 }
index b720777f767b090960d5a305068e6655964d7ed7..63b186220c30a562e900722d63d38be50bde05d6 100644 (file)
@@ -224,7 +224,7 @@ func (s *StubbedS3Suite) TestBackendStates(c *check.C) {
                // Check canGet
                loc, blk := setupScenario()
                buf := make([]byte, len(blk))
-               _, err := v.Get(context.TODO(), loc, buf)
+               _, err := v.Get(context.Background(), loc, buf)
                c.Check(err == nil, check.Equals, scenario.canGet)
                if err != nil {
                        c.Check(os.IsNotExist(err), check.Equals, true)
@@ -234,7 +234,7 @@ func (s *StubbedS3Suite) TestBackendStates(c *check.C) {
                loc, blk = setupScenario()
                err = v.Trash(loc)
                c.Check(err == nil, check.Equals, scenario.canTrash)
-               _, err = v.Get(context.TODO(), loc, buf)
+               _, err = v.Get(context.Background(), loc, buf)
                c.Check(err == nil, check.Equals, scenario.canGetAfterTrash)
                if err != nil {
                        c.Check(os.IsNotExist(err), check.Equals, true)
@@ -249,7 +249,7 @@ func (s *StubbedS3Suite) TestBackendStates(c *check.C) {
                        // should be able to Get after Untrash --
                        // regardless of timestamps, errors, race
                        // conditions, etc.
-                       _, err = v.Get(context.TODO(), loc, buf)
+                       _, err = v.Get(context.Background(), loc, buf)
                        c.Check(err, check.IsNil)
                }
 
@@ -270,7 +270,7 @@ func (s *StubbedS3Suite) TestBackendStates(c *check.C) {
                // Check for current Mtime after Put (applies to all
                // scenarios)
                loc, blk = setupScenario()
-               err = v.Put(context.TODO(), loc, blk)
+               err = v.Put(context.Background(), loc, blk)
                c.Check(err, check.IsNil)
                t, err := v.Mtime(loc)
                c.Check(err, check.IsNil)
index 857f86a790447d04e489871d5a1517fa53f4f251..04b034a97976980c5ce66d59c361b44936dabbca 100644 (file)
@@ -220,15 +220,15 @@ func performTrashWorkerTest(testData TrashWorkerTestData, t *testing.T) {
        // Put test content
        vols := KeepVM.AllWritable()
        if testData.CreateData {
-               vols[0].Put(context.TODO(), testData.Locator1, testData.Block1)
-               vols[0].Put(context.TODO(), testData.Locator1+".meta", []byte("metadata"))
+               vols[0].Put(context.Background(), testData.Locator1, testData.Block1)
+               vols[0].Put(context.Background(), testData.Locator1+".meta", []byte("metadata"))
 
                if testData.CreateInVolume1 {
-                       vols[0].Put(context.TODO(), testData.Locator2, testData.Block2)
-                       vols[0].Put(context.TODO(), testData.Locator2+".meta", []byte("metadata"))
+                       vols[0].Put(context.Background(), testData.Locator2, testData.Block2)
+                       vols[0].Put(context.Background(), testData.Locator2+".meta", []byte("metadata"))
                } else {
-                       vols[1].Put(context.TODO(), testData.Locator2, testData.Block2)
-                       vols[1].Put(context.TODO(), testData.Locator2+".meta", []byte("metadata"))
+                       vols[1].Put(context.Background(), testData.Locator2, testData.Block2)
+                       vols[1].Put(context.Background(), testData.Locator2+".meta", []byte("metadata"))
                }
        }
 
@@ -292,7 +292,7 @@ func performTrashWorkerTest(testData TrashWorkerTestData, t *testing.T) {
 
        // Verify Locator1 to be un/deleted as expected
        buf := make([]byte, BlockSize)
-       size, err := GetBlock(context.TODO(), testData.Locator1, buf, nil)
+       size, err := GetBlock(context.Background(), testData.Locator1, buf, nil)
        if testData.ExpectLocator1 {
                if size == 0 || err != nil {
                        t.Errorf("Expected Locator1 to be still present: %s", testData.Locator1)
@@ -305,7 +305,7 @@ func performTrashWorkerTest(testData TrashWorkerTestData, t *testing.T) {
 
        // Verify Locator2 to be un/deleted as expected
        if testData.Locator1 != testData.Locator2 {
-               size, err = GetBlock(context.TODO(), testData.Locator2, buf, nil)
+               size, err = GetBlock(context.Background(), testData.Locator2, buf, nil)
                if testData.ExpectLocator2 {
                        if size == 0 || err != nil {
                                t.Errorf("Expected Locator2 to be still present: %s", testData.Locator2)
@@ -324,7 +324,7 @@ func performTrashWorkerTest(testData TrashWorkerTestData, t *testing.T) {
                locatorFoundIn := 0
                for _, volume := range KeepVM.AllReadable() {
                        buf := make([]byte, BlockSize)
-                       if _, err := volume.Get(context.TODO(), testData.Locator1, buf); err == nil {
+                       if _, err := volume.Get(context.Background(), testData.Locator1, buf); err == nil {
                                locatorFoundIn = locatorFoundIn + 1
                        }
                }
index d91092624ec6c0bb15ca78ecb50830429aa10297..7e72a8f246ee60410e7110417de3284ae4263ca3 100644 (file)
@@ -93,7 +93,7 @@ func testGet(t TB, factory TestableVolumeFactory) {
        v.PutRaw(TestHash, TestBlock)
 
        buf := make([]byte, BlockSize)
-       n, err := v.Get(context.TODO(), TestHash, buf)
+       n, err := v.Get(context.Background(), TestHash, buf)
        if err != nil {
                t.Fatal(err)
        }
@@ -110,7 +110,7 @@ func testGetNoSuchBlock(t TB, factory TestableVolumeFactory) {
        defer v.Teardown()
 
        buf := make([]byte, BlockSize)
-       if _, err := v.Get(context.TODO(), TestHash2, buf); err == nil {
+       if _, err := v.Get(context.Background(), TestHash2, buf); err == nil {
                t.Errorf("Expected error while getting non-existing block %v", TestHash2)
        }
 }
@@ -122,7 +122,7 @@ func testCompareNonexistent(t TB, factory TestableVolumeFactory) {
        v := factory(t)
        defer v.Teardown()
 
-       err := v.Compare(context.TODO(), TestHash, TestBlock)
+       err := v.Compare(context.Background(), TestHash, TestBlock)
        if err != os.ErrNotExist {
                t.Errorf("Got err %T %q, expected os.ErrNotExist", err, err)
        }
@@ -137,7 +137,7 @@ func testCompareSameContent(t TB, factory TestableVolumeFactory, testHash string
        v.PutRaw(testHash, testData)
 
        // Compare the block locator with same content
-       err := v.Compare(context.TODO(), testHash, testData)
+       err := v.Compare(context.Background(), testHash, testData)
        if err != nil {
                t.Errorf("Got err %q, expected nil", err)
        }
@@ -155,7 +155,7 @@ func testCompareWithCollision(t TB, factory TestableVolumeFactory, testHash stri
        v.PutRaw(testHash, testDataA)
 
        // Compare the block locator with different content; collision
-       err := v.Compare(context.TODO(), TestHash, testDataB)
+       err := v.Compare(context.Background(), TestHash, testDataB)
        if err == nil {
                t.Errorf("Got err nil, expected error due to collision")
        }
@@ -171,7 +171,7 @@ func testCompareWithCorruptStoredData(t TB, factory TestableVolumeFactory, testH
 
        v.PutRaw(TestHash, testDataB)
 
-       err := v.Compare(context.TODO(), testHash, testDataA)
+       err := v.Compare(context.Background(), testHash, testDataA)
        if err == nil || err == CollisionError {
                t.Errorf("Got err %+v, expected non-collision error", err)
        }
@@ -187,12 +187,12 @@ func testPutBlockWithSameContent(t TB, factory TestableVolumeFactory, testHash s
                return
        }
 
-       err := v.Put(context.TODO(), testHash, testData)
+       err := v.Put(context.Background(), testHash, testData)
        if err != nil {
                t.Errorf("Got err putting block %q: %q, expected nil", TestBlock, err)
        }
 
-       err = v.Put(context.TODO(), testHash, testData)
+       err = v.Put(context.Background(), testHash, testData)
        if err != nil {
                t.Errorf("Got err putting block second time %q: %q, expected nil", TestBlock, err)
        }
@@ -210,9 +210,9 @@ func testPutBlockWithDifferentContent(t TB, factory TestableVolumeFactory, testH
 
        v.PutRaw(testHash, testDataA)
 
-       putErr := v.Put(context.TODO(), testHash, testDataB)
+       putErr := v.Put(context.Background(), testHash, testDataB)
        buf := make([]byte, BlockSize)
-       n, getErr := v.Get(context.TODO(), testHash, buf)
+       n, getErr := v.Get(context.Background(), testHash, buf)
        if putErr == nil {
                // Put must not return a nil error unless it has
                // overwritten the existing data.
@@ -239,23 +239,23 @@ func testPutMultipleBlocks(t TB, factory TestableVolumeFactory) {
                return
        }
 
-       err := v.Put(context.TODO(), TestHash, TestBlock)
+       err := v.Put(context.Background(), TestHash, TestBlock)
        if err != nil {
                t.Errorf("Got err putting block %q: %q, expected nil", TestBlock, err)
        }
 
-       err = v.Put(context.TODO(), TestHash2, TestBlock2)
+       err = v.Put(context.Background(), TestHash2, TestBlock2)
        if err != nil {
                t.Errorf("Got err putting block %q: %q, expected nil", TestBlock2, err)
        }
 
-       err = v.Put(context.TODO(), TestHash3, TestBlock3)
+       err = v.Put(context.Background(), TestHash3, TestBlock3)
        if err != nil {
                t.Errorf("Got err putting block %q: %q, expected nil", TestBlock3, err)
        }
 
        data := make([]byte, BlockSize)
-       n, err := v.Get(context.TODO(), TestHash, data)
+       n, err := v.Get(context.Background(), TestHash, data)
        if err != nil {
                t.Error(err)
        } else {
@@ -264,7 +264,7 @@ func testPutMultipleBlocks(t TB, factory TestableVolumeFactory) {
                }
        }
 
-       n, err = v.Get(context.TODO(), TestHash2, data)
+       n, err = v.Get(context.Background(), TestHash2, data)
        if err != nil {
                t.Error(err)
        } else {
@@ -273,7 +273,7 @@ func testPutMultipleBlocks(t TB, factory TestableVolumeFactory) {
                }
        }
 
-       n, err = v.Get(context.TODO(), TestHash3, data)
+       n, err = v.Get(context.Background(), TestHash3, data)
        if err != nil {
                t.Error(err)
        } else {
@@ -295,7 +295,7 @@ func testPutAndTouch(t TB, factory TestableVolumeFactory) {
                return
        }
 
-       if err := v.Put(context.TODO(), TestHash, TestBlock); err != nil {
+       if err := v.Put(context.Background(), TestHash, TestBlock); err != nil {
                t.Error(err)
        }
 
@@ -315,7 +315,7 @@ func testPutAndTouch(t TB, factory TestableVolumeFactory) {
        }
 
        // Write the same block again.
-       if err := v.Put(context.TODO(), TestHash, TestBlock); err != nil {
+       if err := v.Put(context.Background(), TestHash, TestBlock); err != nil {
                t.Error(err)
        }
 
@@ -438,13 +438,13 @@ func testDeleteNewBlock(t TB, factory TestableVolumeFactory) {
                return
        }
 
-       v.Put(context.TODO(), TestHash, TestBlock)
+       v.Put(context.Background(), TestHash, TestBlock)
 
        if err := v.Trash(TestHash); err != nil {
                t.Error(err)
        }
        data := make([]byte, BlockSize)
-       n, err := v.Get(context.TODO(), TestHash, data)
+       n, err := v.Get(context.Background(), TestHash, data)
        if err != nil {
                t.Error(err)
        } else if bytes.Compare(data[:n], TestBlock) != 0 {
@@ -464,14 +464,14 @@ func testDeleteOldBlock(t TB, factory TestableVolumeFactory) {
                return
        }
 
-       v.Put(context.TODO(), TestHash, TestBlock)
+       v.Put(context.Background(), TestHash, TestBlock)
        v.TouchWithDate(TestHash, time.Now().Add(-2*theConfig.BlobSignatureTTL.Duration()))
 
        if err := v.Trash(TestHash); err != nil {
                t.Error(err)
        }
        data := make([]byte, BlockSize)
-       if _, err := v.Get(context.TODO(), TestHash, data); err == nil || !os.IsNotExist(err) {
+       if _, err := v.Get(context.Background(), TestHash, data); err == nil || !os.IsNotExist(err) {
                t.Errorf("os.IsNotExist(%v) should have been true", err)
        }
 
@@ -480,7 +480,7 @@ func testDeleteOldBlock(t TB, factory TestableVolumeFactory) {
                t.Fatalf("os.IsNotExist(%v) should have been true", err)
        }
 
-       err = v.Compare(context.TODO(), TestHash, TestBlock)
+       err = v.Compare(context.Background(), TestHash, TestBlock)
        if err == nil || !os.IsNotExist(err) {
                t.Fatalf("os.IsNotExist(%v) should have been true", err)
        }
@@ -554,17 +554,17 @@ func testUpdateReadOnly(t TB, factory TestableVolumeFactory) {
        buf := make([]byte, BlockSize)
 
        // Get from read-only volume should succeed
-       _, err := v.Get(context.TODO(), TestHash, buf)
+       _, err := v.Get(context.Background(), TestHash, buf)
        if err != nil {
                t.Errorf("got err %v, expected nil", err)
        }
 
        // Put a new block to read-only volume should result in error
-       err = v.Put(context.TODO(), TestHash2, TestBlock2)
+       err = v.Put(context.Background(), TestHash2, TestBlock2)
        if err == nil {
                t.Errorf("Expected error when putting block in a read-only volume")
        }
-       _, err = v.Get(context.TODO(), TestHash2, buf)
+       _, err = v.Get(context.Background(), TestHash2, buf)
        if err == nil {
                t.Errorf("Expected error when getting block whose put in read-only volume failed")
        }
@@ -582,7 +582,7 @@ func testUpdateReadOnly(t TB, factory TestableVolumeFactory) {
        }
 
        // Overwriting an existing block in read-only volume should result in error
-       err = v.Put(context.TODO(), TestHash, TestBlock)
+       err = v.Put(context.Background(), TestHash, TestBlock)
        if err == nil {
                t.Errorf("Expected error when putting block in a read-only volume")
        }
@@ -601,7 +601,7 @@ func testGetConcurrent(t TB, factory TestableVolumeFactory) {
        sem := make(chan int)
        go func() {
                buf := make([]byte, BlockSize)
-               n, err := v.Get(context.TODO(), TestHash, buf)
+               n, err := v.Get(context.Background(), TestHash, buf)
                if err != nil {
                        t.Errorf("err1: %v", err)
                }
@@ -613,7 +613,7 @@ func testGetConcurrent(t TB, factory TestableVolumeFactory) {
 
        go func() {
                buf := make([]byte, BlockSize)
-               n, err := v.Get(context.TODO(), TestHash2, buf)
+               n, err := v.Get(context.Background(), TestHash2, buf)
                if err != nil {
                        t.Errorf("err2: %v", err)
                }
@@ -625,7 +625,7 @@ func testGetConcurrent(t TB, factory TestableVolumeFactory) {
 
        go func() {
                buf := make([]byte, BlockSize)
-               n, err := v.Get(context.TODO(), TestHash3, buf)
+               n, err := v.Get(context.Background(), TestHash3, buf)
                if err != nil {
                        t.Errorf("err3: %v", err)
                }
@@ -653,7 +653,7 @@ func testPutConcurrent(t TB, factory TestableVolumeFactory) {
 
        sem := make(chan int)
        go func(sem chan int) {
-               err := v.Put(context.TODO(), TestHash, TestBlock)
+               err := v.Put(context.Background(), TestHash, TestBlock)
                if err != nil {
                        t.Errorf("err1: %v", err)
                }
@@ -661,7 +661,7 @@ func testPutConcurrent(t TB, factory TestableVolumeFactory) {
        }(sem)
 
        go func(sem chan int) {
-               err := v.Put(context.TODO(), TestHash2, TestBlock2)
+               err := v.Put(context.Background(), TestHash2, TestBlock2)
                if err != nil {
                        t.Errorf("err2: %v", err)
                }
@@ -669,7 +669,7 @@ func testPutConcurrent(t TB, factory TestableVolumeFactory) {
        }(sem)
 
        go func(sem chan int) {
-               err := v.Put(context.TODO(), TestHash3, TestBlock3)
+               err := v.Put(context.Background(), TestHash3, TestBlock3)
                if err != nil {
                        t.Errorf("err3: %v", err)
                }
@@ -683,7 +683,7 @@ func testPutConcurrent(t TB, factory TestableVolumeFactory) {
 
        // Double check that we actually wrote the blocks we expected to write.
        buf := make([]byte, BlockSize)
-       n, err := v.Get(context.TODO(), TestHash, buf)
+       n, err := v.Get(context.Background(), TestHash, buf)
        if err != nil {
                t.Errorf("Get #1: %v", err)
        }
@@ -691,7 +691,7 @@ func testPutConcurrent(t TB, factory TestableVolumeFactory) {
                t.Errorf("Get #1: expected %s, got %s", string(TestBlock), string(buf[:n]))
        }
 
-       n, err = v.Get(context.TODO(), TestHash2, buf)
+       n, err = v.Get(context.Background(), TestHash2, buf)
        if err != nil {
                t.Errorf("Get #2: %v", err)
        }
@@ -699,7 +699,7 @@ func testPutConcurrent(t TB, factory TestableVolumeFactory) {
                t.Errorf("Get #2: expected %s, got %s", string(TestBlock2), string(buf[:n]))
        }
 
-       n, err = v.Get(context.TODO(), TestHash3, buf)
+       n, err = v.Get(context.Background(), TestHash3, buf)
        if err != nil {
                t.Errorf("Get #3: %v", err)
        }
@@ -721,12 +721,12 @@ func testPutFullBlock(t TB, factory TestableVolumeFactory) {
        wdata[0] = 'a'
        wdata[BlockSize-1] = 'z'
        hash := fmt.Sprintf("%x", md5.Sum(wdata))
-       err := v.Put(context.TODO(), hash, wdata)
+       err := v.Put(context.Background(), hash, wdata)
        if err != nil {
                t.Fatal(err)
        }
        buf := make([]byte, BlockSize)
-       n, err := v.Get(context.TODO(), hash, buf)
+       n, err := v.Get(context.Background(), hash, buf)
        if err != nil {
                t.Error(err)
        }
@@ -753,7 +753,7 @@ func testTrashUntrash(t TB, factory TestableVolumeFactory) {
        v.TouchWithDate(TestHash, time.Now().Add(-2*theConfig.BlobSignatureTTL.Duration()))
 
        buf := make([]byte, BlockSize)
-       n, err := v.Get(context.TODO(), TestHash, buf)
+       n, err := v.Get(context.Background(), TestHash, buf)
        if err != nil {
                t.Fatal(err)
        }
@@ -772,7 +772,7 @@ func testTrashUntrash(t TB, factory TestableVolumeFactory) {
                        t.Fatal(err)
                }
        } else {
-               _, err = v.Get(context.TODO(), TestHash, buf)
+               _, err = v.Get(context.Background(), TestHash, buf)
                if err == nil || !os.IsNotExist(err) {
                        t.Errorf("os.IsNotExist(%v) should have been true", err)
                }
@@ -785,7 +785,7 @@ func testTrashUntrash(t TB, factory TestableVolumeFactory) {
        }
 
        // Get the block - after trash and untrash sequence
-       n, err = v.Get(context.TODO(), TestHash, buf)
+       n, err = v.Get(context.Background(), TestHash, buf)
        if err != nil {
                t.Fatal(err)
        }
@@ -803,7 +803,7 @@ func testTrashEmptyTrashUntrash(t TB, factory TestableVolumeFactory) {
 
        checkGet := func() error {
                buf := make([]byte, BlockSize)
-               n, err := v.Get(context.TODO(), TestHash, buf)
+               n, err := v.Get(context.Background(), TestHash, buf)
                if err != nil {
                        return err
                }
@@ -816,7 +816,7 @@ func testTrashEmptyTrashUntrash(t TB, factory TestableVolumeFactory) {
                        return err
                }
 
-               err = v.Compare(context.TODO(), TestHash, TestBlock)
+               err = v.Compare(context.Background(), TestHash, TestBlock)
                if err != nil {
                        return err
                }
index 870489aaba15f47924124a0f66f0ac551c57ad7a..3021d6bd362724e7136d1054095e49bb53778199 100644 (file)
@@ -46,7 +46,7 @@ func (v *TestableUnixVolume) PutRaw(locator string, data []byte) {
                v.ReadOnly = orig
        }(v.ReadOnly)
        v.ReadOnly = false
-       err := v.Put(context.TODO(), locator, data)
+       err := v.Put(context.Background(), locator, data)
        if err != nil {
                v.t.Fatal(err)
        }
@@ -118,10 +118,10 @@ func TestReplicationDefault1(t *testing.T) {
 func TestGetNotFound(t *testing.T) {
        v := NewTestableUnixVolume(t, false, false)
        defer v.Teardown()
-       v.Put(context.TODO(), TestHash, TestBlock)
+       v.Put(context.Background(), TestHash, TestBlock)
 
        buf := make([]byte, BlockSize)
-       n, err := v.Get(context.TODO(), TestHash2, buf)
+       n, err := v.Get(context.Background(), TestHash2, buf)
        switch {
        case os.IsNotExist(err):
                break
@@ -136,7 +136,7 @@ func TestPut(t *testing.T) {
        v := NewTestableUnixVolume(t, false, false)
        defer v.Teardown()
 
-       err := v.Put(context.TODO(), TestHash, TestBlock)
+       err := v.Put(context.Background(), TestHash, TestBlock)
        if err != nil {
                t.Error(err)
        }
@@ -154,7 +154,7 @@ func TestPutBadVolume(t *testing.T) {
        defer v.Teardown()
 
        os.Chmod(v.Root, 000)
-       err := v.Put(context.TODO(), TestHash, TestBlock)
+       err := v.Put(context.Background(), TestHash, TestBlock)
        if err == nil {
                t.Error("Write should have failed")
        }
@@ -167,12 +167,12 @@ func TestUnixVolumeReadonly(t *testing.T) {
        v.PutRaw(TestHash, TestBlock)
 
        buf := make([]byte, BlockSize)
-       _, err := v.Get(context.TODO(), TestHash, buf)
+       _, err := v.Get(context.Background(), TestHash, buf)
        if err != nil {
                t.Errorf("got err %v, expected nil", err)
        }
 
-       err = v.Put(context.TODO(), TestHash, TestBlock)
+       err = v.Put(context.Background(), TestHash, TestBlock)
        if err != MethodDisabledError {
                t.Errorf("got err %v, expected MethodDisabledError", err)
        }
@@ -232,9 +232,9 @@ func TestUnixVolumeGetFuncWorkerError(t *testing.T) {
        v := NewTestableUnixVolume(t, false, false)
        defer v.Teardown()
 
-       v.Put(context.TODO(), TestHash, TestBlock)
+       v.Put(context.Background(), TestHash, TestBlock)
        mockErr := errors.New("Mock error")
-       err := v.getFunc(context.TODO(), v.blockPath(TestHash), func(rdr io.Reader) error {
+       err := v.getFunc(context.Background(), v.blockPath(TestHash), func(rdr io.Reader) error {
                return mockErr
        })
        if err != mockErr {
@@ -247,7 +247,7 @@ func TestUnixVolumeGetFuncFileError(t *testing.T) {
        defer v.Teardown()
 
        funcCalled := false
-       err := v.getFunc(context.TODO(), v.blockPath(TestHash), func(rdr io.Reader) error {
+       err := v.getFunc(context.Background(), v.blockPath(TestHash), func(rdr io.Reader) error {
                funcCalled = true
                return nil
        })
@@ -263,13 +263,13 @@ func TestUnixVolumeGetFuncWorkerWaitsOnMutex(t *testing.T) {
        v := NewTestableUnixVolume(t, false, false)
        defer v.Teardown()
 
-       v.Put(context.TODO(), TestHash, TestBlock)
+       v.Put(context.Background(), TestHash, TestBlock)
 
        mtx := NewMockMutex()
        v.locker = mtx
 
        funcCalled := make(chan struct{})
-       go v.getFunc(context.TODO(), v.blockPath(TestHash), func(rdr io.Reader) error {
+       go v.getFunc(context.Background(), v.blockPath(TestHash), func(rdr io.Reader) error {
                funcCalled <- struct{}{}
                return nil
        })
@@ -298,26 +298,26 @@ func TestUnixVolumeCompare(t *testing.T) {
        v := NewTestableUnixVolume(t, false, false)
        defer v.Teardown()
 
-       v.Put(context.TODO(), TestHash, TestBlock)
-       err := v.Compare(context.TODO(), TestHash, TestBlock)
+       v.Put(context.Background(), TestHash, TestBlock)
+       err := v.Compare(context.Background(), TestHash, TestBlock)
        if err != nil {
                t.Errorf("Got err %q, expected nil", err)
        }
 
-       err = v.Compare(context.TODO(), TestHash, []byte("baddata"))
+       err = v.Compare(context.Background(), TestHash, []byte("baddata"))
        if err != CollisionError {
                t.Errorf("Got err %q, expected %q", err, CollisionError)
        }
 
-       v.Put(context.TODO(), TestHash, []byte("baddata"))
-       err = v.Compare(context.TODO(), TestHash, TestBlock)
+       v.Put(context.Background(), TestHash, []byte("baddata"))
+       err = v.Compare(context.Background(), TestHash, TestBlock)
        if err != DiskHashError {
                t.Errorf("Got err %q, expected %q", err, DiskHashError)
        }
 
        p := fmt.Sprintf("%s/%s/%s", v.Root, TestHash[:3], TestHash)
        os.Chmod(p, 000)
-       err = v.Compare(context.TODO(), TestHash, TestBlock)
+       err = v.Compare(context.Background(), TestHash, TestBlock)
        if err == nil || strings.Index(err.Error(), "permission denied") < 0 {
                t.Errorf("Got err %q, expected %q", err, "permission denied")
        }