From 2bb2190b3399a0c2c661fb11d401babaa40560be Mon Sep 17 00:00:00 2001 From: Chris Schinnerl Date: Wed, 31 Jul 2024 16:15:02 +0200 Subject: [PATCH] stores: fix TestBusRecordedMetrics --- stores/metadata.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/stores/metadata.go b/stores/metadata.go index da1bf1496..21dca732a 100644 --- a/stores/metadata.go +++ b/stores/metadata.go @@ -602,6 +602,7 @@ func (s *SQLStore) SetContractSet(ctx context.Context, name string, contractIds var diff []types.FileContractID var nContractsAfter int err := s.db.Transaction(ctx, func(tx sql.DatabaseTx) error { + // build diff prevContracts, err := tx.Contracts(ctx, api.ContractsOpts{ContractSet: name}) if err != nil && !errors.Is(err, api.ErrContractSetNotFound) { return fmt.Errorf("failed to fetch contracts: %w", err) @@ -617,7 +618,17 @@ func (s *SQLStore) SetContractSet(ctx context.Context, name string, contractIds for fcid := range wanted { diff = append(diff, fcid) // addition } - return tx.SetContractSet(ctx, name, contractIds) + // update contract set + if err := tx.SetContractSet(ctx, name, contractIds); err != nil { + return fmt.Errorf("failed to set contract set: %w", err) + } + // fetch contracts after update + afterContracts, err := tx.Contracts(ctx, api.ContractsOpts{ContractSet: name}) + if err != nil { + return fmt.Errorf("failed to fetch contracts after update: %w", err) + } + nContractsAfter = len(afterContracts) + return nil }) if err != nil { return fmt.Errorf("failed to set contract set: %w", err)