github.com/MetalBlockchain/subnet-evm@v0.4.9/plugin/evm/block_builder_test.go (about) 1 // (c) 2019-2021, Ava Labs, Inc. All rights reserved. 2 // See the file LICENSE for licensing terms. 3 4 package evm 5 6 import ( 7 "math/big" 8 "sync" 9 "testing" 10 "time" 11 12 "github.com/MetalBlockchain/subnet-evm/params" 13 14 "github.com/MetalBlockchain/metalgo/snow" 15 ) 16 17 func TestBlockBuilderShutsDown(t *testing.T) { 18 shutdownChan := make(chan struct{}) 19 wg := &sync.WaitGroup{} 20 config := *params.TestChainConfig 21 config.SubnetEVMTimestamp = big.NewInt(time.Now().Add(time.Hour).Unix()) 22 23 builder := &blockBuilder{ 24 ctx: snow.DefaultContextTest(), 25 chainConfig: &config, 26 shutdownChan: shutdownChan, 27 shutdownWg: wg, 28 } 29 30 builder.handleBlockBuilding() 31 // Close [shutdownChan] and ensure that the wait group finishes in a reasonable 32 // amount of time. 33 close(shutdownChan) 34 attemptAwait(t, wg, 5*time.Second) 35 } 36 37 func TestBlockBuilderSkipsTimerInitialization(t *testing.T) { 38 shutdownChan := make(chan struct{}) 39 wg := &sync.WaitGroup{} 40 builder := &blockBuilder{ 41 ctx: snow.DefaultContextTest(), 42 chainConfig: params.TestChainConfig, 43 shutdownChan: shutdownChan, 44 shutdownWg: wg, 45 } 46 47 builder.handleBlockBuilding() 48 49 if builder.buildBlockTimer == nil { 50 t.Fatal("expected block timer to be non-nil") 51 } 52 53 // The wait group should finish immediately since no goroutine 54 // should be created when all prices should be set from the start 55 attemptAwait(t, wg, time.Millisecond) 56 }