Skip to content

Commit

Permalink
vms/platformvm: Move vm.Shutdown call in tests to t.Cleanup (#2669
Browse files Browse the repository at this point in the history
)
  • Loading branch information
dhrubabasu authored Jan 26, 2024
1 parent 5c2def7 commit b81b936
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 178 deletions.
44 changes: 0 additions & 44 deletions vms/platformvm/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,6 @@ func TestExportKey(t *testing.T) {

service, _ := defaultService(t)
defaultAddress(t, service)
defer func() {
service.vm.ctx.Lock.Lock()
require.NoError(service.vm.Shutdown(context.Background()))
service.vm.ctx.Lock.Unlock()
}()

reply := ExportKeyReply{}
require.NoError(service.ExportKey(nil, &args, &reply))
Expand All @@ -152,11 +147,6 @@ func TestImportKey(t *testing.T) {
require.NoError(stdjson.Unmarshal([]byte(jsonString), &args))

service, _ := defaultService(t)
defer func() {
service.vm.ctx.Lock.Lock()
require.NoError(service.vm.Shutdown(context.Background()))
service.vm.ctx.Lock.Unlock()
}()

reply := api.JSONAddress{}
require.NoError(service.ImportKey(nil, &args, &reply))
Expand All @@ -169,11 +159,6 @@ func TestGetTxStatus(t *testing.T) {
service, mutableSharedMemory := defaultService(t)
defaultAddress(t, service)
service.vm.ctx.Lock.Lock()
defer func() {
service.vm.ctx.Lock.Lock()
require.NoError(service.vm.Shutdown(context.Background()))
service.vm.ctx.Lock.Unlock()
}()

recipientKey, err := secp256k1.NewPrivateKey()
require.NoError(err)
Expand Down Expand Up @@ -374,10 +359,6 @@ func TestGetTx(t *testing.T) {
require.NoError(err)
require.Equal(expectedTxJSON, []byte(response.Tx))
}

service.vm.ctx.Lock.Lock()
require.NoError(service.vm.Shutdown(context.Background()))
service.vm.ctx.Lock.Unlock()
})
}
}
Expand All @@ -387,11 +368,6 @@ func TestGetBalance(t *testing.T) {
require := require.New(t)
service, _ := defaultService(t)
defaultAddress(t, service)
defer func() {
service.vm.ctx.Lock.Lock()
require.NoError(service.vm.Shutdown(context.Background()))
service.vm.ctx.Lock.Unlock()
}()

// Ensure GetStake is correct for each of the genesis validators
genesis, _ := defaultGenesis(t, service.vm.ctx.AVAXAssetID)
Expand Down Expand Up @@ -421,11 +397,6 @@ func TestGetStake(t *testing.T) {
require := require.New(t)
service, _ := defaultService(t)
defaultAddress(t, service)
defer func() {
service.vm.ctx.Lock.Lock()
require.NoError(service.vm.Shutdown(context.Background()))
service.vm.ctx.Lock.Unlock()
}()

// Ensure GetStake is correct for each of the genesis validators
genesis, _ := defaultGenesis(t, service.vm.ctx.AVAXAssetID)
Expand Down Expand Up @@ -597,11 +568,6 @@ func TestGetCurrentValidators(t *testing.T) {
require := require.New(t)
service, _ := defaultService(t)
defaultAddress(t, service)
defer func() {
service.vm.ctx.Lock.Lock()
require.NoError(service.vm.Shutdown(context.Background()))
service.vm.ctx.Lock.Unlock()
}()

genesis, _ := defaultGenesis(t, service.vm.ctx.AVAXAssetID)

Expand Down Expand Up @@ -727,11 +693,6 @@ func TestGetCurrentValidators(t *testing.T) {
func TestGetTimestamp(t *testing.T) {
require := require.New(t)
service, _ := defaultService(t)
defer func() {
service.vm.ctx.Lock.Lock()
require.NoError(service.vm.Shutdown(context.Background()))
service.vm.ctx.Lock.Unlock()
}()

reply := GetTimestampReply{}
require.NoError(service.GetTimestamp(nil, nil, &reply))
Expand Down Expand Up @@ -769,11 +730,6 @@ func TestGetBlock(t *testing.T) {
require := require.New(t)
service, _ := defaultService(t)
service.vm.ctx.Lock.Lock()
defer func() {
service.vm.ctx.Lock.Lock()
require.NoError(service.vm.Shutdown(context.Background()))
service.vm.ctx.Lock.Unlock()
}()

service.vm.Config.CreateAssetTxFee = 100 * defaultTxFee

Expand Down
69 changes: 14 additions & 55 deletions vms/platformvm/vm_regression_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,7 @@ func TestAddDelegatorTxOverDelegatedRegression(t *testing.T) {
require := require.New(t)
vm, _, _ := defaultVM(t, cortinaFork)
vm.ctx.Lock.Lock()
defer func() {
vm.ctx.Lock.Lock()
require.NoError(vm.Shutdown(context.Background()))
vm.ctx.Lock.Unlock()
}()
defer vm.ctx.Lock.Unlock()

validatorStartTime := vm.clock.Time().Add(executor.SyncBound).Add(1 * time.Second)
validatorEndTime := validatorStartTime.Add(360 * 24 * time.Hour)
Expand Down Expand Up @@ -174,6 +170,7 @@ func TestAddDelegatorTxOverDelegatedRegression(t *testing.T) {
vm.ctx.Lock.Unlock()
err = vm.issueTx(context.Background(), addThirdDelegatorTx)
require.ErrorIs(err, executor.ErrOverDelegated)
vm.ctx.Lock.Lock()
}

func TestAddDelegatorTxHeapCorruption(t *testing.T) {
Expand Down Expand Up @@ -219,10 +216,7 @@ func TestAddDelegatorTxHeapCorruption(t *testing.T) {
vm.ApricotPhase3Time = test.ap3Time

vm.ctx.Lock.Lock()
defer func() {
require.NoError(vm.Shutdown(context.Background()))
vm.ctx.Lock.Unlock()
}()
defer vm.ctx.Lock.Unlock()

key, err := secp256k1.NewPrivateKey()
require.NoError(err)
Expand Down Expand Up @@ -487,10 +481,7 @@ func TestRejectedStateRegressionInvalidValidatorTimestamp(t *testing.T) {

vm, baseDB, mutableSharedMemory := defaultVM(t, cortinaFork)
vm.ctx.Lock.Lock()
defer func() {
require.NoError(vm.Shutdown(context.Background()))
vm.ctx.Lock.Unlock()
}()
defer vm.ctx.Lock.Unlock()

nodeID := ids.GenerateTestNodeID()
newValidatorStartTime := vm.clock.Time().Add(executor.SyncBound).Add(1 * time.Second)
Expand Down Expand Up @@ -695,10 +686,7 @@ func TestRejectedStateRegressionInvalidValidatorReward(t *testing.T) {

vm, baseDB, mutableSharedMemory := defaultVM(t, cortinaFork)
vm.ctx.Lock.Lock()
defer func() {
require.NoError(vm.Shutdown(context.Background()))
vm.ctx.Lock.Unlock()
}()
defer vm.ctx.Lock.Unlock()

vm.state.SetCurrentSupply(constants.PrimaryNetworkID, defaultRewardConfig.SupplyCap/2)

Expand Down Expand Up @@ -1010,10 +998,7 @@ func TestValidatorSetAtCacheOverwriteRegression(t *testing.T) {

vm, _, _ := defaultVM(t, cortinaFork)
vm.ctx.Lock.Lock()
defer func() {
require.NoError(vm.Shutdown(context.Background()))
vm.ctx.Lock.Unlock()
}()
defer vm.ctx.Lock.Unlock()

currentHeight, err := vm.GetCurrentHeight(context.Background())
require.NoError(err)
Expand Down Expand Up @@ -1148,14 +1133,8 @@ func TestAddDelegatorTxAddBeforeRemove(t *testing.T) {
delegator2Stake := defaultMaxValidatorStake - validatorStake

vm, _, _ := defaultVM(t, cortinaFork)

vm.ctx.Lock.Lock()
defer func() {
vm.ctx.Lock.Lock()
require.NoError(vm.Shutdown(context.Background()))

vm.ctx.Lock.Unlock()
}()
defer vm.ctx.Lock.Unlock()

key, err := secp256k1.NewPrivateKey()
require.NoError(err)
Expand Down Expand Up @@ -1230,6 +1209,7 @@ func TestAddDelegatorTxAddBeforeRemove(t *testing.T) {
vm.ctx.Lock.Unlock()
err = vm.issueTx(context.Background(), addSecondDelegatorTx)
require.ErrorIs(err, executor.ErrOverDelegated)
vm.ctx.Lock.Lock()
}

func TestRemovePermissionedValidatorDuringPendingToCurrentTransitionNotTracked(t *testing.T) {
Expand All @@ -1239,12 +1219,8 @@ func TestRemovePermissionedValidatorDuringPendingToCurrentTransitionNotTracked(t
validatorEndTime := validatorStartTime.Add(360 * 24 * time.Hour)

vm, _, _ := defaultVM(t, cortinaFork)

vm.ctx.Lock.Lock()
defer func() {
require.NoError(vm.Shutdown(context.Background()))
vm.ctx.Lock.Unlock()
}()
defer vm.ctx.Lock.Unlock()

key, err := secp256k1.NewPrivateKey()
require.NoError(err)
Expand Down Expand Up @@ -1364,13 +1340,8 @@ func TestRemovePermissionedValidatorDuringPendingToCurrentTransitionTracked(t *t
validatorEndTime := validatorStartTime.Add(360 * 24 * time.Hour)

vm, _, _ := defaultVM(t, cortinaFork)

vm.ctx.Lock.Lock()
defer func() {
require.NoError(vm.Shutdown(context.Background()))

vm.ctx.Lock.Unlock()
}()
defer vm.ctx.Lock.Unlock()

key, err := secp256k1.NewPrivateKey()
require.NoError(err)
Expand Down Expand Up @@ -1474,10 +1445,7 @@ func TestSubnetValidatorBLSKeyDiffAfterExpiry(t *testing.T) {
require := require.New(t)
vm, _, _ := defaultVM(t, cortinaFork)
vm.ctx.Lock.Lock()
defer func() {
require.NoError(vm.Shutdown(context.Background()))
vm.ctx.Lock.Unlock()
}()
defer vm.ctx.Lock.Unlock()

subnetID := testSubnet1.TxID

Expand Down Expand Up @@ -1762,10 +1730,7 @@ func TestPrimaryNetworkValidatorPopulatedToEmptyBLSKeyDiff(t *testing.T) {
require := require.New(t)
vm, _, _ := defaultVM(t, cortinaFork)
vm.ctx.Lock.Lock()
defer func() {
require.NoError(vm.Shutdown(context.Background()))
vm.ctx.Lock.Unlock()
}()
defer vm.ctx.Lock.Unlock()

// setup time
currentTime := defaultGenesisTime
Expand Down Expand Up @@ -1925,10 +1890,7 @@ func TestSubnetValidatorPopulatedToEmptyBLSKeyDiff(t *testing.T) {
require := require.New(t)
vm, _, _ := defaultVM(t, cortinaFork)
vm.ctx.Lock.Lock()
defer func() {
require.NoError(vm.Shutdown(context.Background()))
vm.ctx.Lock.Unlock()
}()
defer vm.ctx.Lock.Unlock()

subnetID := testSubnet1.TxID

Expand Down Expand Up @@ -2142,10 +2104,7 @@ func TestSubnetValidatorSetAfterPrimaryNetworkValidatorRemoval(t *testing.T) {
require := require.New(t)
vm, _, _ := defaultVM(t, cortinaFork)
vm.ctx.Lock.Lock()
defer func() {
require.NoError(vm.Shutdown(context.Background()))
vm.ctx.Lock.Unlock()
}()
defer vm.ctx.Lock.Unlock()

subnetID := testSubnet1.TxID

Expand Down
Loading

0 comments on commit b81b936

Please sign in to comment.