From 94f8ad5e4c208b91c0c3f081be7048635ca3ff34 Mon Sep 17 00:00:00 2001 From: illia-li Date: Mon, 10 Jul 2023 13:12:17 -0400 Subject: [PATCH 1/2] add(store): makes Check func do queries on test and oracle stores parallel --- pkg/store/store.go | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/pkg/store/store.go b/pkg/store/store.go index 267c6d50..c98f7035 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" @@ -177,13 +178,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 From 7c33379b5a2b6ef7c04cc663fd5e51fb2d50eb33 Mon Sep 17 00:00:00 2001 From: illia-li Date: Mon, 10 Jul 2023 13:59:02 -0400 Subject: [PATCH 2/2] add(store): makes Mutate func do queries on test and oracle stores parallel --- pkg/store/store.go | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/pkg/store/store.go b/pkg/store/store.go index c98f7035..24ecbd68 100644 --- a/pkg/store/store.go +++ b/pkg/store/store.go @@ -162,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 } - return mutate(ctx, ds.testStore, builder, values...) + 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 nil } func mutate(ctx context.Context, s storeLoader, builder qb.Builder, values ...interface{}) error {