Skip to content

Commit 3eeb1dd

Browse files
authored
Merge pull request #504 from rakshasa/fix/mock-conn-race-2
fix: changing entry conversations in mock connection manager caused r…
2 parents bf31cb1 + 6ee477b commit 3eeb1dd

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

internal/test/ouroboros_mock/connection.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,12 @@ func (c *Connection) processInputEntry(entry ConversationEntry) error {
187187
if msg == nil {
188188
return fmt.Errorf("received unknown message type: %d", msgType)
189189
}
190-
// Set CBOR for expected message to match received to make comparison easier
191-
entry.InputMessage.SetCbor(msg.Cbor())
192-
// Compare received message to expected message
190+
191+
// Compare received message to expected message, excluding the cbor content
192+
//
193+
// As changing the CBOR of the expected message is not thread-safe, we instead clear the
194+
// CBOR of the received message
195+
msg.SetCbor(nil)
193196
if !reflect.DeepEqual(msg, entry.InputMessage) {
194197
return fmt.Errorf(
195198
"parsed message does not match expected value: got %#v, expected %#v",

protocol/message.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ type MessageBase struct {
3131

3232
// SetCbor stores the original CBOR that was parsed
3333
func (m *MessageBase) SetCbor(data []byte) {
34+
if data == nil {
35+
m.rawCbor = nil
36+
return
37+
}
3438
m.rawCbor = make([]byte, len(data))
3539
copy(m.rawCbor, data)
3640
}

0 commit comments

Comments
 (0)