vms: Ensure all avm.VM instances in tests get shutdown

I suspect these could be simplified/made more uniform, but I don't think
I fully understand the locking semantics.
This commit is contained in:
Alex Willmer 2020-04-19 14:21:28 +01:00
parent de3fd2915b
commit 2eb8add469
6 changed files with 32 additions and 0 deletions

View File

@ -624,6 +624,7 @@ func TestBaseTxSyntacticVerifyUninitialized(t *testing.T) {
func TestBaseTxSemanticVerify(t *testing.T) {
genesisBytes, _, vm := GenesisVM(t)
defer ctx.Lock.Unlock()
defer vm.Shutdown()
genesisTx := GetFirstTxFromGenesisTest(genesisBytes, t)
@ -688,6 +689,7 @@ func TestBaseTxSemanticVerify(t *testing.T) {
func TestBaseTxSemanticVerifyUnknownFx(t *testing.T) {
genesisBytes, _, vm := GenesisVM(t)
defer ctx.Lock.Unlock()
defer vm.Shutdown()
vm.codec.RegisterType(&ava.TestVerifiable{})
@ -737,6 +739,7 @@ func TestBaseTxSemanticVerifyUnknownFx(t *testing.T) {
func TestBaseTxSemanticVerifyWrongAssetID(t *testing.T) {
genesisBytes, _, vm := GenesisVM(t)
defer ctx.Lock.Unlock()
defer vm.Shutdown()
vm.codec.RegisterType(&ava.TestVerifiable{})
@ -809,6 +812,7 @@ func TestBaseTxSemanticVerifyUnauthorizedFx(t *testing.T) {
defer ctx.Lock.Unlock()
vm := &VM{}
defer vm.Shutdown()
err := vm.Initialize(
ctx,
memdb.New(),
@ -894,6 +898,7 @@ func TestBaseTxSemanticVerifyUnauthorizedFx(t *testing.T) {
func TestBaseTxSemanticVerifyInvalidSignature(t *testing.T) {
genesisBytes, _, vm := GenesisVM(t)
defer ctx.Lock.Unlock()
defer vm.Shutdown()
genesisTx := GetFirstTxFromGenesisTest(genesisBytes, t)
@ -945,6 +950,7 @@ func TestBaseTxSemanticVerifyInvalidSignature(t *testing.T) {
func TestBaseTxSemanticVerifyMissingUTXO(t *testing.T) {
genesisBytes, _, vm := GenesisVM(t)
defer ctx.Lock.Unlock()
defer vm.Shutdown()
genesisTx := GetFirstTxFromGenesisTest(genesisBytes, t)
@ -1009,6 +1015,7 @@ func TestBaseTxSemanticVerifyMissingUTXO(t *testing.T) {
func TestBaseTxSemanticVerifyInvalidUTXO(t *testing.T) {
genesisBytes, _, vm := GenesisVM(t)
defer ctx.Lock.Unlock()
defer vm.Shutdown()
genesisTx := GetFirstTxFromGenesisTest(genesisBytes, t)
@ -1141,6 +1148,7 @@ func TestBaseTxSemanticVerifyPendingInvalidUTXO(t *testing.T) {
ctx.Lock.Lock()
defer ctx.Lock.Unlock()
defer vm.Shutdown()
vm.PendingTxs()
@ -1272,6 +1280,7 @@ func TestBaseTxSemanticVerifyPendingWrongAssetID(t *testing.T) {
ctx.Lock.Lock()
defer ctx.Lock.Unlock()
defer vm.Shutdown()
vm.PendingTxs()
@ -1437,6 +1446,7 @@ func TestBaseTxSemanticVerifyPendingUnauthorizedFx(t *testing.T) {
ctx.Lock.Lock()
defer ctx.Lock.Unlock()
defer vm.Shutdown()
vm.PendingTxs()
@ -1586,6 +1596,7 @@ func TestBaseTxSemanticVerifyPendingInvalidSignature(t *testing.T) {
ctx.Lock.Lock()
defer ctx.Lock.Unlock()
defer vm.Shutdown()
vm.PendingTxs()

View File

@ -217,6 +217,7 @@ func TestIssueExportTx(t *testing.T) {
ctx.Lock.Lock()
defer ctx.Lock.Unlock()
defer vm.Shutdown()
txs := vm.PendingTxs()
if len(txs) != 1 {
@ -350,6 +351,7 @@ func TestClearForceAcceptedExportTx(t *testing.T) {
ctx.Lock.Lock()
defer ctx.Lock.Unlock()
defer vm.Shutdown()
txs := vm.PendingTxs()
if len(txs) != 1 {

View File

@ -222,6 +222,7 @@ func TestIssueImportTx(t *testing.T) {
}
ctx.Lock.Unlock()
defer func() { ctx.Lock.Lock(); vm.Shutdown(); ctx.Lock.Unlock() }()
msg := <-issuer
if msg != common.PendingTxs {
@ -265,6 +266,7 @@ func TestForceAcceptImportTx(t *testing.T) {
defer ctx.Lock.Unlock()
vm := &VM{platform: platformID}
defer vm.Shutdown()
err := vm.Initialize(
ctx,
memdb.New(),

View File

@ -18,6 +18,8 @@ import (
func TestPrefixedSetsAndGets(t *testing.T) {
_, _, vm := GenesisVM(t)
ctx.Lock.Unlock()
defer func() { ctx.Lock.Lock(); vm.Shutdown(); ctx.Lock.Unlock() }()
state := vm.state
vm.codec.RegisterType(&ava.TestVerifiable{})
@ -113,6 +115,8 @@ func TestPrefixedSetsAndGets(t *testing.T) {
func TestPrefixedFundingNoAddresses(t *testing.T) {
_, _, vm := GenesisVM(t)
ctx.Lock.Unlock()
defer func() { ctx.Lock.Lock(); vm.Shutdown(); ctx.Lock.Unlock() }()
state := vm.state
vm.codec.RegisterType(&ava.TestVerifiable{})
@ -137,6 +141,8 @@ func TestPrefixedFundingNoAddresses(t *testing.T) {
func TestPrefixedFundingAddresses(t *testing.T) {
_, _, vm := GenesisVM(t)
ctx.Lock.Unlock()
defer func() { ctx.Lock.Lock(); vm.Shutdown(); ctx.Lock.Unlock() }()
state := vm.state
vm.codec.RegisterType(&testAddressable{})

View File

@ -16,6 +16,7 @@ import (
func TestStateIDs(t *testing.T) {
_, _, vm := GenesisVM(t)
defer func() { ctx.Lock.Lock(); vm.Shutdown(); ctx.Lock.Unlock() }()
ctx.Lock.Unlock()
state := vm.state.state
@ -126,6 +127,7 @@ func TestStateIDs(t *testing.T) {
func TestStateStatuses(t *testing.T) {
_, _, vm := GenesisVM(t)
defer func() { ctx.Lock.Lock(); vm.Shutdown(); ctx.Lock.Unlock() }()
ctx.Lock.Unlock()
state := vm.state.state
@ -175,6 +177,7 @@ func TestStateStatuses(t *testing.T) {
func TestStateUTXOs(t *testing.T) {
_, _, vm := GenesisVM(t)
defer func() { ctx.Lock.Lock(); vm.Shutdown(); ctx.Lock.Unlock() }()
ctx.Lock.Unlock()
state := vm.state.state
@ -246,6 +249,7 @@ func TestStateUTXOs(t *testing.T) {
func TestStateTXs(t *testing.T) {
_, _, vm := GenesisVM(t)
defer func() { ctx.Lock.Lock(); vm.Shutdown(); ctx.Lock.Unlock() }()
ctx.Lock.Unlock()
state := vm.state.state

View File

@ -396,6 +396,7 @@ func TestInvalidGenesis(t *testing.T) {
defer ctx.Lock.Unlock()
vm := &VM{}
defer vm.Shutdown()
err := vm.Initialize(
/*context=*/ ctx,
/*db=*/ memdb.New(),
@ -415,6 +416,7 @@ func TestInvalidFx(t *testing.T) {
defer ctx.Lock.Unlock()
vm := &VM{}
defer vm.Shutdown()
err := vm.Initialize(
/*context=*/ ctx,
/*db=*/ memdb.New(),
@ -436,6 +438,7 @@ func TestFxInitializationFailure(t *testing.T) {
defer ctx.Lock.Unlock()
vm := &VM{}
defer vm.Shutdown()
err := vm.Initialize(
/*context=*/ ctx,
/*db=*/ memdb.New(),
@ -457,6 +460,7 @@ func (tx *testTxBytes) UnsignedBytes() []byte { return tx.unsignedBytes }
func TestIssueTx(t *testing.T) {
genesisBytes, issuer, vm := GenesisVM(t)
defer func() { ctx.Lock.Lock(); vm.Shutdown(); ctx.Lock.Unlock() }()
newTx := NewTx(t, genesisBytes, vm)
@ -503,6 +507,7 @@ func TestGenesisGetUTXOs(t *testing.T) {
// transaction should be issued successfully.
func TestIssueDependentTx(t *testing.T) {
genesisBytes, issuer, vm := GenesisVM(t)
defer func() { ctx.Lock.Lock(); vm.Shutdown(); ctx.Lock.Unlock() }()
genesisTx := GetFirstTxFromGenesisTest(genesisBytes, t)
@ -638,6 +643,7 @@ func TestIssueNFT(t *testing.T) {
defer ctx.Lock.Unlock()
vm := &VM{}
defer vm.Shutdown()
err := vm.Initialize(
ctx,
memdb.New(),
@ -796,6 +802,7 @@ func TestIssueProperty(t *testing.T) {
defer ctx.Lock.Unlock()
vm := &VM{}
defer vm.Shutdown()
err := vm.Initialize(
ctx,
memdb.New(),