storj/private/testplanet/storagenode-wait.go
Egon Elbre 6511bb91fb private/testplanet: support writing monitoring spans
This allows to set `STORJ_TEST_MONKIT` to either
`svg` or `json` to write individual testplanet test
traces to disk.

It also allows to specify an absolute directory:

  STORJ_TEST_MONKIT=svg,dir:/abs/dir/path

It requires an absolute path, because from the context of
tests, there's no easy way to find the folder where tests
were called.

Change-Id: I6fe008a4d4237d221cf5a5bede798b46399ee197
2021-09-30 09:03:35 +03:00

51 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) (err error) {
defer mon.Task()(&ctx)(&err)
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) {
defer mon.Task()(&ctx)(nil)
for _, sn := range planet.StorageNodes {
sn.Peer.Storage2.PieceDeleter.Wait(ctx)
}
}