[#165] pool: update WaitForContainerPresence

Signed-off-by: Denis Kirillov <denis@nspcc.ru>
This commit is contained in:
Denis Kirillov 2022-03-16 16:06:43 +03:00 committed by Alex Vanin
parent 191d85e607
commit 59b49dd7e6
2 changed files with 8 additions and 13 deletions

View file

@ -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. // WaitForContainerPresence waits until the container is found on the NeoFS network.
func (p *Pool) WaitForContainerPresence(ctx context.Context, cid *cid.ID, pollParams *ContainerPollingParams) error { func WaitForContainerPresence(ctx context.Context, pool *Pool, cid *cid.ID, pollParams *ContainerPollingParams) error {
cp, err := p.connection()
if err != nil {
return err
}
wctx, cancel := context.WithTimeout(ctx, pollParams.timeout) wctx, cancel := context.WithTimeout(ctx, pollParams.timeout)
defer cancel() defer cancel()
ticker := time.NewTimer(pollParams.pollInterval) ticker := time.NewTimer(pollParams.pollInterval)
@ -1548,10 +1544,9 @@ func (p *Pool) WaitForContainerPresence(ctx context.Context, cid *cid.ID, pollPa
wdone := wctx.Done() wdone := wctx.Done()
done := ctx.Done() done := ctx.Done()
var cliPrm sdkClient.PrmContainerGet var prm PrmContainerGet
if cid != nil { if cid != nil {
cliPrm.SetContainer(*cid) prm.SetContainerID(*cid)
} }
for { for {
@ -1561,7 +1556,7 @@ func (p *Pool) WaitForContainerPresence(ctx context.Context, cid *cid.ID, pollPa
case <-wdone: case <-wdone:
return wctx.Err() return wctx.Err()
case <-ticker.C: case <-ticker.C:
_, err = cp.client.ContainerGet(ctx, cliPrm) _, err := pool.GetContainer(ctx, prm)
if err == nil { if err == nil {
return nil return nil
} }

View file

@ -583,7 +583,7 @@ func TestWaitPresence(t *testing.T) {
mockClient.EXPECT().CreateSession(gomock.Any(), gomock.Any()).Return(nil, nil).AnyTimes() mockClient.EXPECT().CreateSession(gomock.Any(), gomock.Any()).Return(nil, nil).AnyTimes()
mockClient.EXPECT().EndpointInfo(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().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() cache, err := newCache()
require.NoError(t, err) require.NoError(t, err)
@ -609,14 +609,14 @@ func TestWaitPresence(t *testing.T) {
cancel() cancel()
}() }()
err := p.WaitForContainerPresence(ctx, nil, DefaultPollingParams()) err := WaitForContainerPresence(ctx, p, nil, DefaultPollingParams())
require.Error(t, err) require.Error(t, err)
require.Contains(t, err.Error(), "context canceled") require.Contains(t, err.Error(), "context canceled")
}) })
t.Run("context deadline exceeded", func(t *testing.T) { t.Run("context deadline exceeded", func(t *testing.T) {
ctx := context.Background() ctx := context.Background()
err := p.WaitForContainerPresence(ctx, nil, &ContainerPollingParams{ err := WaitForContainerPresence(ctx, p, nil, &ContainerPollingParams{
timeout: 500 * time.Millisecond, timeout: 500 * time.Millisecond,
pollInterval: 5 * time.Second, pollInterval: 5 * time.Second,
}) })
@ -626,7 +626,7 @@ func TestWaitPresence(t *testing.T) {
t.Run("ok", func(t *testing.T) { t.Run("ok", func(t *testing.T) {
ctx := context.Background() ctx := context.Background()
err := p.WaitForContainerPresence(ctx, nil, &ContainerPollingParams{ err := WaitForContainerPresence(ctx, p, nil, &ContainerPollingParams{
timeout: 10 * time.Second, timeout: 10 * time.Second,
pollInterval: 500 * time.Millisecond, pollInterval: 500 * time.Millisecond,
}) })