Skip to content

Commit

Permalink
pool: Release contexts via CleanUp in AIO tests
Browse files Browse the repository at this point in the history
More accepted approach for tests instead of defer.

Signed-off-by: Leonard Lyubich <[email protected]>
  • Loading branch information
cthulhu-rider committed Dec 4, 2024
1 parent 951cacd commit dd87066
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions pool/pool_aio_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ func testPoolInterfaceWithAIO(t *testing.T, nodeAddr string) {

// create container
ctxTimeout, cancel := context.WithTimeout(context.Background(), defaultTimeOut)
defer cancel()
t.Cleanup(cancel)

containerID := testCreateContainer(ctxTimeout, t, signer, cont, pool)
cl, err := pool.sdkClient()
Expand All @@ -293,7 +293,7 @@ func testPoolInterfaceWithAIO(t *testing.T, nodeAddr string) {

t.Run("set eacl", func(t *testing.T) {
ctxTimeout, cancel := context.WithTimeout(ctx, defaultTimeOut)
defer cancel()
t.Cleanup(cancel)

// note that eACL setting and its potential failure does not affect other ops
// tested in the superior test
Expand All @@ -310,13 +310,13 @@ func testPoolInterfaceWithAIO(t *testing.T, nodeAddr string) {
require.NoError(t, err)

ctxTimeout, cancel = context.WithTimeout(ctx, defaultTimeOut)
defer cancel()
t.Cleanup(cancel)

objectID := testObjectPutInit(ctxTimeout, t, account, containerID, signer, payload, pool)

// download object
ctxTimeout, cancel = context.WithTimeout(ctx, defaultTimeOut)
defer cancel()
t.Cleanup(cancel)

var cmd client.PrmObjectGet

Expand All @@ -337,7 +337,7 @@ func testPoolInterfaceWithAIO(t *testing.T, nodeAddr string) {

// delete object
ctxTimeout, cancel = context.WithTimeout(ctx, defaultTimeOut)
defer cancel()
t.Cleanup(cancel)

testDeleteObject(ctxTimeout, t, signer, containerID, objectID, pool)
cl, err = pool.sdkClient()
Expand All @@ -352,7 +352,7 @@ func testPoolInterfaceWithAIO(t *testing.T, nodeAddr string) {
require.NoError(t, err)

ctxTimeout, cancel = context.WithTimeout(ctx, defaultTimeOut*time.Duration(times))
defer cancel()
t.Cleanup(cancel)

payload = append(payload, 0x01) // Make it different from the one above, otherwise OID will be the same and we can get "status: code = 2052 message = object already removed"
objID := testObjectPutInit(ctxTimeout, t, account, containerID, signer, payload, pool)
Expand All @@ -364,7 +364,7 @@ func testPoolInterfaceWithAIO(t *testing.T, nodeAddr string) {
require.NoError(t, err)

ctxTimeout, cancel := context.WithTimeout(ctx, defaultTimeOut*time.Duration(times))
defer cancel()
t.Cleanup(cancel)

testDeleteObject(ctxTimeout, t, signer, containerID, objID, pool)

Expand All @@ -376,7 +376,7 @@ func testPoolInterfaceWithAIO(t *testing.T, nodeAddr string) {

// delete container
ctxTimeout, cancel = context.WithTimeout(ctx, defaultTimeOut)
defer cancel()
t.Cleanup(cancel)

testDeleteContainer(ctxTimeout, t, signer, containerID, pool)
cl, err = pool.sdkClient()
Expand All @@ -398,27 +398,27 @@ func testPoolWaiterWithAIO(t *testing.T, nodeAddr string) {

// create container
ctxTimeout, cancel := context.WithTimeout(ctx, defaultTimeOut)
defer cancel()
t.Cleanup(cancel)

containerID := testCreateContainer(ctxTimeout, t, signer, cont, wait)
eaclTable := testEaclTable(containerID)

// set eacl
ctxTimeout, cancel = context.WithTimeout(ctx, defaultTimeOut)
defer cancel()
t.Cleanup(cancel)

testSetEacl(ctxTimeout, t, signer, eaclTable, wait)

t.Run("get eacl", func(t *testing.T) {
ctxTimeout, cancel := context.WithTimeout(ctx, defaultTimeOut)
defer cancel()
t.Cleanup(cancel)

testGetEacl(ctxTimeout, t, containerID, eaclTable, pool)
})

// upload object
ctxTimeout, cancel = context.WithTimeout(ctx, defaultTimeOut)
defer cancel()
t.Cleanup(cancel)

rf := object.RequiredFields{
Container: containerID,
Expand Down Expand Up @@ -447,7 +447,7 @@ func testPoolWaiterWithAIO(t *testing.T, nodeAddr string) {

// download object
ctxTimeout, cancel = context.WithTimeout(ctx, defaultTimeOut)
defer cancel()
t.Cleanup(cancel)

var cmd client.PrmObjectGet

Expand All @@ -468,13 +468,13 @@ func testPoolWaiterWithAIO(t *testing.T, nodeAddr string) {

// delete object
ctxTimeout, cancel = context.WithTimeout(ctx, defaultTimeOut)
defer cancel()
t.Cleanup(cancel)

testDeleteObject(ctxTimeout, t, signer, containerID, objectID, pool)

// container delete"
ctxTimeout, cancel = context.WithTimeout(ctx, defaultTimeOut)
defer cancel()
t.Cleanup(cancel)

testDeleteContainer(ctxTimeout, t, signer, containerID, wait)
}
Expand Down Expand Up @@ -505,19 +505,19 @@ func testClientWaiterWithAIO(t *testing.T, nodeAddr string) {

// create container
ctxTimeout, cancel := context.WithTimeout(ctx, defaultTimeOut)
defer cancel()
t.Cleanup(cancel)

containerID := testCreateContainer(ctxTimeout, t, signer, cont, wait)
eaclTable := testEaclTable(containerID)

ctxTimeout, cancel = context.WithTimeout(ctx, defaultTimeOut)
defer cancel()
t.Cleanup(cancel)

testSetEacl(ctxTimeout, t, signer, eaclTable, wait)

t.Run("get eacl", func(t *testing.T) {
ctxTimeout, cancel := context.WithTimeout(ctx, defaultTimeOut)
defer cancel()
t.Cleanup(cancel)

testGetEacl(ctxTimeout, t, containerID, eaclTable, cl)
})
Expand Down Expand Up @@ -549,7 +549,7 @@ func testClientWaiterWithAIO(t *testing.T, nodeAddr string) {
require.NoError(t, err)

ctxTimeout, cancel = context.WithTimeout(ctx, defaultTimeOut)
defer cancel()
t.Cleanup(cancel)

rf := object.RequiredFields{
Container: containerID,
Expand Down Expand Up @@ -579,7 +579,7 @@ func testClientWaiterWithAIO(t *testing.T, nodeAddr string) {

// download object
ctxTimeout, cancel = context.WithTimeout(ctx, defaultTimeOut)
defer cancel()
t.Cleanup(cancel)

var cmd client.PrmObjectGet

Expand All @@ -600,13 +600,13 @@ func testClientWaiterWithAIO(t *testing.T, nodeAddr string) {

// delete object
ctxTimeout, cancel = context.WithTimeout(ctx, defaultTimeOut)
defer cancel()
t.Cleanup(cancel)

testDeleteObject(ctxTimeout, t, signer, containerID, objectID, cl)

// container delete
ctxTimeout, cancel = context.WithTimeout(ctx, defaultTimeOut)
defer cancel()
t.Cleanup(cancel)

testDeleteContainer(ctxTimeout, t, signer, containerID, wait)
}
Expand Down

0 comments on commit dd87066

Please sign in to comment.