Skip to content

Commit a607f4a

Browse files
committed
Enforce awaitPacket behaviour on unit tests
1 parent e39f602 commit a607f4a

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

network-api/network-api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ func udpRead(ctx context.Context, rpc *msgpackrpc.Connection, params []any) (_re
568568
udpReadBuffers[id] = buffer[maxBytes:]
569569
n = maxBytes
570570
} else {
571-
udpReadBuffers[id] = nil
571+
delete(udpReadBuffers, id)
572572
}
573573
}
574574
lock.Unlock()

network-api/network-api_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,11 +297,14 @@ func TestUDPNetworkAPI(t *testing.T) {
297297
require.Nil(t, err)
298298
require.Equal(t, []any{3, "127.0.0.1", 9800}, res)
299299

300-
res2, err := udpRead(ctx, nil, []any{conn2, 100})
300+
// A partial read of a packet is allowed
301+
res2, err := udpRead(ctx, nil, []any{conn2, 2})
301302
require.Nil(t, err)
302-
require.Equal(t, []uint8("One"), res2)
303+
require.Equal(t, []uint8("On"), res2)
303304
}
304305
{
306+
// Even if the previous packet was only partially read,
307+
// the next packet can be received
305308
res, err := udpAwaitPacket(ctx, nil, []any{conn2})
306309
require.Nil(t, err)
307310
require.Equal(t, []any{3, "127.0.0.1", 9800}, res)

0 commit comments

Comments
 (0)