mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2026-08-15 13:04:36 +00:00
Fix Auto Relog reconnect lifecycle
This commit is contained in:
parent
c19fdd6634
commit
64c1dc55e0
20 changed files with 1243 additions and 415 deletions
34
MinecraftClient.Tests/SocketWrapperTests.cs
Normal file
34
MinecraftClient.Tests/SocketWrapperTests.cs
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using MinecraftClient.Protocol.Handlers;
|
||||
|
||||
namespace MinecraftClient.Tests;
|
||||
|
||||
public sealed class SocketWrapperTests
|
||||
{
|
||||
[Fact]
|
||||
public async Task GracefulPeerCloseEndsReadInsteadOfSpinning()
|
||||
{
|
||||
var listener = new TcpListener(IPAddress.Loopback, 0);
|
||||
listener.Start();
|
||||
try
|
||||
{
|
||||
using var client = new TcpClient();
|
||||
Task<TcpClient> acceptTask = listener.AcceptTcpClientAsync();
|
||||
await client.ConnectAsync((IPEndPoint)listener.LocalEndpoint);
|
||||
using TcpClient peer = await acceptTask;
|
||||
var wrapper = new SocketWrapper(client);
|
||||
|
||||
peer.Client.Shutdown(SocketShutdown.Both);
|
||||
peer.Close();
|
||||
|
||||
Assert.True(SpinWait.SpinUntil(wrapper.HasDataAvailable, TimeSpan.FromSeconds(5)));
|
||||
await Assert.ThrowsAsync<EndOfStreamException>(
|
||||
() => Task.Run(() => wrapper.ReadDataRAW(1)).WaitAsync(TimeSpan.FromSeconds(5)));
|
||||
}
|
||||
finally
|
||||
{
|
||||
listener.Stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue