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

This commit is contained in:
Alex Willmer 2020-04-21 01:34:22 +01:00
parent a769c2017e
commit 996ea99fb1
3 changed files with 10 additions and 0 deletions

View File

@ -66,6 +66,7 @@ func ConsensusLeader(numBlocks, numTxsPerBlock int, b *testing.B) {
// Initialize the VM
vm := &VM{}
defer func() { ctx.Lock.Lock(); vm.Shutdown(); vm.ctx.Lock.Unlock() }()
ctx.Lock.Lock()
if err := vm.Initialize(ctx, vmDB, genesisData, msgChan, nil); err != nil {
b.Fatal(err)
@ -198,6 +199,7 @@ func ConsensusFollower(numBlocks, numTxsPerBlock int, b *testing.B) {
vm := &VM{
onAccept: func(ids.ID) { wg.Done() },
}
defer func() { ctx.Lock.Lock(); vm.Shutdown(); vm.ctx.Lock.Unlock() }()
ctx.Lock.Lock()
if err := vm.Initialize(ctx, vmDB, genesisData, msgChan, nil); err != nil {
b.Fatal(err)

View File

@ -73,6 +73,7 @@ func BenchmarkParseBlock(b *testing.B) {
/*testing=*/ b,
)
vm := &VM{}
defer func() { ctx.Lock.Lock(); vm.Shutdown(); vm.ctx.Lock.Unlock() }()
vm.Initialize(
/*ctx=*/ ctx,
/*db=*/ memdb.New(),
@ -106,6 +107,7 @@ func BenchmarkParseAndVerify(b *testing.B) {
for n := 0; n < b.N; n++ {
vm := &VM{}
defer func() { ctx.Lock.Lock(); vm.Shutdown(); vm.ctx.Lock.Unlock() }()
vm.Initialize(
/*ctx=*/ snow.DefaultContextTest(),
/*db=*/ memdb.New(),
@ -141,6 +143,8 @@ func BenchmarkAccept(b *testing.B) {
for n := 0; n < b.N; n++ {
vm := &VM{}
defer func() { ctx.Lock.Lock(); vm.Shutdown(); vm.ctx.Lock.Unlock() }()
vm.Initialize(
/*ctx=*/ snow.DefaultContextTest(),
/*db=*/ memdb.New(),
@ -178,6 +182,7 @@ func ParseAndVerifyAndAccept(numBlocks, numTxsPerBlock int, b *testing.B) {
for n := 0; n < b.N; n++ {
vm := &VM{}
defer func() { ctx.Lock.Lock(); vm.Shutdown(); vm.ctx.Lock.Unlock() }()
vm.Initialize(
/*ctx=*/ snow.DefaultContextTest(),
/*db=*/ memdb.New(),
@ -232,6 +237,7 @@ func ParseThenVerifyThenAccept(numBlocks, numTxsPerBlock int, b *testing.B) {
for n := 0; n < b.N; n++ {
vm := &VM{}
defer func() { ctx.Lock.Lock(); vm.Shutdown(); vm.ctx.Lock.Unlock() }()
vm.Initialize(
/*ctx=*/ snow.DefaultContextTest(),
/*db=*/ memdb.New(),
@ -292,6 +298,7 @@ func IssueAndVerifyAndAccept(numBlocks, numTxsPerBlock int, b *testing.B) {
for n := 0; n < b.N; n++ {
vm := &VM{}
defer func() { ctx.Lock.Lock(); vm.Shutdown(); vm.ctx.Lock.Unlock() }()
vm.Initialize(
/*ctx=*/ snow.DefaultContextTest(),
/*db=*/ memdb.New(),

View File

@ -67,6 +67,7 @@ func TestPayments(t *testing.T) {
blocker, _ := queue.New(bootstrappingDB)
vm := &VM{}
defer func() { ctx.Lock.Lock(); vm.Shutdown(); vm.ctx.Lock.Unlock() }()
vm.Initialize(ctx, db, genesisData, msgChan, nil)
sender := &common.SenderTest{}