Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add concurrency unit tests #6642

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions trie/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,24 @@ func GetDefaultTrieStorageManagerParameters() NewTrieStorageManagerArgs {
}
}

// ExecuteUpdatesFromBatch -
func ExecuteUpdatesFromBatch(tr common.Trie) {
pmt, _ := tr.(*patriciaMerkleTrie)
_ = pmt.updateTrie()
}

// KeyBytesToHex -
func KeyBytesToHex(str []byte) []byte {
return keyBytesToHex(str)
}

// GetBatchManager -
func GetBatchManager(tr common.Trie) common.TrieBatchManager {
return tr.(*patriciaMerkleTrie).batchManager
}

// SetGoRoutinesManager -
func SetGoRoutinesManager(tr common.Trie, gm common.TrieGoroutinesManager) {
pmt, _ := tr.(*patriciaMerkleTrie)
pmt.goRoutinesManager = gm
}
3 changes: 3 additions & 0 deletions trie/extensionNode.go
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,9 @@ func (en *extensionNode) isEmptyOrNil() error {
if en == nil {
return ErrNilExtensionNode
}

en.childMutex.RLock()
defer en.childMutex.RUnlock()
if en.child == nil && len(en.EncodedChild) == 0 {
return ErrEmptyExtensionNode
}
Expand Down
64 changes: 64 additions & 0 deletions trie/mock/goroutinesManagerStub.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package mock

import "github.com/multiversx/mx-chain-go/common"

// GoroutinesManagerStub -
type GoroutinesManagerStub struct {
ShouldContinueProcessingCalled func() bool
CanStartGoRoutineCalled func() bool
EndGoRoutineProcessingCalled func()
SetNewErrorChannelCalled func(common.BufferedErrChan) error
SetErrorCalled func(error)
GetErrorCalled func() error
}

// ShouldContinueProcessing -
func (g *GoroutinesManagerStub) ShouldContinueProcessing() bool {
if g.ShouldContinueProcessingCalled != nil {
return g.ShouldContinueProcessingCalled()
}
return true
}

// CanStartGoRoutine -
func (g *GoroutinesManagerStub) CanStartGoRoutine() bool {
if g.CanStartGoRoutineCalled != nil {
return g.CanStartGoRoutineCalled()
}
return true
}

// EndGoRoutineProcessing -
func (g *GoroutinesManagerStub) EndGoRoutineProcessing() {
if g.EndGoRoutineProcessingCalled != nil {
g.EndGoRoutineProcessingCalled()
}
}

// SetNewErrorChannel -
func (g *GoroutinesManagerStub) SetNewErrorChannel(errChan common.BufferedErrChan) error {
if g.SetNewErrorChannelCalled != nil {
return g.SetNewErrorChannelCalled(errChan)
}
return nil
}

// SetError -
func (g *GoroutinesManagerStub) SetError(err error) {
if g.SetErrorCalled != nil {
g.SetErrorCalled(err)
}
}

// GetError -
func (g *GoroutinesManagerStub) GetError() error {
if g.GetErrorCalled != nil {
return g.GetErrorCalled()
}
return nil
}

// IsInterfaceNil -
func (g *GoroutinesManagerStub) IsInterfaceNil() bool {
return g == nil
}
Loading
Loading