diff --git a/Makefile b/Makefile index ba738e2..e6b831d 100644 --- a/Makefile +++ b/Makefile @@ -18,3 +18,7 @@ build-clean: clean build test: go test -trimpath -buildvcs=false -ldflags '-extldflags "-static" -s -w -buildid=' -race -failfast -vet=all -v ./... .PHONY: test + +gen: + $(MAKE) -C ./ingest +.PHONY: gen diff --git a/go.sum b/go.sum index b6888b4..cbd42df 100644 --- a/go.sum +++ b/go.sum @@ -28,8 +28,6 @@ github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxec github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= -github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPng= -github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= github.com/mattn/go-isatty v0.0.18 h1:DOKFKCQ7FNG2L1rbrmstDN4QVRdS89Nkh85u68Uwp98= github.com/mattn/go-isatty v0.0.18/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mdlayher/genetlink v1.3.1 h1:roBiPnual+eqtRkKX2Jb8UQN5ZPWnhDCGj/wR6Jlz2w= diff --git a/ingest/Makefile b/ingest/Makefile new file mode 100644 index 0000000..395b1f0 --- /dev/null +++ b/ingest/Makefile @@ -0,0 +1,3 @@ +gen: + mockgen -source ingest.go -destination mocks/ingest.go -package mocks +.PHONY: gen diff --git a/ingest/cmd/main.go b/ingest/cmd/main.go index 26d24dc..4fa3bab 100644 --- a/ingest/cmd/main.go +++ b/ingest/cmd/main.go @@ -167,11 +167,11 @@ func (m *storeMongo) LoadBeforeRestartUsage(ctx context.Context) (map[string]ing return out, nil } -func (m *storeMongo) IngestUsage(ctx context.Context, peersUsage []ingest.PeerUsage) error { +func (m *storeMongo) IngestUsage(ctx context.Context, peersUsage []ingest.PeerUsage, gatheredAt time.Time) error { models := funcutils.Map(peersUsage, func(p ingest.PeerUsage) mongo.WriteModel { return mongo.NewUpdateOneModel(). SetFilter(bson.M{"publicKey": p.PublicKey}). - SetUpdate(bson.M{"$push": bson.M{"usage": bson.M{"upload": p.Upload, "download": p.Download}}}). + SetUpdate(bson.M{"$push": bson.M{"usage": bson.M{"upload": p.Upload, "download": p.Download, "at": gatheredAt.UnixMilli()}}}). SetUpsert(true) }) opts := options.BulkWrite().SetOrdered(false).SetBypassDocumentValidation(true) @@ -186,10 +186,11 @@ type wgPeers struct { ctrl *wgctrl.Client } -func (wg *wgPeers) Usage(ctx context.Context) ([]ingest.PeerUsage, error) { +func (wg *wgPeers) Usage(ctx context.Context) ([]ingest.PeerUsage, time.Time, error) { dev, err := wg.ctrl.Device(wgDeviceName) + gatheredAt := time.Now() if nil != err { - return nil, err + return nil, gatheredAt, err } out := funcutils.Map(dev.Peers, func(p wgtypes.Peer) ingest.PeerUsage { @@ -200,7 +201,7 @@ func (wg *wgPeers) Usage(ctx context.Context) ([]ingest.PeerUsage, error) { } }) - return out, nil + return out, gatheredAt, nil } type restartMarkFileReadRemover struct{} diff --git a/ingest/ingest.go b/ingest/ingest.go index 5776595..bfda776 100644 --- a/ingest/ingest.go +++ b/ingest/ingest.go @@ -5,6 +5,7 @@ import ( "errors" "fmt" "os" + "time" "github.com/rs/zerolog" ) @@ -17,11 +18,11 @@ type PeerUsage struct { type Store interface { LoadBeforeRestartUsage(ctx context.Context) (map[string]PeerUsage, error) - IngestUsage(ctx context.Context, peersUsage []PeerUsage) error + IngestUsage(ctx context.Context, peersUsage []PeerUsage, gatheredAt time.Time) error } type WgPeers interface { - Usage(ctx context.Context) ([]PeerUsage, error) + Usage(ctx context.Context) (peersUsage []PeerUsage, gatheredAt time.Time, err error) } type RestartMarkFileReadRemover interface { @@ -57,7 +58,7 @@ func (e *Engine) Run(ctx context.Context, tick <-chan struct{}, restartMarkFileN case <-ctx.Done(): return ctx.Err() default: - peersUsage, err := e.wgPeers.Usage(ctx) + peersUsage, gatheredAt, err := e.wgPeers.Usage(ctx) if nil != err { e.logger.Error().Err(err).Msg("failed to get wireguard peers usage data") continue @@ -86,7 +87,7 @@ func (e *Engine) Run(ctx context.Context, tick <-chan struct{}, restartMarkFileN } if len(peersUsage) > 0 { - if err := e.store.IngestUsage(ctx, peersUsage); nil != err { + if err := e.store.IngestUsage(ctx, peersUsage, gatheredAt); nil != err { e.logger.Error().Err(err).Msg("failed to ingest peers usage data") continue } diff --git a/ingest/ingest_test.go b/ingest/ingest_test.go index 0d1ebf6..f5c4617 100644 --- a/ingest/ingest_test.go +++ b/ingest/ingest_test.go @@ -6,6 +6,7 @@ import ( "io" "os" "testing" + "time" "github.com/golang/mock/gomock" "github.com/rs/zerolog" @@ -23,16 +24,18 @@ func TestEngineContextCancellation(t *testing.T) { runCtx, cancelRunCtx := context.WithCancelCause(ctx) var runErr error + gatherTime := time.Now() + store := mocks.NewMockStore(ctrl) store.EXPECT().LoadBeforeRestartUsage(runCtx).Times(0) - store.EXPECT().IngestUsage(runCtx, []ingest.PeerUsage{{Upload: 10, Download: 30, PublicKey: "xyz"}}).Return(nil).Times(1) + store.EXPECT().IngestUsage(runCtx, []ingest.PeerUsage{{Upload: 10, Download: 30, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1) readRestartMarkFile := mocks.NewMockRestartMarkFileReadRemover(ctrl) readRestartMarkFile.EXPECT().Read("TODO").Return([1]byte{0}, os.ErrNotExist).Times(1) readRestartMarkFile.EXPECT().Remove("TODO").Return(nil).Times(0) readWGPeersUsage := mocks.NewMockWgPeers(ctrl) - readWGPeersUsage.EXPECT().Usage(runCtx).Return([]ingest.PeerUsage{{Upload: 10, Download: 30, PublicKey: "xyz"}}, nil).Times(1) + readWGPeersUsage.EXPECT().Usage(runCtx).Return([]ingest.PeerUsage{{Upload: 10, Download: 30, PublicKey: "xyz"}}, gatherTime, nil).Times(1) e := ingest.NewEngine(readRestartMarkFile, readWGPeersUsage, store, zerolog.New(io.Discard)) @@ -71,19 +74,22 @@ func TestEngineSingleStaticPeer(t *testing.T) { t.Parallel() ctx := context.Background() ctrl, ctx := gomock.WithContext(ctx, t) + + gatherTime := time.Now() + store := mocks.NewMockStore(ctrl) store.EXPECT().LoadBeforeRestartUsage(ctx).Times(0) gomock.InOrder( - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 10, Download: 30, PublicKey: "xyz"}}).Return(nil).Times(1), - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 20, Download: 60, PublicKey: "xyz"}}).Return(nil).Times(1), - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 30, Download: 90, PublicKey: "xyz"}}).Return(nil).Times(1), - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 40, Download: 120, PublicKey: "xyz"}}).Return(nil).Times(1), - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 50, Download: 150, PublicKey: "xyz"}}).Return(nil).Times(1), - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 60, Download: 180, PublicKey: "xyz"}}).Return(nil).Times(1), - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 70, Download: 210, PublicKey: "xyz"}}).Return(nil).Times(1), - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 80, Download: 240, PublicKey: "xyz"}}).Return(nil).Times(1), - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 90, Download: 270, PublicKey: "xyz"}}).Return(nil).Times(1), - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 100, Download: 300, PublicKey: "xyz"}}).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 10, Download: 30, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 20, Download: 60, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 30, Download: 90, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 40, Download: 120, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 50, Download: 150, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 60, Download: 180, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 70, Download: 210, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 80, Download: 240, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 90, Download: 270, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 100, Download: 300, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), ) readRestartMarkFile := mocks.NewMockRestartMarkFileReadRemover(ctrl) @@ -92,16 +98,16 @@ func TestEngineSingleStaticPeer(t *testing.T) { readWGPeersUsage := mocks.NewMockWgPeers(ctrl) gomock.InOrder( - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 10, Download: 30, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 20, Download: 60, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 30, Download: 90, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 40, Download: 120, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 50, Download: 150, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 60, Download: 180, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 70, Download: 210, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 80, Download: 240, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 90, Download: 270, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 100, Download: 300, PublicKey: "xyz"}}, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 10, Download: 30, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 20, Download: 60, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 30, Download: 90, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 40, Download: 120, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 50, Download: 150, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 60, Download: 180, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 70, Download: 210, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 80, Download: 240, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 90, Download: 270, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 100, Download: 300, PublicKey: "xyz"}}, gatherTime, nil).Times(1), ) e := ingest.NewEngine(readRestartMarkFile, readWGPeersUsage, store, zerolog.New(io.Discard)) @@ -134,17 +140,20 @@ func TestEngineSingleStaticPeerWithWgReadPeersUsageFailure(t *testing.T) { t.Parallel() ctx := context.Background() ctrl, ctx := gomock.WithContext(ctx, t) + + gatherTime := time.Now() + store := mocks.NewMockStore(ctrl) store.EXPECT().LoadBeforeRestartUsage(ctx).Times(0) gomock.InOrder( - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 10, Download: 30, PublicKey: "xyz"}}).Return(nil).Times(1), - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 20, Download: 60, PublicKey: "xyz"}}).Return(nil).Times(1), - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 40, Download: 120, PublicKey: "xyz"}}).Return(nil).Times(1), - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 50, Download: 150, PublicKey: "xyz"}}).Return(nil).Times(1), - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 60, Download: 180, PublicKey: "xyz"}}).Return(nil).Times(1), - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 70, Download: 210, PublicKey: "xyz"}}).Return(nil).Times(1), - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 90, Download: 270, PublicKey: "xyz"}}).Return(nil).Times(1), - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 100, Download: 300, PublicKey: "xyz"}}).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 10, Download: 30, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 20, Download: 60, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 40, Download: 120, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 50, Download: 150, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 60, Download: 180, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 70, Download: 210, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 90, Download: 270, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 100, Download: 300, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), ) readRestartMarkFile := mocks.NewMockRestartMarkFileReadRemover(ctrl) @@ -153,16 +162,16 @@ func TestEngineSingleStaticPeerWithWgReadPeersUsageFailure(t *testing.T) { readWGPeersUsage := mocks.NewMockWgPeers(ctrl) gomock.InOrder( - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 10, Download: 30, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 20, Download: 60, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return(nil, errors.New("unknown error")).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 40, Download: 120, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 50, Download: 150, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 60, Download: 180, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 70, Download: 210, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return(nil, errors.New("network error")).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 90, Download: 270, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 100, Download: 300, PublicKey: "xyz"}}, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 10, Download: 30, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 20, Download: 60, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return(nil, gatherTime, errors.New("unknown error")).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 40, Download: 120, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 50, Download: 150, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 60, Download: 180, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 70, Download: 210, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return(nil, gatherTime, errors.New("network error")).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 90, Download: 270, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 100, Download: 300, PublicKey: "xyz"}}, gatherTime, nil).Times(1), ) e := ingest.NewEngine(readRestartMarkFile, readWGPeersUsage, store, zerolog.New(io.Discard)) @@ -195,19 +204,22 @@ func TestEngineSingleStaticPeerWithIngestFailure(t *testing.T) { t.Parallel() ctx := context.Background() ctrl, ctx := gomock.WithContext(ctx, t) + + gatherTime := time.Now() + store := mocks.NewMockStore(ctrl) store.EXPECT().LoadBeforeRestartUsage(ctx).Times(0) gomock.InOrder( - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 10, Download: 30, PublicKey: "xyz"}}).Return(nil).Times(1), - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 20, Download: 60, PublicKey: "xyz"}}).Return(errors.New("unknown error")).Times(1), - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 30, Download: 90, PublicKey: "xyz"}}).Return(nil).Times(1), - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 40, Download: 120, PublicKey: "xyz"}}).Return(nil).Times(1), - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 50, Download: 150, PublicKey: "xyz"}}).Return(nil).Times(1), - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 60, Download: 180, PublicKey: "xyz"}}).Return(errors.New("network error")).Times(1), - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 70, Download: 210, PublicKey: "xyz"}}).Return(nil).Times(1), - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 80, Download: 240, PublicKey: "xyz"}}).Return(nil).Times(1), - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 90, Download: 270, PublicKey: "xyz"}}).Return(nil).Times(1), - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 100, Download: 300, PublicKey: "xyz"}}).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 10, Download: 30, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 20, Download: 60, PublicKey: "xyz"}}, gatherTime).Return(errors.New("unknown error")).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 30, Download: 90, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 40, Download: 120, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 50, Download: 150, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 60, Download: 180, PublicKey: "xyz"}}, gatherTime).Return(errors.New("network error")).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 70, Download: 210, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 80, Download: 240, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 90, Download: 270, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 100, Download: 300, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), ) readRestartMarkFile := mocks.NewMockRestartMarkFileReadRemover(ctrl) @@ -216,16 +228,16 @@ func TestEngineSingleStaticPeerWithIngestFailure(t *testing.T) { readWGPeersUsage := mocks.NewMockWgPeers(ctrl) gomock.InOrder( - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 10, Download: 30, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 20, Download: 60, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 30, Download: 90, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 40, Download: 120, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 50, Download: 150, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 60, Download: 180, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 70, Download: 210, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 80, Download: 240, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 90, Download: 270, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 100, Download: 300, PublicKey: "xyz"}}, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 10, Download: 30, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 20, Download: 60, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 30, Download: 90, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 40, Download: 120, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 50, Download: 150, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 60, Download: 180, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 70, Download: 210, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 80, Download: 240, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 90, Download: 270, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 100, Download: 300, PublicKey: "xyz"}}, gatherTime, nil).Times(1), ) e := ingest.NewEngine(readRestartMarkFile, readWGPeersUsage, store, zerolog.New(io.Discard)) @@ -258,15 +270,18 @@ func TestEngineSingleStaticPeerWithRestartMarkFileReadFailure(t *testing.T) { t.Parallel() ctx := context.Background() ctrl, ctx := gomock.WithContext(ctx, t) + + gatherTime := time.Now() + store := mocks.NewMockStore(ctrl) store.EXPECT().LoadBeforeRestartUsage(ctx).Times(0) gomock.InOrder( - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 10, Download: 30, PublicKey: "xyz"}}).Return(nil).Times(1), - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 20, Download: 60, PublicKey: "xyz"}}).Return(nil).Times(1), - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 30, Download: 90, PublicKey: "xyz"}}).Return(nil).Times(1), - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 40, Download: 120, PublicKey: "xyz"}}).Return(nil).Times(1), - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 50, Download: 150, PublicKey: "xyz"}}).Return(nil).Times(1), - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 60, Download: 180, PublicKey: "xyz"}}).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 10, Download: 30, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 20, Download: 60, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 30, Download: 90, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 40, Download: 120, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 50, Download: 150, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 60, Download: 180, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), ) readRestartMarkFile := mocks.NewMockRestartMarkFileReadRemover(ctrl) @@ -280,13 +295,13 @@ func TestEngineSingleStaticPeerWithRestartMarkFileReadFailure(t *testing.T) { readWGPeersUsage := mocks.NewMockWgPeers(ctrl) gomock.InOrder( - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 10, Download: 30, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 20, Download: 60, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 30, Download: 90, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 40, Download: 120, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 50, Download: 150, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 60, Download: 180, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 70, Download: 210, PublicKey: "xyz"}}, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 10, Download: 30, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 20, Download: 60, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 30, Download: 90, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 40, Download: 120, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 50, Download: 150, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 60, Download: 180, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 70, Download: 210, PublicKey: "xyz"}}, gatherTime, nil).Times(1), ) e := ingest.NewEngine(readRestartMarkFile, readWGPeersUsage, store, zerolog.New(io.Discard)) @@ -320,6 +335,9 @@ func TestEngineSingleStaticPeerWithRestartsAndLoadBeforeRestartUsageFailure(t *t t.Parallel() ctx := context.Background() ctrl, ctx := gomock.WithContext(ctx, t) + + gatherTime := time.Now() + store := mocks.NewMockStore(ctrl) gomock.InOrder( store.EXPECT().LoadBeforeRestartUsage(ctx).Return(map[string]ingest.PeerUsage{"xyz": {Upload: 10, Download: 80, PublicKey: "xyz"}}, nil).Times(1), @@ -330,12 +348,12 @@ func TestEngineSingleStaticPeerWithRestartsAndLoadBeforeRestartUsageFailure(t *t store.EXPECT().LoadBeforeRestartUsage(ctx).Return(nil, errors.New("unknown error")).Times(1), ) gomock.InOrder( - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 10 + 10, Download: 30 + 80, PublicKey: "xyz"}}).Return(nil).Times(1), - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 30 + 10 + 10, Download: 90 + 30 + 80, PublicKey: "xyz"}}).Return(nil).Times(1), - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 40 + 10 + 10, Download: 120 + 30 + 80, PublicKey: "xyz"}}).Return(nil).Times(1), - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 50 + 10 + 10, Download: 150 + 30 + 80, PublicKey: "xyz"}}).Return(nil).Times(1), - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 80 + 50 + 10 + 10, Download: 240 + 150 + 30 + 80, PublicKey: "xyz"}}).Return(nil).Times(1), - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 90 + 50 + 10 + 10, Download: 270 + 150 + 30 + 80, PublicKey: "xyz"}}).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 10 + 10, Download: 30 + 80, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 30 + 10 + 10, Download: 90 + 30 + 80, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 40 + 10 + 10, Download: 120 + 30 + 80, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 50 + 10 + 10, Download: 150 + 30 + 80, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 80 + 50 + 10 + 10, Download: 240 + 150 + 30 + 80, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 90 + 50 + 10 + 10, Download: 270 + 150 + 30 + 80, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), ) readRestartMarkFile := mocks.NewMockRestartMarkFileReadRemover(ctrl) @@ -350,16 +368,16 @@ func TestEngineSingleStaticPeerWithRestartsAndLoadBeforeRestartUsageFailure(t *t readWGPeersUsage := mocks.NewMockWgPeers(ctrl) gomock.InOrder( - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 10, Download: 30, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 20, Download: 60, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 30, Download: 90, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 40, Download: 120, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 50, Download: 150, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 60, Download: 180, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 70, Download: 210, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 80, Download: 240, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 90, Download: 270, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 100, Download: 300, PublicKey: "xyz"}}, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 10, Download: 30, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 20, Download: 60, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 30, Download: 90, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 40, Download: 120, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 50, Download: 150, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 60, Download: 180, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 70, Download: 210, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 80, Download: 240, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 90, Download: 270, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 100, Download: 300, PublicKey: "xyz"}}, gatherTime, nil).Times(1), ) e := ingest.NewEngine(readRestartMarkFile, readWGPeersUsage, store, zerolog.New(io.Discard)) @@ -394,6 +412,8 @@ func TestEngineSingleStaticPeerWithRestart(t *testing.T) { ctx := context.Background() ctrl, ctx := gomock.WithContext(ctx, t) + gatherTime := time.Now() + store := mocks.NewMockStore(ctrl) gomock.InOrder( store.EXPECT().LoadBeforeRestartUsage(ctx).Return(map[string]ingest.PeerUsage{"xyz": {Upload: 154, Download: 215, PublicKey: "xyz"}}, nil).Times(1), @@ -402,41 +422,41 @@ func TestEngineSingleStaticPeerWithRestart(t *testing.T) { store.EXPECT().LoadBeforeRestartUsage(ctx).Return(map[string]ingest.PeerUsage{"xyz": {Upload: 8555, Download: 67015, PublicKey: "xyz"}}, nil).Times(1), ) gomock.InOrder( - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 120, Download: 169, PublicKey: "xyz"}}).Return(nil).Times(1), - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 122, Download: 170, PublicKey: "xyz"}}).Return(nil).Times(1), - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 141, Download: 176, PublicKey: "xyz"}}).Return(nil).Times(1), - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 142, Download: 186, PublicKey: "xyz"}}).Return(nil).Times(1), - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 150, Download: 194, PublicKey: "xyz"}}).Return(nil).Times(1), - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 151, Download: 198, PublicKey: "xyz"}}).Return(nil).Times(1), - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 154, Download: 215, PublicKey: "xyz"}}).Return(nil).Times(1), - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 4130, Download: 29607, PublicKey: "xyz"}}).Return(nil).Times(1), - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 4230, Download: 31776, PublicKey: "xyz"}}).Return(nil).Times(1), - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 4562, Download: 32532, PublicKey: "xyz"}}).Return(nil).Times(1), - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 4631, Download: 35744, PublicKey: "xyz"}}).Return(nil).Times(1), - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 4889, Download: 38013, PublicKey: "xyz"}}).Return(nil).Times(1), - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 5659, Download: 38580, PublicKey: "xyz"}}).Return(nil).Times(1), - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 5852, Download: 43146, PublicKey: "xyz"}}).Return(nil).Times(1), - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 6365, Download: 43847, PublicKey: "xyz"}}).Return(nil).Times(1), - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 6383, Download: 43848, PublicKey: "xyz"}}).Return(nil).Times(1), - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 6392, Download: 43854, PublicKey: "xyz"}}).Return(nil).Times(1), - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 6394, Download: 43867, PublicKey: "xyz"}}).Return(nil).Times(1), - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 6396, Download: 43876, PublicKey: "xyz"}}).Return(nil).Times(1), - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 6403, Download: 43884, PublicKey: "xyz"}}).Return(nil).Times(1), - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 6406, Download: 43888, PublicKey: "xyz"}}).Return(nil).Times(1), - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 7776, Download: 57184, PublicKey: "xyz"}}).Return(nil).Times(1), - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 7896, Download: 57947, PublicKey: "xyz"}}).Return(nil).Times(1), - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 7916, Download: 58876, PublicKey: "xyz"}}).Return(nil).Times(1), - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 8319, Download: 59953, PublicKey: "xyz"}}).Return(nil).Times(1), - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 8366, Download: 63397, PublicKey: "xyz"}}).Return(nil).Times(1), - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 8434, Download: 64510, PublicKey: "xyz"}}).Return(nil).Times(1), - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 8555, Download: 67015, PublicKey: "xyz"}}).Return(nil).Times(1), - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 15057, Download: 143589, PublicKey: "xyz"}}).Return(nil).Times(1), - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 15061, Download: 149515, PublicKey: "xyz"}}).Return(nil).Times(1), - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 15637, Download: 150101, PublicKey: "xyz"}}).Return(nil).Times(1), - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 15915, Download: 157102, PublicKey: "xyz"}}).Return(nil).Times(1), - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 15972, Download: 158860, PublicKey: "xyz"}}).Return(nil).Times(1), - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 16083, Download: 163393, PublicKey: "xyz"}}).Return(nil).Times(1), - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 16545, Download: 166809, PublicKey: "xyz"}}).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 120, Download: 169, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 122, Download: 170, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 141, Download: 176, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 142, Download: 186, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 150, Download: 194, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 151, Download: 198, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 154, Download: 215, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 4130, Download: 29607, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 4230, Download: 31776, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 4562, Download: 32532, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 4631, Download: 35744, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 4889, Download: 38013, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 5659, Download: 38580, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 5852, Download: 43146, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 6365, Download: 43847, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 6383, Download: 43848, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 6392, Download: 43854, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 6394, Download: 43867, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 6396, Download: 43876, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 6403, Download: 43884, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 6406, Download: 43888, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 7776, Download: 57184, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 7896, Download: 57947, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 7916, Download: 58876, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 8319, Download: 59953, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 8366, Download: 63397, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 8434, Download: 64510, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 8555, Download: 67015, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 15057, Download: 143589, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 15061, Download: 149515, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 15637, Download: 150101, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 15915, Download: 157102, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 15972, Download: 158860, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 16083, Download: 163393, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 16545, Download: 166809, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), ) readRestartMarkFile := mocks.NewMockRestartMarkFileReadRemover(ctrl) @@ -455,41 +475,41 @@ func TestEngineSingleStaticPeerWithRestart(t *testing.T) { readWGPeersUsage := mocks.NewMockWgPeers(ctrl) gomock.InOrder( - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 120, Download: 169, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 122, Download: 170, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 141, Download: 176, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 142, Download: 186, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 150, Download: 194, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 151, Download: 198, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 154, Download: 215, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 3976, Download: 29392, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 4076, Download: 31561, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 4408, Download: 32317, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 4477, Download: 35529, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 4735, Download: 37798, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 5505, Download: 38365, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 5698, Download: 42931, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 513, Download: 701, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 531, Download: 702, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 540, Download: 708, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 542, Download: 721, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 544, Download: 730, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 551, Download: 738, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 554, Download: 742, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 1370, Download: 13296, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 1490, Download: 14059, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 1510, Download: 14988, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 1913, Download: 16065, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 1960, Download: 19509, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 2028, Download: 20622, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 2149, Download: 23127, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 6502, Download: 76574, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 6506, Download: 82500, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 7082, Download: 83086, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 7360, Download: 90087, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 7417, Download: 91845, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 7528, Download: 96378, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 7990, Download: 99794, PublicKey: "xyz"}}, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 120, Download: 169, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 122, Download: 170, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 141, Download: 176, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 142, Download: 186, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 150, Download: 194, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 151, Download: 198, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 154, Download: 215, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 3976, Download: 29392, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 4076, Download: 31561, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 4408, Download: 32317, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 4477, Download: 35529, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 4735, Download: 37798, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 5505, Download: 38365, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 5698, Download: 42931, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 513, Download: 701, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 531, Download: 702, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 540, Download: 708, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 542, Download: 721, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 544, Download: 730, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 551, Download: 738, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 554, Download: 742, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 1370, Download: 13296, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 1490, Download: 14059, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 1510, Download: 14988, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 1913, Download: 16065, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 1960, Download: 19509, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 2028, Download: 20622, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 2149, Download: 23127, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 6502, Download: 76574, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 6506, Download: 82500, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 7082, Download: 83086, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 7360, Download: 90087, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 7417, Download: 91845, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 7528, Download: 96378, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 7990, Download: 99794, PublicKey: "xyz"}}, gatherTime, nil).Times(1), ) e := ingest.NewEngine(readRestartMarkFile, readWGPeersUsage, store, zerolog.New(io.Discard)) @@ -524,6 +544,8 @@ func TestEngineSingleStaticPeerWithRestartStartingWithRestartMarkFileExistence(t ctx := context.Background() ctrl, ctx := gomock.WithContext(ctx, t) + gatherTime := time.Now() + store := mocks.NewMockStore(ctrl) gomock.InOrder( store.EXPECT().LoadBeforeRestartUsage(ctx).Return(map[string]ingest.PeerUsage{"xyz": {Upload: 1, Download: 2, PublicKey: "xyz"}}, nil).Times(1), @@ -533,41 +555,41 @@ func TestEngineSingleStaticPeerWithRestartStartingWithRestartMarkFileExistence(t store.EXPECT().LoadBeforeRestartUsage(ctx).Return(map[string]ingest.PeerUsage{"xyz": {Upload: 8556, Download: 67017, PublicKey: "xyz"}}, nil).Times(1), ) gomock.InOrder( - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 121, Download: 171, PublicKey: "xyz"}}).Return(nil).Times(1), - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 123, Download: 172, PublicKey: "xyz"}}).Return(nil).Times(1), - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 142, Download: 178, PublicKey: "xyz"}}).Return(nil).Times(1), - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 143, Download: 188, PublicKey: "xyz"}}).Return(nil).Times(1), - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 151, Download: 196, PublicKey: "xyz"}}).Return(nil).Times(1), - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 152, Download: 200, PublicKey: "xyz"}}).Return(nil).Times(1), - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 155, Download: 217, PublicKey: "xyz"}}).Return(nil).Times(1), - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 4131, Download: 29609, PublicKey: "xyz"}}).Return(nil).Times(1), - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 4231, Download: 31778, PublicKey: "xyz"}}).Return(nil).Times(1), - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 4563, Download: 32534, PublicKey: "xyz"}}).Return(nil).Times(1), - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 4632, Download: 35746, PublicKey: "xyz"}}).Return(nil).Times(1), - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 4890, Download: 38015, PublicKey: "xyz"}}).Return(nil).Times(1), - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 5660, Download: 38582, PublicKey: "xyz"}}).Return(nil).Times(1), - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 5853, Download: 43148, PublicKey: "xyz"}}).Return(nil).Times(1), - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 6366, Download: 43849, PublicKey: "xyz"}}).Return(nil).Times(1), - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 6384, Download: 43850, PublicKey: "xyz"}}).Return(nil).Times(1), - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 6393, Download: 43856, PublicKey: "xyz"}}).Return(nil).Times(1), - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 6395, Download: 43869, PublicKey: "xyz"}}).Return(nil).Times(1), - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 6397, Download: 43878, PublicKey: "xyz"}}).Return(nil).Times(1), - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 6404, Download: 43886, PublicKey: "xyz"}}).Return(nil).Times(1), - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 6407, Download: 43890, PublicKey: "xyz"}}).Return(nil).Times(1), - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 7777, Download: 57186, PublicKey: "xyz"}}).Return(nil).Times(1), - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 7897, Download: 57949, PublicKey: "xyz"}}).Return(nil).Times(1), - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 7917, Download: 58878, PublicKey: "xyz"}}).Return(nil).Times(1), - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 8320, Download: 59955, PublicKey: "xyz"}}).Return(nil).Times(1), - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 8367, Download: 63399, PublicKey: "xyz"}}).Return(nil).Times(1), - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 8435, Download: 64512, PublicKey: "xyz"}}).Return(nil).Times(1), - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 8556, Download: 67017, PublicKey: "xyz"}}).Return(nil).Times(1), - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 15058, Download: 143591, PublicKey: "xyz"}}).Return(nil).Times(1), - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 15062, Download: 149517, PublicKey: "xyz"}}).Return(nil).Times(1), - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 15638, Download: 150103, PublicKey: "xyz"}}).Return(nil).Times(1), - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 15916, Download: 157104, PublicKey: "xyz"}}).Return(nil).Times(1), - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 15973, Download: 158862, PublicKey: "xyz"}}).Return(nil).Times(1), - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 16084, Download: 163395, PublicKey: "xyz"}}).Return(nil).Times(1), - store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 16546, Download: 166811, PublicKey: "xyz"}}).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 121, Download: 171, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 123, Download: 172, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 142, Download: 178, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 143, Download: 188, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 151, Download: 196, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 152, Download: 200, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 155, Download: 217, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 4131, Download: 29609, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 4231, Download: 31778, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 4563, Download: 32534, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 4632, Download: 35746, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 4890, Download: 38015, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 5660, Download: 38582, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 5853, Download: 43148, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 6366, Download: 43849, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 6384, Download: 43850, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 6393, Download: 43856, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 6395, Download: 43869, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 6397, Download: 43878, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 6404, Download: 43886, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 6407, Download: 43890, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 7777, Download: 57186, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 7897, Download: 57949, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 7917, Download: 58878, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 8320, Download: 59955, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 8367, Download: 63399, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 8435, Download: 64512, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 8556, Download: 67017, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 15058, Download: 143591, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 15062, Download: 149517, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 15638, Download: 150103, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 15916, Download: 157104, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 15973, Download: 158862, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 16084, Download: 163395, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), + store.EXPECT().IngestUsage(ctx, []ingest.PeerUsage{{Upload: 16546, Download: 166811, PublicKey: "xyz"}}, gatherTime).Return(nil).Times(1), ) readRestartMarkFile := mocks.NewMockRestartMarkFileReadRemover(ctrl) @@ -587,41 +609,41 @@ func TestEngineSingleStaticPeerWithRestartStartingWithRestartMarkFileExistence(t readWGPeersUsage := mocks.NewMockWgPeers(ctrl) gomock.InOrder( - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 120, Download: 169, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 122, Download: 170, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 141, Download: 176, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 142, Download: 186, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 150, Download: 194, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 151, Download: 198, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 154, Download: 215, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 3976, Download: 29392, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 4076, Download: 31561, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 4408, Download: 32317, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 4477, Download: 35529, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 4735, Download: 37798, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 5505, Download: 38365, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 5698, Download: 42931, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 513, Download: 701, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 531, Download: 702, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 540, Download: 708, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 542, Download: 721, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 544, Download: 730, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 551, Download: 738, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 554, Download: 742, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 1370, Download: 13296, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 1490, Download: 14059, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 1510, Download: 14988, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 1913, Download: 16065, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 1960, Download: 19509, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 2028, Download: 20622, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 2149, Download: 23127, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 6502, Download: 76574, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 6506, Download: 82500, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 7082, Download: 83086, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 7360, Download: 90087, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 7417, Download: 91845, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 7528, Download: 96378, PublicKey: "xyz"}}, nil).Times(1), - readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 7990, Download: 99794, PublicKey: "xyz"}}, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 120, Download: 169, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 122, Download: 170, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 141, Download: 176, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 142, Download: 186, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 150, Download: 194, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 151, Download: 198, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 154, Download: 215, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 3976, Download: 29392, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 4076, Download: 31561, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 4408, Download: 32317, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 4477, Download: 35529, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 4735, Download: 37798, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 5505, Download: 38365, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 5698, Download: 42931, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 513, Download: 701, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 531, Download: 702, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 540, Download: 708, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 542, Download: 721, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 544, Download: 730, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 551, Download: 738, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 554, Download: 742, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 1370, Download: 13296, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 1490, Download: 14059, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 1510, Download: 14988, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 1913, Download: 16065, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 1960, Download: 19509, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 2028, Download: 20622, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 2149, Download: 23127, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 6502, Download: 76574, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 6506, Download: 82500, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 7082, Download: 83086, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 7360, Download: 90087, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 7417, Download: 91845, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 7528, Download: 96378, PublicKey: "xyz"}}, gatherTime, nil).Times(1), + readWGPeersUsage.EXPECT().Usage(ctx).Return([]ingest.PeerUsage{{Upload: 7990, Download: 99794, PublicKey: "xyz"}}, gatherTime, nil).Times(1), ) e := ingest.NewEngine(readRestartMarkFile, readWGPeersUsage, store, zerolog.New(io.Discard)) @@ -654,8 +676,10 @@ func TestEngineMultipleDynamicPeers(t *testing.T) { t.Parallel() ctx := context.Background() ctrl, ctx := gomock.WithContext(ctx, t) - store := mocks.NewMockStore(ctrl) + gatherTime := time.Now() + + store := mocks.NewMockStore(ctrl) gomock.InOrder( store.EXPECT().LoadBeforeRestartUsage(ctx).Return( map[string]ingest.PeerUsage{ @@ -703,6 +727,7 @@ func TestEngineMultipleDynamicPeers(t *testing.T) { {Upload: 10, Download: 30, PublicKey: "xyz"}, {Upload: 15, Download: 35, PublicKey: "abc"}, }, + gatherTime, ).Return(nil).Times(1), store.EXPECT().IngestUsage( ctx, @@ -711,6 +736,7 @@ func TestEngineMultipleDynamicPeers(t *testing.T) { {Upload: 17, Download: 53, PublicKey: "123"}, {Upload: 25, Download: 65, PublicKey: "abc"}, }, + gatherTime, ).Return(nil).Times(1), store.EXPECT().IngestUsage( ctx, @@ -718,6 +744,7 @@ func TestEngineMultipleDynamicPeers(t *testing.T) { {Upload: 6531511 + 25, Download: 55474931 + 65, PublicKey: "abc"}, {Upload: 12 + 20, Download: 33 + 60, PublicKey: "xyz"}, }, + gatherTime, ).Return(nil).Times(1), store.EXPECT().IngestUsage( ctx, @@ -727,12 +754,14 @@ func TestEngineMultipleDynamicPeers(t *testing.T) { {Upload: 128001692, Download: 186202004, PublicKey: "abc"}, {Upload: 57, Download: 153, PublicKey: "123"}, }, + gatherTime, ).Return(nil).Times(1), store.EXPECT().IngestUsage( ctx, []ingest.PeerUsage{ {Upload: 50 + 57, Download: 110 + 153, PublicKey: "123"}, }, + gatherTime, ).Return(nil).Times(1), store.EXPECT().IngestUsage( ctx, @@ -742,6 +771,7 @@ func TestEngineMultipleDynamicPeers(t *testing.T) { {Upload: 45 + 57 + 50, Download: 120 + 110 + 153, PublicKey: "123"}, {Upload: 49 + 128001692, Download: 137 + 186202004, PublicKey: "abc"}, }, + gatherTime, ).Return(nil).Times(1), store.EXPECT().IngestUsage( ctx, @@ -749,6 +779,7 @@ func TestEngineMultipleDynamicPeers(t *testing.T) { {Upload: 30, Download: 75, PublicKey: "qwe"}, {Upload: 53 + 107, Download: 132 + 263, PublicKey: "123"}, }, + gatherTime, ).Return(nil).Times(1), store.EXPECT().IngestUsage( ctx, @@ -759,6 +790,7 @@ func TestEngineMultipleDynamicPeers(t *testing.T) { {Upload: 124728866, Download: 155917550, PublicKey: "456"}, {Upload: 49 + 128001692, Download: 137 + 186202004, PublicKey: "abc"}, }, + gatherTime, ).Return(nil).Times(1), store.EXPECT().IngestUsage( ctx, @@ -767,6 +799,7 @@ func TestEngineMultipleDynamicPeers(t *testing.T) { {Upload: 50 + 40, Download: 95 + 85, PublicKey: "qwe"}, {Upload: 76 + 37 + 50, Download: 168 + 98 + 150, PublicKey: "xyz"}, }, + gatherTime, ).Return(nil).Times(1), ) @@ -788,6 +821,7 @@ func TestEngineMultipleDynamicPeers(t *testing.T) { {Upload: 10, Download: 30, PublicKey: "xyz"}, {Upload: 15, Download: 35, PublicKey: "abc"}, }, + gatherTime, nil, ).Times(1), readWGPeersUsage.EXPECT().Usage(ctx).Return( @@ -796,6 +830,7 @@ func TestEngineMultipleDynamicPeers(t *testing.T) { {Upload: 17, Download: 53, PublicKey: "123"}, {Upload: 25, Download: 65, PublicKey: "abc"}, }, + gatherTime, nil, ).Times(1), readWGPeersUsage.EXPECT().Usage(ctx).Return( @@ -803,6 +838,7 @@ func TestEngineMultipleDynamicPeers(t *testing.T) { {Upload: 6531511, Download: 55474931, PublicKey: "abc"}, {Upload: 12, Download: 33, PublicKey: "xyz"}, }, + gatherTime, nil, ).Times(1), readWGPeersUsage.EXPECT().Usage(ctx).Return( @@ -812,16 +848,19 @@ func TestEngineMultipleDynamicPeers(t *testing.T) { {Upload: 128001667, Download: 186201939, PublicKey: "abc"}, {Upload: 40, Download: 100, PublicKey: "123"}, }, + gatherTime, nil, ).Times(1), readWGPeersUsage.EXPECT().Usage(ctx).Return( []ingest.PeerUsage{ {Upload: 50, Download: 110, PublicKey: "123"}, }, + gatherTime, nil, ).Times(1), readWGPeersUsage.EXPECT().Usage(ctx).Return( []ingest.PeerUsage{}, + gatherTime, nil, ).Times(1), readWGPeersUsage.EXPECT().Usage(ctx).Return( @@ -831,6 +870,7 @@ func TestEngineMultipleDynamicPeers(t *testing.T) { {Upload: 45, Download: 120, PublicKey: "123"}, {Upload: 49, Download: 137, PublicKey: "abc"}, }, + gatherTime, nil, ).Times(1), readWGPeersUsage.EXPECT().Usage(ctx).Return( @@ -838,6 +878,7 @@ func TestEngineMultipleDynamicPeers(t *testing.T) { {Upload: 30, Download: 75, PublicKey: "qwe"}, {Upload: 53, Download: 132, PublicKey: "123"}, }, + gatherTime, nil, ).Times(1), readWGPeersUsage.EXPECT().Usage(ctx).Return( @@ -848,6 +889,7 @@ func TestEngineMultipleDynamicPeers(t *testing.T) { {Upload: 124728866, Download: 155917550, PublicKey: "456"}, {Upload: 49, Download: 137, PublicKey: "abc"}, }, + gatherTime, nil, ).Times(1), readWGPeersUsage.EXPECT().Usage(ctx).Return( @@ -856,6 +898,7 @@ func TestEngineMultipleDynamicPeers(t *testing.T) { {Upload: 50, Download: 95, PublicKey: "qwe"}, {Upload: 76, Download: 168, PublicKey: "xyz"}, }, + gatherTime, nil, ).Times(1), ) diff --git a/ingest/mocks/ingest.go b/ingest/mocks/ingest.go index 93ce58e..06dd7a5 100644 --- a/ingest/mocks/ingest.go +++ b/ingest/mocks/ingest.go @@ -7,6 +7,7 @@ package mocks import ( context "context" reflect "reflect" + time "time" gomock "github.com/golang/mock/gomock" ingest "github.com/xeptore/wireuse/ingest" @@ -36,17 +37,17 @@ func (m *MockStore) EXPECT() *MockStoreMockRecorder { } // IngestUsage mocks base method. -func (m *MockStore) IngestUsage(ctx context.Context, peersUsage []ingest.PeerUsage) error { +func (m *MockStore) IngestUsage(ctx context.Context, peersUsage []ingest.PeerUsage, gatheredAt time.Time) error { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "IngestUsage", ctx, peersUsage) + ret := m.ctrl.Call(m, "IngestUsage", ctx, peersUsage, gatheredAt) ret0, _ := ret[0].(error) return ret0 } // IngestUsage indicates an expected call of IngestUsage. -func (mr *MockStoreMockRecorder) IngestUsage(ctx, peersUsage interface{}) *gomock.Call { +func (mr *MockStoreMockRecorder) IngestUsage(ctx, peersUsage, gatheredAt interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IngestUsage", reflect.TypeOf((*MockStore)(nil).IngestUsage), ctx, peersUsage) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IngestUsage", reflect.TypeOf((*MockStore)(nil).IngestUsage), ctx, peersUsage, gatheredAt) } // LoadBeforeRestartUsage mocks base method. @@ -88,12 +89,13 @@ func (m *MockWgPeers) EXPECT() *MockWgPeersMockRecorder { } // Usage mocks base method. -func (m *MockWgPeers) Usage(ctx context.Context) ([]ingest.PeerUsage, error) { +func (m *MockWgPeers) Usage(ctx context.Context) ([]ingest.PeerUsage, time.Time, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Usage", ctx) ret0, _ := ret[0].([]ingest.PeerUsage) - ret1, _ := ret[1].(error) - return ret0, ret1 + ret1, _ := ret[1].(time.Time) + ret2, _ := ret[2].(error) + return ret0, ret1, ret2 } // Usage indicates an expected call of Usage.