Skip to content

Commit

Permalink
Merge pull request #504 from rakshasa/fix/mock-conn-race-2
Browse files Browse the repository at this point in the history
fix: changing entry conversations in mock connection manager caused r…
  • Loading branch information
agaffney authored Feb 20, 2024
2 parents bf31cb1 + 6ee477b commit 3eeb1dd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
9 changes: 6 additions & 3 deletions internal/test/ouroboros_mock/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,12 @@ func (c *Connection) processInputEntry(entry ConversationEntry) error {
if msg == nil {
return fmt.Errorf("received unknown message type: %d", msgType)
}
// Set CBOR for expected message to match received to make comparison easier
entry.InputMessage.SetCbor(msg.Cbor())
// Compare received message to expected message

// Compare received message to expected message, excluding the cbor content
//
// As changing the CBOR of the expected message is not thread-safe, we instead clear the
// CBOR of the received message
msg.SetCbor(nil)
if !reflect.DeepEqual(msg, entry.InputMessage) {
return fmt.Errorf(
"parsed message does not match expected value: got %#v, expected %#v",
Expand Down
4 changes: 4 additions & 0 deletions protocol/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ type MessageBase struct {

// SetCbor stores the original CBOR that was parsed
func (m *MessageBase) SetCbor(data []byte) {
if data == nil {
m.rawCbor = nil
return
}
m.rawCbor = make([]byte, len(data))
copy(m.rawCbor, data)
}
Expand Down

0 comments on commit 3eeb1dd

Please sign in to comment.