|
| 1 | +package debug |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/multiversx/mx-chain-go/consensus" |
| 7 | + "github.com/stretchr/testify/require" |
| 8 | +) |
| 9 | + |
| 10 | +func TestNewEquivalentMessagesDebugger_IsInterfaceNil(t *testing.T) { |
| 11 | + t.Parallel() |
| 12 | + |
| 13 | + var debugger *equivalentMessagesDebugger |
| 14 | + require.True(t, debugger.IsInterfaceNil()) |
| 15 | + |
| 16 | + debugger = NewEquivalentMessagesDebugger() |
| 17 | + require.False(t, debugger.IsInterfaceNil()) |
| 18 | +} |
| 19 | + |
| 20 | +func TestEquivalentMessagesDebugger_DisplayEquivalentMessagesStatistics(t *testing.T) { |
| 21 | + t.Parallel() |
| 22 | + |
| 23 | + t.Run("log level not trace should early exit", func(t *testing.T) { |
| 24 | + t.Parallel() |
| 25 | + |
| 26 | + defer func() { |
| 27 | + r := recover() |
| 28 | + if r != nil { |
| 29 | + require.Fail(t, "should have not panicked") |
| 30 | + } |
| 31 | + }() |
| 32 | + |
| 33 | + debugger := NewEquivalentMessagesDebugger() |
| 34 | + debugger.DisplayEquivalentMessagesStatistics(func() map[string]*consensus.EquivalentMessageInfo { |
| 35 | + return make(map[string]*consensus.EquivalentMessageInfo) |
| 36 | + }) |
| 37 | + }) |
| 38 | + t.Run("nil get data handler should early exit", func(t *testing.T) { |
| 39 | + t.Parallel() |
| 40 | + |
| 41 | + defer func() { |
| 42 | + r := recover() |
| 43 | + if r != nil { |
| 44 | + require.Fail(t, "should have not panicked") |
| 45 | + } |
| 46 | + }() |
| 47 | + |
| 48 | + debugger := NewEquivalentMessagesDebugger() |
| 49 | + debugger.shouldProcessDataFunc = func() bool { |
| 50 | + return true |
| 51 | + } |
| 52 | + |
| 53 | + debugger.DisplayEquivalentMessagesStatistics(nil) |
| 54 | + }) |
| 55 | + t.Run("should work", func(t *testing.T) { |
| 56 | + t.Parallel() |
| 57 | + |
| 58 | + defer func() { |
| 59 | + r := recover() |
| 60 | + if r != nil { |
| 61 | + require.Fail(t, "should have not panicked") |
| 62 | + } |
| 63 | + }() |
| 64 | + |
| 65 | + debugger := NewEquivalentMessagesDebugger() |
| 66 | + debugger.shouldProcessDataFunc = func() bool { |
| 67 | + return true |
| 68 | + } |
| 69 | + |
| 70 | + debugger.DisplayEquivalentMessagesStatistics(func() map[string]*consensus.EquivalentMessageInfo { |
| 71 | + return map[string]*consensus.EquivalentMessageInfo{ |
| 72 | + "hash1": {NumMessages: 1, Validated: true}, |
| 73 | + "hash2": {NumMessages: 2, Validated: true}, |
| 74 | + "hash3": {NumMessages: 3, Validated: true}, |
| 75 | + "hash4": {NumMessages: 4, Validated: true}, |
| 76 | + } |
| 77 | + }) |
| 78 | + |
| 79 | + }) |
| 80 | +} |
0 commit comments