Skip to content

Commit

Permalink
FIX broken netstd tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Jens-G committed Feb 11, 2025
1 parent 624118f commit 7eec227
Showing 1 changed file with 47 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Thrift.Protocol;
using Thrift.Protocol.Entities;
using Thrift.Transport;
using Thrift.Transport.Client;

#pragma warning disable IDE0063 // using
Expand Down Expand Up @@ -55,12 +56,13 @@ public async Task WriteReadMessage_Test(Type protocolType, TMessageType messageT
try
{
var tuple = GetProtocolInstance(protocolType);
using (var stream = tuple.Item1)
using (var stream = tuple.Stream)
{
var protocol = tuple.Item2;
var protocol = tuple.Protocol;

await protocol.WriteMessageBeginAsync(expected, default);
await protocol.WriteMessageEndAsync(default);
await tuple.Transport.FlushAsync(default);

stream.Seek(0, SeekOrigin.Begin);

Expand Down Expand Up @@ -89,12 +91,13 @@ public async Task WriteReadStruct_Test(Type protocolType)
try
{
var tuple = GetProtocolInstance(protocolType);
using (var stream = tuple.Item1)
using (var stream = tuple.Stream)
{
var protocol = tuple.Item2;
var protocol = tuple.Protocol;

await protocol.WriteStructBeginAsync(expected, default);
await protocol.WriteStructEndAsync(default);
await tuple.Transport.FlushAsync(default);

stream?.Seek(0, SeekOrigin.Begin);

Expand Down Expand Up @@ -124,12 +127,13 @@ public async Task WriteReadField_Test(Type protocolType)
try
{
var tuple = GetProtocolInstance(protocolType);
using (var stream = tuple.Item1)
using (var stream = tuple.Stream)
{
var protocol = tuple.Item2;
var protocol = tuple.Protocol;

await protocol.WriteFieldBeginAsync(expected, default);
await protocol.WriteFieldEndAsync(default);
await tuple.Transport.FlushAsync(default);

stream?.Seek(0, SeekOrigin.Begin);

Expand Down Expand Up @@ -157,12 +161,13 @@ public async Task WriteReadMap_Test(Type protocolType)
try
{
var tuple = GetProtocolInstance(protocolType);
using (var stream = tuple.Item1)
using (var stream = tuple.Stream)
{
var protocol = tuple.Item2;
var protocol = tuple.Protocol;

await protocol.WriteMapBeginAsync(expected, default);
await protocol.WriteMapEndAsync(default);
await tuple.Transport.FlushAsync(default);

stream?.Seek(0, SeekOrigin.Begin);

Expand Down Expand Up @@ -191,12 +196,13 @@ public async Task WriteReadList_Test(Type protocolType)
try
{
var tuple = GetProtocolInstance(protocolType);
using (var stream = tuple.Item1)
using (var stream = tuple.Stream)
{
var protocol = tuple.Item2;
var protocol = tuple.Protocol;

await protocol.WriteListBeginAsync(expected, default);
await protocol.WriteListEndAsync(default);
await tuple.Transport.FlushAsync(default);

stream?.Seek(0, SeekOrigin.Begin);

Expand Down Expand Up @@ -224,12 +230,13 @@ public async Task WriteReadSet_Test(Type protocolType)
try
{
var tuple = GetProtocolInstance(protocolType);
using (var stream = tuple.Item1)
using (var stream = tuple.Stream)
{
var protocol = tuple.Item2;
var protocol = tuple.Protocol;

await protocol.WriteSetBeginAsync(expected, default);
await protocol.WriteSetEndAsync(default);
await tuple.Transport.FlushAsync(default);

stream?.Seek(0, SeekOrigin.Begin);

Expand Down Expand Up @@ -257,11 +264,12 @@ public async Task WriteReadBool_Test(Type protocolType)
try
{
var tuple = GetProtocolInstance(protocolType);
using (var stream = tuple.Item1)
using (var stream = tuple.Stream)
{
var protocol = tuple.Item2;
var protocol = tuple.Protocol;

await protocol.WriteBoolAsync(expected, default);
await tuple.Transport.FlushAsync(default);

stream?.Seek(0, SeekOrigin.Begin);

Expand All @@ -288,11 +296,12 @@ public async Task WriteReadByte_Test(Type protocolType)
try
{
var tuple = GetProtocolInstance(protocolType);
using (var stream = tuple.Item1)
using (var stream = tuple.Stream)
{
var protocol = tuple.Item2;
var protocol = tuple.Protocol;

await protocol.WriteByteAsync(expected, default);
await tuple.Transport.FlushAsync(default);

stream?.Seek(0, SeekOrigin.Begin);

Expand All @@ -319,11 +328,12 @@ public async Task WriteReadI16_Test(Type protocolType)
try
{
var tuple = GetProtocolInstance(protocolType);
using (var stream = tuple.Item1)
using (var stream = tuple.Stream)
{
var protocol = tuple.Item2;
var protocol = tuple.Protocol;

await protocol.WriteI16Async(expected, default);
await tuple.Transport.FlushAsync(default);

stream?.Seek(0, SeekOrigin.Begin);

Expand All @@ -350,11 +360,12 @@ public async Task WriteReadI32_Test(Type protocolType)
try
{
var tuple = GetProtocolInstance(protocolType);
using (var stream = tuple.Item1)
using (var stream = tuple.Stream)
{
var protocol = tuple.Item2;
var protocol = tuple.Protocol;

await protocol.WriteI32Async(expected, default);
await tuple.Transport.FlushAsync(default);

stream?.Seek(0, SeekOrigin.Begin);

Expand All @@ -381,11 +392,12 @@ public async Task WriteReadI64_Test(Type protocolType)
try
{
var tuple = GetProtocolInstance(protocolType);
using (var stream = tuple.Item1)
using (var stream = tuple.Stream)
{
var protocol = tuple.Item2;
var protocol = tuple.Protocol;

await protocol.WriteI64Async(expected, default);
await tuple.Transport.FlushAsync(default);

stream?.Seek(0, SeekOrigin.Begin);

Expand All @@ -412,11 +424,12 @@ public async Task WriteReadDouble_Test(Type protocolType)
try
{
var tuple = GetProtocolInstance(protocolType);
using (var stream = tuple.Item1)
using (var stream = tuple.Stream)
{
var protocol = tuple.Item2;
var protocol = tuple.Protocol;

await protocol.WriteDoubleAsync(expected, default);
await tuple.Transport.FlushAsync(default);

stream?.Seek(0, SeekOrigin.Begin);

Expand All @@ -443,11 +456,12 @@ public async Task WriteReadString_Test(Type protocolType)
try
{
var tuple = GetProtocolInstance(protocolType);
using (var stream = tuple.Item1)
using (var stream = tuple.Stream)
{
var protocol = tuple.Item2;
var protocol = tuple.Protocol;

await protocol.WriteStringAsync(expected, default);
await tuple.Transport.FlushAsync(default);

stream?.Seek(0, SeekOrigin.Begin);

Expand All @@ -474,11 +488,12 @@ public async Task WriteReadBinary_Test(Type protocolType)
try
{
var tuple = GetProtocolInstance(protocolType);
using (var stream = tuple.Item1)
using (var stream = tuple.Stream)
{
var protocol = tuple.Item2;
var protocol = tuple.Protocol;

await protocol.WriteBinaryAsync(expected, default);
await tuple.Transport.FlushAsync(default);

stream?.Seek(0, SeekOrigin.Begin);

Expand All @@ -494,12 +509,14 @@ public async Task WriteReadBinary_Test(Type protocolType)
}
}

private static Tuple<Stream, TProtocol> GetProtocolInstance(Type protocolType)
private record struct ProtocolTransportStack(Stream Stream, TTransport Transport, TProtocol Protocol);

private static ProtocolTransportStack GetProtocolInstance(Type protocolType)
{
var memoryStream = new MemoryStream();
var streamClientTransport = new TStreamTransport(memoryStream, memoryStream,Configuration);
if( Activator.CreateInstance(protocolType, streamClientTransport) is TProtocol protocol)
return new Tuple<Stream, TProtocol>(memoryStream, protocol);
return new ProtocolTransportStack(memoryStream, streamClientTransport, protocol);
throw new Exception("Unexpected");
}
}
Expand Down

0 comments on commit 7eec227

Please sign in to comment.