[bugfix] Start + stop caches properly for testrig + pruning (#1804)

* [bugfix] Start + stop caches properly for testrig + pruning

* go fmt ./...
This commit is contained in:
tobi 2023-05-21 14:44:10 +02:00 committed by GitHub
parent 99ddaba57e
commit 68e54cbaa4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 6 deletions

View file

@ -37,7 +37,10 @@ type prune struct {
func setupPrune(ctx context.Context) (*prune, error) { func setupPrune(ctx context.Context) (*prune, error) {
var state state.State var state state.State
state.Caches.Init() state.Caches.Init()
state.Caches.Start()
state.Workers.Start() state.Workers.Start()
dbService, err := bundb.NewBunDBService(ctx, &state) dbService, err := bundb.NewBunDBService(ctx, &state)
@ -51,8 +54,6 @@ func setupPrune(ctx context.Context) (*prune, error) {
if err != nil { if err != nil {
return nil, fmt.Errorf("error creating storage backend: %w", err) return nil, fmt.Errorf("error creating storage backend: %w", err)
} }
state.DB = dbService
state.Storage = storage state.Storage = storage
//nolint:contextcheck //nolint:contextcheck
@ -75,8 +76,8 @@ func (p *prune) shutdown(ctx context.Context) error {
return fmt.Errorf("error closing dbservice: %w", err) return fmt.Errorf("error closing dbservice: %w", err)
} }
p.state.Caches.Stop()
p.state.Workers.Stop() p.state.Workers.Stop()
p.state.Caches.Stop()
return nil return nil
} }

View file

@ -56,12 +56,14 @@ var Start action.GTSAction = func(ctx context.Context) error {
return fmt.Errorf("error initializing tracing: %w", err) return fmt.Errorf("error initializing tracing: %w", err)
} }
// Initialize caches // Initialize caches and database
state.Caches.Init() state.DB = testrig.NewTestDB(&state)
// New test db inits caches so we don't need to do
// that twice, we can just start the initialized caches.
state.Caches.Start() state.Caches.Start()
defer state.Caches.Stop() defer state.Caches.Stop()
state.DB = testrig.NewTestDB(&state)
testrig.StandardDBSetup(state.DB, nil) testrig.StandardDBSetup(state.DB, nil)
if os.Getenv("GTS_STORAGE_BACKEND") == "s3" { if os.Getenv("GTS_STORAGE_BACKEND") == "s3" {