From 59b49dd7e665a26524908e4f7ed47fbce0cfbde1 Mon Sep 17 00:00:00 2001 From: Denis Kirillov Date: Wed, 16 Mar 2022 16:06:43 +0300 Subject: [PATCH] [#165] pool: update WaitForContainerPresence Signed-off-by: Denis Kirillov --- pool/pool.go | 13 ++++--------- pool/pool_test.go | 8 ++++---- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/pool/pool.go b/pool/pool.go index 21b9279f..bd1bffb3 100644 --- a/pool/pool.go +++ b/pool/pool.go @@ -1536,11 +1536,7 @@ func (p *Pool) Balance(ctx context.Context, prm PrmBalanceGet) (*accounting.Deci } // WaitForContainerPresence waits until the container is found on the NeoFS network. -func (p *Pool) WaitForContainerPresence(ctx context.Context, cid *cid.ID, pollParams *ContainerPollingParams) error { - cp, err := p.connection() - if err != nil { - return err - } +func WaitForContainerPresence(ctx context.Context, pool *Pool, cid *cid.ID, pollParams *ContainerPollingParams) error { wctx, cancel := context.WithTimeout(ctx, pollParams.timeout) defer cancel() ticker := time.NewTimer(pollParams.pollInterval) @@ -1548,10 +1544,9 @@ func (p *Pool) WaitForContainerPresence(ctx context.Context, cid *cid.ID, pollPa wdone := wctx.Done() done := ctx.Done() - var cliPrm sdkClient.PrmContainerGet - + var prm PrmContainerGet if cid != nil { - cliPrm.SetContainer(*cid) + prm.SetContainerID(*cid) } for { @@ -1561,7 +1556,7 @@ func (p *Pool) WaitForContainerPresence(ctx context.Context, cid *cid.ID, pollPa case <-wdone: return wctx.Err() case <-ticker.C: - _, err = cp.client.ContainerGet(ctx, cliPrm) + _, err := pool.GetContainer(ctx, prm) if err == nil { return nil } diff --git a/pool/pool_test.go b/pool/pool_test.go index 9326a27f..f89e6714 100644 --- a/pool/pool_test.go +++ b/pool/pool_test.go @@ -583,7 +583,7 @@ func TestWaitPresence(t *testing.T) { mockClient.EXPECT().CreateSession(gomock.Any(), gomock.Any()).Return(nil, nil).AnyTimes() mockClient.EXPECT().EndpointInfo(gomock.Any(), gomock.Any()).Return(nil, nil).AnyTimes() mockClient.EXPECT().NetworkInfo(gomock.Any(), gomock.Any()).Return(&sdkClient.ResNetworkInfo{}, nil).AnyTimes() - mockClient.EXPECT().GetContainer(gomock.Any(), gomock.Any()).Return(nil, nil).AnyTimes() + mockClient.EXPECT().GetContainer(gomock.Any(), gomock.Any()).Return(&sdkClient.ResContainerGet{}, nil).AnyTimes() cache, err := newCache() require.NoError(t, err) @@ -609,14 +609,14 @@ func TestWaitPresence(t *testing.T) { cancel() }() - err := p.WaitForContainerPresence(ctx, nil, DefaultPollingParams()) + err := WaitForContainerPresence(ctx, p, nil, DefaultPollingParams()) require.Error(t, err) require.Contains(t, err.Error(), "context canceled") }) t.Run("context deadline exceeded", func(t *testing.T) { ctx := context.Background() - err := p.WaitForContainerPresence(ctx, nil, &ContainerPollingParams{ + err := WaitForContainerPresence(ctx, p, nil, &ContainerPollingParams{ timeout: 500 * time.Millisecond, pollInterval: 5 * time.Second, }) @@ -626,7 +626,7 @@ func TestWaitPresence(t *testing.T) { t.Run("ok", func(t *testing.T) { ctx := context.Background() - err := p.WaitForContainerPresence(ctx, nil, &ContainerPollingParams{ + err := WaitForContainerPresence(ctx, p, nil, &ContainerPollingParams{ timeout: 10 * time.Second, pollInterval: 500 * time.Millisecond, })