fix: Fixes tests not correctly testing buffering.

This commit is contained in:
greysoh 2024-10-19 16:47:47 -04:00
parent 5c8ba3ff37
commit 6370948de4
Signed by: imterah
GPG key ID: 8FA7DD57BA6CEA37

View file

@ -74,7 +74,7 @@ func TestProtocolTxRx(t *testing.T) {
err = bismuth.HandleProxy(conn) err = bismuth.HandleProxy(conn)
if err != nil { if err != nil && err.Error() != "EOF" {
t.Fatalf("failed to handle proxy in Bismuth (%s)", err.Error()) t.Fatalf("failed to handle proxy in Bismuth (%s)", err.Error())
} }
}() }()
@ -109,16 +109,22 @@ func TestProtocolTxRx(t *testing.T) {
for totalBufferRead != bufferSize { for totalBufferRead != bufferSize {
randBufSize := mathRand.Intn(bufferSize - totalBufferRead) randBufSize := mathRand.Intn(bufferSize - totalBufferRead)
if randBufSize == bufferSize || randBufSize == 0 { if randBufSize == bufferSize {
continue continue
} else if randBufSize == 0 {
randBufSize = 1
} }
actualReadSize, err := conn.Read(readBuffer[totalBufferRead:]) actualReadSize, err := conn.Read(readBuffer[totalBufferRead : randBufSize+totalBufferRead])
if err != nil { if err != nil {
t.Fatalf("bismuth client failed to read in random slice #%d (%s)", index+1, err.Error()) t.Fatalf("bismuth client failed to read in random slice #%d (%s)", index+1, err.Error())
} }
if actualReadSize > randBufSize {
t.Fatalf("bismuth client is misreporting read size (expecting n < %d, recieved n (%d) > %d in random slice #%d", randBufSize, actualReadSize, randBufSize, index+1)
}
totalBufferRead += actualReadSize totalBufferRead += actualReadSize
} }