storj/private/testplanet/storagenode-wait.go
Isaac Hess 237d9da477 storagenode/pieces: Deleter can handle multiple tests
Before the deleter would close its done channel once, so if additional
tests shared a storagenode, even if not in parallel, the later waits
would not work properly. This fixes that problem.

Change-Id: I7dcacf6699cef7c2c2948ba0f4369ef520601bf5
2020-04-29 11:26:56 -06:00

47 lines
1.2 KiB
Go

// Copyright (C) 2020 Storj Labs, Inc.
// See LICENSE for copying information
package testplanet
import (
"context"
"time"
"github.com/zeebo/errs"
)
// WaitForStorageNodeEndpoints waits for storage node endpoints to finish their work.
// The call will return an error if they have not been completed after 1 minute.
func (planet *Planet) WaitForStorageNodeEndpoints(ctx context.Context) error {
timeout := time.NewTimer(time.Minute)
defer timeout.Stop()
for {
if planet.storageNodeLiveRequestCount() == 0 {
return nil
}
select {
case <-time.After(50 * time.Millisecond):
case <-timeout.C:
return errs.New("timed out waiting for storagenode endpoints")
case <-ctx.Done():
return ctx.Err()
}
}
}
func (planet *Planet) storageNodeLiveRequestCount() int {
total := 0
for _, storageNode := range planet.StorageNodes {
total += int(storageNode.Storage2.Endpoint.TestLiveRequestCount())
}
return total
}
// WaitForStorageNodeDeleters calls the Wait method on each storagenode's PieceDeleter.
func (planet *Planet) WaitForStorageNodeDeleters(ctx context.Context) {
for _, sn := range planet.StorageNodes {
sn.Peer.Storage2.PieceDeleter.Wait(ctx)
}
}