storj/private/testplanet/storagenode-wait.go
Egon Elbre f4d5d89b68 private/testplanet: add WaitForStorageNodeEndpoints
After calling uplink.Upload it is not guaranteed that the
storage node has yet saved all the orders since it happens
asynchronously. Hence we need a separate func to wait
for them to complete.

Change-Id: I0c34b3ea6c98dbcf37f80493c0e10a8bdbbb2aaf
2020-03-05 10:33:56 +00:00

40 lines
939 B
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
}