core: add ability to check whether blockchain is running
This commit is contained in:
parent
eb0494764c
commit
1dac45bbbb
2 changed files with 23 additions and 0 deletions
|
@ -5,6 +5,7 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
|
@ -340,3 +341,20 @@ func TestBlockchain_BaseExecFeeBaseStoragePrice_Compat(t *testing.T) {
|
|||
check(t)
|
||||
})
|
||||
}
|
||||
|
||||
func TestBlockchain_IsRunning(t *testing.T) {
|
||||
chain := initTestChain(t, nil, nil)
|
||||
require.False(t, chain.isRunning.Load().(bool))
|
||||
oldPersisted := atomic.LoadUint32(&chain.persistedHeight)
|
||||
|
||||
go chain.Run()
|
||||
require.NoError(t, chain.AddBlock(chain.newBlock()))
|
||||
require.Eventually(t, func() bool {
|
||||
persisted := atomic.LoadUint32(&chain.persistedHeight)
|
||||
return persisted > oldPersisted
|
||||
}, 2*persistInterval, 100*time.Millisecond)
|
||||
require.True(t, chain.isRunning.Load().(bool))
|
||||
|
||||
chain.Close()
|
||||
require.False(t, chain.isRunning.Load().(bool))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue