Skip to content

Commit

Permalink
fix(plc4go/spi): avoid test transport getting stuck on a endless loop…
Browse files Browse the repository at this point in the history
… when filling
  • Loading branch information
sruehl committed May 5, 2023
1 parent 922c721 commit 6b8da79
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion plc4go/internal/cbus/MessageCodec.go
Expand Up @@ -116,7 +116,7 @@ func (m *MessageCodec) Receive() (spi.Message, error) {
return true
}
}); err != nil {
return nil, errors.Wrap(err, "error filling buffer")
log.Debug().Err(err).Msg("Error filling buffer")
}
}
log.Trace().Msg("Buffer filled")
Expand Down
14 changes: 7 additions & 7 deletions plc4go/internal/cbus/MessageCodec_test.go
Expand Up @@ -120,7 +120,7 @@ func TestMessageCodec_Receive(t *testing.T) {
hashEncountered: 0,
currentlyReportedServerErrors: 0,
},
wantErr: assert.Error,
wantErr: assert.NoError,
},
{
name: "checksum error",
Expand Down Expand Up @@ -547,8 +547,8 @@ func TestMessageCodec_Receive_Delayed_Response(t *testing.T) {
var msg spi.Message
var err error
msg, err = codec.Receive()
// No data yet so this should error
assert.Error(t, err)
// No data yet so this should return no error and no data
assert.NoError(t, err)
assert.Nil(t, msg)
// Now we add a confirmation
transportInstance.FillReadBuffer([]byte("i."))
Expand Down Expand Up @@ -578,8 +578,8 @@ func TestMessageCodec_Receive_Delayed_Response(t *testing.T) {
var msg spi.Message
var err error
msg, err = codec.Receive()
// No data yet so this should error
assert.Error(t, err)
// No data yet so this should return no error and no data
assert.NoError(t, err)
assert.Nil(t, msg)
// Now we add a confirmation
transportInstance.FillReadBuffer([]byte("i."))
Expand Down Expand Up @@ -612,8 +612,8 @@ func TestMessageCodec_Receive_Delayed_Response(t *testing.T) {
var msg spi.Message
var err error
msg, err = codec.Receive()
// No data yet so this should error
assert.Error(t, err)
// No data yet so this should return no error and no data
assert.NoError(t, err)
assert.Nil(t, msg)
// Now we add a confirmation
transportInstance.FillReadBuffer([]byte("i."))
Expand Down
4 changes: 2 additions & 2 deletions plc4go/spi/transports/test/Transport.go
Expand Up @@ -128,16 +128,16 @@ func (m *TransportInstance) FillBuffer(until func(pos uint, currentByte byte, re
}

func (m *TransportInstance) PeekReadableBytes(numBytes uint32) ([]byte, error) {
log.Trace().Msgf("Peek %d readable bytes", numBytes)
availableBytes := uint32(math.Min(float64(numBytes), float64(len(m.readBuffer))))
log.Trace().Msgf("Peek %d readable bytes (%d available bytes)", numBytes, availableBytes)
var err error
if availableBytes != numBytes {
err = errors.New("not enough bytes available")
}
if availableBytes == 0 {
return nil, err
}
return m.readBuffer[0:availableBytes], nil
return m.readBuffer[0:availableBytes], err
}

func (m *TransportInstance) Read(numBytes uint32) ([]byte, error) {
Expand Down

0 comments on commit 6b8da79

Please sign in to comment.