Skip to content

Commit 244b3fc

Browse files
committed
fix CI
1 parent ef2db57 commit 244b3fc

1 file changed

Lines changed: 26 additions & 7 deletions

File tree

tests/StackExchange.Redis.Tests/RedisValueShortBlobTests.cs

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using System.Buffers;
32
using System.Linq;
43
using System.Text;
54
using Xunit;
@@ -144,14 +143,34 @@ public void ShortBlob_WriteBulkString_MatchesByteArray()
144143
RedisValue byteArray = (byte[])bytes.Clone();
145144
Assert.Equal(RedisValue.StorageType.ShortBlob, shortBlob.Type);
146145

147-
var fromShortBlob = new ArrayBufferWriter<byte>();
148-
var fromByteArray = new ArrayBufferWriter<byte>();
149-
MessageWriter.WriteBulkString(shortBlob, fromShortBlob);
150-
MessageWriter.WriteBulkString(byteArray, fromByteArray);
146+
var fromShortBlob = WriteBulkString(shortBlob);
147+
var fromByteArray = WriteBulkString(byteArray);
151148

152149
// the wire bytes must be identical, and a well-formed RESP bulk string
153-
Assert.Equal(fromByteArray.WrittenSpan.ToArray(), fromShortBlob.WrittenSpan.ToArray());
154-
Assert.Equal(Encoding.ASCII.GetBytes("$5\r\nhello\r\n"), fromShortBlob.WrittenSpan.ToArray());
150+
Assert.Equal(fromByteArray, fromShortBlob);
151+
Assert.True(fromShortBlob.AsSpan().SequenceEqual("$5\r\nhello\r\n"u8), "RESP bulk string mismatch");
152+
153+
// serialize a single bulk string via the shared block buffer and copy out the exact wire bytes before
154+
// releasing it (we avoid ArrayBufferWriter<byte>, which isn't available on net48x)
155+
static byte[] WriteBulkString(RedisValue value)
156+
{
157+
ReadOnlyMemory<byte> payload = default;
158+
try
159+
{
160+
MessageWriter.WriteBulkString(value, MessageWriter.BlockBuffer);
161+
payload = MessageWriter.FlushBlockBuffer();
162+
return payload.ToArray();
163+
}
164+
catch
165+
{
166+
MessageWriter.RevertBlockBuffer();
167+
throw;
168+
}
169+
finally
170+
{
171+
MessageWriter.ReleaseBlockBuffer(payload);
172+
}
173+
}
155174
}
156175

157176
[Fact]

0 commit comments

Comments
 (0)