Skip to content

Commit

Permalink
synchronize testhelpers.LogHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
magicxyyz authored and hkalodner committed Sep 16, 2022
1 parent 2483230 commit aa1c7fb
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions util/testhelpers/testhelpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"math/rand"
"os"
"regexp"
"sync"
"testing"

"github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -42,6 +43,7 @@ func RandomAddress() common.Address {
}

type LogHandler struct {
mutex sync.Mutex
t *testing.T
records []log.Record
streamHandler log.Handler
Expand All @@ -51,13 +53,17 @@ func (h *LogHandler) Log(record *log.Record) error {
if err := h.streamHandler.Log(record); err != nil {
return err
}
h.mutex.Lock()
defer h.mutex.Unlock()
h.records = append(h.records, *record)
return nil
}

func (h *LogHandler) WasLogged(pattern string) bool {
re, err := regexp.Compile(pattern)
RequireImpl(h.t, err)
h.mutex.Lock()
defer h.mutex.Unlock()
for _, record := range h.records {
if re.MatchString(record.Msg) {
return true
Expand Down

0 comments on commit aa1c7fb

Please sign in to comment.