Skip to content

Commit

Permalink
use TcpClient to run PerfTest
Browse files Browse the repository at this point in the history
  • Loading branch information
kerryjiang committed Dec 27, 2024
1 parent e86ace9 commit f4a12a1
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 1 deletion.
2 changes: 2 additions & 0 deletions test/SuperSocket.Tests/IHostConfigurator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public interface IHostConfigurator

Socket CreateClient();

ValueTask<Socket> CreateConnectedClientAsync();

ValueTask<Stream> GetClientStream(Socket socket);

TextReader GetStreamReader(Stream stream, Encoding encoding);
Expand Down
2 changes: 1 addition & 1 deletion test/SuperSocket.Tests/PerfTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ private async Task<int> RunConnectionAsync(IHostConfigurator hostConfigurator, C
{
var round = 0;

using (var socket = hostConfigurator.CreateClient())
using (var socket = await hostConfigurator.CreateConnectedClientAsync())
using (var clientStream = await hostConfigurator.GetClientStream(socket))
using (var streamReader = new StreamReader(clientStream, Utf8Encoding, true))
using (var streamWriter = new StreamWriter(clientStream, Utf8Encoding, 1024 * 1024 * 4))
Expand Down
5 changes: 5 additions & 0 deletions test/SuperSocket.Tests/ProxyProtocolHostConfigurator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,10 @@ public ValueTask KeepSequence()
{
return _innerHostConfigurator.KeepSequence();
}

public ValueTask<Socket> CreateConnectedClientAsync()
{
return _innerHostConfigurator.CreateConnectedClientAsync();
}
}
}
7 changes: 7 additions & 0 deletions test/SuperSocket.Tests/TcpHostConfigurator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ public Socket CreateClient()
return socket;
}

public async ValueTask<Socket> CreateConnectedClientAsync()
{
var serverAddress = this.GetServerEndPoint();
var client = new TcpClient();
await client.ConnectAsync(serverAddress);
return client.Client;
}

public TextReader GetStreamReader(Stream stream, Encoding encoding)
{
Expand Down
4 changes: 4 additions & 0 deletions test/SuperSocket.Tests/UdpHostConfigurator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,5 +144,9 @@ public async ValueTask KeepSequence()
await Task.Delay(200);
}

public ValueTask<Socket> CreateConnectedClientAsync()
{
throw new NotSupportedException();
}
}
}

0 comments on commit f4a12a1

Please sign in to comment.