From 67e3cb8bbe9150f30ead7e00c2ea83c5736f9c26 Mon Sep 17 00:00:00 2001 From: Darioush Jalali Date: Sat, 27 Jan 2024 18:30:07 -0800 Subject: [PATCH 1/2] testing suggestion --- vms/platformvm/vm_regression_test.go | 35 ++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/vms/platformvm/vm_regression_test.go b/vms/platformvm/vm_regression_test.go index 0a87758fdb1b..7c35b0b9ac0a 100644 --- a/vms/platformvm/vm_regression_test.go +++ b/vms/platformvm/vm_regression_test.go @@ -2245,21 +2245,34 @@ func TestValidatorSetRaceCondition(t *testing.T) { protocolAppRequestBytest, ) - var eg errgroup.Group - for i := 0; i < 100; i++ { + sendAppRequest := func() error { + return vm.AppRequest( + context.Background(), + nodeID, + 0, + time.Now().Add(time.Hour), + appRequestBytes, + ) + } + + var ( + eg errgroup.Group + ctx, cancel = context.WithCancel(context.Background()) + ) + // keep 10 workers running + for i := 0; i < 10; i++ { eg.Go(func() error { - return vm.AppRequest( - context.Background(), - nodeID, - 0, - time.Now().Add(time.Hour), - appRequestBytes, - ) + for ctx.Err() == nil { + if err := sendAppRequest(); err != nil { + return err + } + } + return nil }) } // If the validator set lock isn't held, the race detector should fail here. - for i := uint64(0); i < 100; i++ { + for i := uint64(0); i < 1000; i++ { blk, err := block.NewBanffStandardBlock( time.Now(), vm.state.GetLastAccepted(), @@ -2276,6 +2289,8 @@ func TestValidatorSetRaceCondition(t *testing.T) { // If the validator set lock is grabbed, we need to make sure to release the // lock to avoid a deadlock. vm.ctx.Lock.Unlock() + cancel() // stop and wait for workers + require.NoError(eg.Wait()) vm.ctx.Lock.Lock() } From 9026658573f22c42b7b218642fe624823608a974 Mon Sep 17 00:00:00 2001 From: Stephen Buttolph Date: Sun, 28 Jan 2024 10:06:02 -0500 Subject: [PATCH 2/2] nits --- vms/platformvm/vm_regression_test.go | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/vms/platformvm/vm_regression_test.go b/vms/platformvm/vm_regression_test.go index 7c35b0b9ac0a..f4e84d0776ae 100644 --- a/vms/platformvm/vm_regression_test.go +++ b/vms/platformvm/vm_regression_test.go @@ -2245,16 +2245,6 @@ func TestValidatorSetRaceCondition(t *testing.T) { protocolAppRequestBytest, ) - sendAppRequest := func() error { - return vm.AppRequest( - context.Background(), - nodeID, - 0, - time.Now().Add(time.Hour), - appRequestBytes, - ) - } - var ( eg errgroup.Group ctx, cancel = context.WithCancel(context.Background()) @@ -2263,7 +2253,14 @@ func TestValidatorSetRaceCondition(t *testing.T) { for i := 0; i < 10; i++ { eg.Go(func() error { for ctx.Err() == nil { - if err := sendAppRequest(); err != nil { + err := vm.AppRequest( + context.Background(), + nodeID, + 0, + time.Now().Add(time.Hour), + appRequestBytes, + ) + if err != nil { return err } } @@ -2290,7 +2287,6 @@ func TestValidatorSetRaceCondition(t *testing.T) { // lock to avoid a deadlock. vm.ctx.Lock.Unlock() cancel() // stop and wait for workers - require.NoError(eg.Wait()) vm.ctx.Lock.Lock() }