Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
satellite/audit: implement rangedloop observer
This change implements the ranged loop observer to replace the audit chore that builds the audit queue. The strategy employed by this change is to use a collector for each segment range to build separate per-node segment reservoirs that are then merge them during the join step. In previous observer migrations, there were only a handful of tests so the strategy was to duplicate them. In this package, there are dozens of tests that utilize the chore. To reduce code churn and maintenance burden until the chore is removed, this change introduces a helper that runs tests under both the chore and observer, providing a pair of functions that can be used to pause or run the queueing function. #5232 Change-Id: I8bb4b4e55cf98b1aac9f26307e3a9a355cb3f506
- Loading branch information
Showing
12 changed files
with
441 additions
and
156 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Copyright (C) 2021 Storj Labs, Inc. | ||
// See LICENSE for copying information. | ||
|
||
package audit_test | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"go.uber.org/zap" | ||
|
||
"storj.io/common/testcontext" | ||
"storj.io/storj/private/testplanet" | ||
"storj.io/storj/satellite" | ||
) | ||
|
||
type pauseQueueingFunc = func(satellite *testplanet.Satellite) | ||
type runQueueingOnceFunc = func(ctx context.Context, satellite *testplanet.Satellite) error | ||
|
||
// testWithChoreAndObserver runs an audit test for both the chore and observer. | ||
// It provides functions that the test can use to pause and run the queueing | ||
// done by the chore or observer. | ||
func testWithChoreAndObserver(t *testing.T, planetConfig testplanet.Config, run func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet, pauseQueueing pauseQueueingFunc, runQueueingOnce runQueueingOnceFunc)) { | ||
t.Run("Chore", func(t *testing.T) { | ||
planetConfig := planetConfig | ||
testplanet.Run(t, planetConfig, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) { | ||
t.Helper() | ||
run(t, ctx, planet, | ||
func(satellite *testplanet.Satellite) { | ||
satellite.Audit.Chore.Loop.Pause() | ||
}, | ||
func(ctx context.Context, satellite *testplanet.Satellite) error { | ||
satellite.Audit.Chore.Loop.TriggerWait() | ||
return nil | ||
}, | ||
) | ||
}) | ||
}) | ||
|
||
t.Run("Observer", func(t *testing.T) { | ||
planetConfig := planetConfig | ||
reconfigureSatellite := planetConfig.Reconfigure.Satellite | ||
planetConfig.Reconfigure.Satellite = func(log *zap.Logger, index int, config *satellite.Config) { | ||
if reconfigureSatellite != nil { | ||
reconfigureSatellite(log, index, config) | ||
} | ||
config.Audit.UseRangedLoop = true | ||
} | ||
testplanet.Run(t, planetConfig, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) { | ||
t.Helper() | ||
run(t, ctx, planet, | ||
func(satellite *testplanet.Satellite) {}, | ||
func(ctx context.Context, satellite *testplanet.Satellite) error { | ||
_, err := satellite.RangedLoop.RangedLoop.Service.RunOnce(ctx) | ||
return err | ||
}, | ||
) | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.