mirror of
https://github.com/FabInfra/capnproto-dotnetcore_Runtime.git
synced 2025-03-14 15:51:43 +01:00
made tcp server handling in tests more robust
This commit is contained in:
parent
14adb1ed71
commit
fcc8108e9e
@ -16,38 +16,9 @@ namespace Capnp.Net.Runtime.Tests
|
|||||||
|
|
||||||
[TestClass]
|
[TestClass]
|
||||||
[TestCategory("Coverage")]
|
[TestCategory("Coverage")]
|
||||||
public class TcpRpc
|
public class TcpRpc: TestBase
|
||||||
{
|
{
|
||||||
public static int TcpPort = 49153;
|
bool ExpectingLogOutput { get; set; } = true;
|
||||||
|
|
||||||
(TcpRpcServer, TcpRpcClient) SetupClientServerPair()
|
|
||||||
{
|
|
||||||
var server = new TcpRpcServer(IPAddress.Any, TcpPort);
|
|
||||||
var client = new TcpRpcClient("localhost", TcpPort);
|
|
||||||
return (server, client);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ExpectingLogOutput { get; set; }
|
|
||||||
|
|
||||||
[TestInitialize]
|
|
||||||
public void InitConsoleLogging()
|
|
||||||
{
|
|
||||||
ExpectingLogOutput = true;
|
|
||||||
|
|
||||||
Logging.LoggerFactory?.Dispose();
|
|
||||||
#pragma warning disable CS0618 // Typ oder Element ist veraltet
|
|
||||||
Logging.LoggerFactory = new LoggerFactory().AddConsole((msg, level) =>
|
|
||||||
{
|
|
||||||
if (!ExpectingLogOutput && level != LogLevel.Debug)
|
|
||||||
{
|
|
||||||
Assert.Fail("Did not expect any logging output, but got this: " + msg);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
#pragma warning restore CS0618 // Typ oder Element ist veraltet
|
|
||||||
}
|
|
||||||
|
|
||||||
int MediumNonDbgTimeout => Debugger.IsAttached ? Timeout.Infinite : 2000;
|
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void CreateAndDispose()
|
public void CreateAndDispose()
|
||||||
@ -720,6 +691,27 @@ namespace Capnp.Net.Runtime.Tests
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void RobustStartAccepting(TcpRpcServer server)
|
||||||
|
{
|
||||||
|
int retry = 0;
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
server.StartAccepting(IPAddress.Any, TcpPort);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
catch (SocketException)
|
||||||
|
{
|
||||||
|
if (retry++ == 100)
|
||||||
|
throw;
|
||||||
|
|
||||||
|
IncrementTcpPort();
|
||||||
|
}
|
||||||
|
} while (true);
|
||||||
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void Server1()
|
public void Server1()
|
||||||
{
|
{
|
||||||
@ -757,7 +749,7 @@ namespace Capnp.Net.Runtime.Tests
|
|||||||
|
|
||||||
Assert.ThrowsException<InvalidOperationException>(() => server.StopListening());
|
Assert.ThrowsException<InvalidOperationException>(() => server.StopListening());
|
||||||
|
|
||||||
server.StartAccepting(IPAddress.Any, TcpPort);
|
RobustStartAccepting(server);
|
||||||
Assert.IsTrue(server.IsAlive);
|
Assert.IsTrue(server.IsAlive);
|
||||||
Assert.ThrowsException<InvalidOperationException>(() => server.StartAccepting(IPAddress.Any, TcpPort));
|
Assert.ThrowsException<InvalidOperationException>(() => server.StartAccepting(IPAddress.Any, TcpPort));
|
||||||
|
|
||||||
@ -822,7 +814,7 @@ namespace Capnp.Net.Runtime.Tests
|
|||||||
server.Dispose();
|
server.Dispose();
|
||||||
};
|
};
|
||||||
|
|
||||||
server.StartAccepting(IPAddress.Any, TcpPort);
|
RobustStartAccepting(server);
|
||||||
|
|
||||||
var client1 = new TcpRpcClient("localhost", TcpPort);
|
var client1 = new TcpRpcClient("localhost", TcpPort);
|
||||||
Assert.IsTrue(client1.WhenConnected.Wait(MediumNonDbgTimeout), "Did not connect");
|
Assert.IsTrue(client1.WhenConnected.Wait(MediumNonDbgTimeout), "Did not connect");
|
||||||
@ -842,7 +834,7 @@ namespace Capnp.Net.Runtime.Tests
|
|||||||
a.Connection.Close();
|
a.Connection.Close();
|
||||||
};
|
};
|
||||||
|
|
||||||
server.StartAccepting(IPAddress.Any, TcpPort);
|
RobustStartAccepting(server);
|
||||||
|
|
||||||
var client1 = new TcpRpcClient("localhost", TcpPort);
|
var client1 = new TcpRpcClient("localhost", TcpPort);
|
||||||
Assert.IsTrue(client1.WhenConnected.Wait(MediumNonDbgTimeout));
|
Assert.IsTrue(client1.WhenConnected.Wait(MediumNonDbgTimeout));
|
||||||
@ -863,7 +855,7 @@ namespace Capnp.Net.Runtime.Tests
|
|||||||
Assert.ThrowsException<InvalidOperationException>(() => client.GetMain<ITestInterface>());
|
Assert.ThrowsException<InvalidOperationException>(() => client.GetMain<ITestInterface>());
|
||||||
Assert.ThrowsException<ArgumentNullException>(() => client.AttachTracer(null));
|
Assert.ThrowsException<ArgumentNullException>(() => client.AttachTracer(null));
|
||||||
Assert.ThrowsException<ArgumentNullException>(() => client.InjectMidlayer(null));
|
Assert.ThrowsException<ArgumentNullException>(() => client.InjectMidlayer(null));
|
||||||
server.StartAccepting(IPAddress.Any, TcpPort);
|
RobustStartAccepting(server);
|
||||||
client.Connect("localhost", TcpPort);
|
client.Connect("localhost", TcpPort);
|
||||||
Assert.ThrowsException<InvalidOperationException>(() => client.Connect("localhost", TcpPort));
|
Assert.ThrowsException<InvalidOperationException>(() => client.Connect("localhost", TcpPort));
|
||||||
Assert.IsTrue(client.WhenConnected.Wait(MediumNonDbgTimeout));
|
Assert.IsTrue(client.WhenConnected.Wait(MediumNonDbgTimeout));
|
||||||
|
@ -359,6 +359,7 @@ namespace Capnp.Net.Runtime.Tests
|
|||||||
client.AttachTracer(new FrameTracing.RpcFrameTracer(Console.Out, false));
|
client.AttachTracer(new FrameTracing.RpcFrameTracer(Console.Out, false));
|
||||||
if (options.HasFlag(TcpRpcTestOptions.ClientFluctStream))
|
if (options.HasFlag(TcpRpcTestOptions.ClientFluctStream))
|
||||||
client.InjectMidlayer(s => new FluctStream(s));
|
client.InjectMidlayer(s => new FluctStream(s));
|
||||||
|
if (!options.HasFlag(TcpRpcTestOptions.ClientNoConnect))
|
||||||
client.Connect("localhost", TcpPort);
|
client.Connect("localhost", TcpPort);
|
||||||
return client;
|
return client;
|
||||||
}
|
}
|
||||||
@ -368,7 +369,8 @@ namespace Capnp.Net.Runtime.Tests
|
|||||||
{
|
{
|
||||||
None = 0,
|
None = 0,
|
||||||
ClientTracer = 1,
|
ClientTracer = 1,
|
||||||
ClientFluctStream = 2
|
ClientFluctStream = 2,
|
||||||
|
ClientNoConnect = 4
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static TcpRpcServer SetupServer()
|
protected static TcpRpcServer SetupServer()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user