diff --git a/pkg/store/store.go b/pkg/store/store.go index 267c6d50..24ecbd68 100644 --- a/pkg/store/store.go +++ b/pkg/store/store.go @@ -20,6 +20,7 @@ import ( "math/big" "os" "sort" + "sync" "time" "go.uber.org/zap" @@ -161,12 +162,25 @@ func (ds delegatingStore) Create(ctx context.Context, testBuilder, oracleBuilder } func (ds delegatingStore) Mutate(ctx context.Context, builder qb.Builder, values ...interface{}) error { - if err := mutate(ctx, ds.oracleStore, builder, values...); err != nil { + var testErr error + var wg sync.WaitGroup + wg.Add(1) + go func() { + testErr = mutate(ctx, ds.testStore, builder, values...) + wg.Done() + }() + if oracleErr := mutate(ctx, ds.oracleStore, builder, values...); oracleErr != nil { // Oracle failed, transition cannot take place - ds.logger.Info("oracle failed mutation, transition to next state impossible so continuing with next mutation", zap.Error(err)) - return nil + ds.logger.Info("oracle store failed mutation, transition to next state impossible so continuing with next mutation", zap.Error(oracleErr)) + return oracleErr + } + wg.Wait() + if testErr != nil { + // Test store failed, transition cannot take place + ds.logger.Info("test store failed mutation, transition to next state impossible so continuing with next mutation", zap.Error(testErr)) + return testErr } - return mutate(ctx, ds.testStore, builder, values...) + return nil } func mutate(ctx context.Context, s storeLoader, builder qb.Builder, values ...interface{}) error { @@ -177,13 +191,21 @@ func mutate(ctx context.Context, s storeLoader, builder qb.Builder, values ...in } func (ds delegatingStore) Check(ctx context.Context, table *typedef.Table, builder qb.Builder, values ...interface{}) error { - testRows, err := ds.testStore.load(ctx, builder, values) - if err != nil { - return errors.Wrapf(err, "unable to load check data from the test store") + var testRows, oracleRows []map[string]interface{} + var testErr, oracleErr error + var wg sync.WaitGroup + wg.Add(1) + go func() { + testRows, testErr = ds.testStore.load(ctx, builder, values) + wg.Done() + }() + oracleRows, oracleErr = ds.oracleStore.load(ctx, builder, values) + if oracleErr != nil { + return errors.Wrapf(oracleErr, "unable to load check data from the oracle store") } - oracleRows, err := ds.oracleStore.load(ctx, builder, values) - if err != nil { - return errors.Wrapf(err, "unable to load check data from the oracle store") + wg.Wait() + if testErr != nil { + return errors.Wrapf(testErr, "unable to load check data from the test store") } if !ds.validations { return nil