140 lines
4.3 KiB
C#
Raw Normal View History

2019-06-12 21:56:55 +02:00
using Capnp.Net.Runtime.Tests.GenImpls;
using Capnp.Net.Runtime.Tests.Util;
2019-06-12 21:56:55 +02:00
using Capnp.Rpc;
using Capnproto_test.Capnp.Test;
using Microsoft.Extensions.Logging;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
2020-02-01 13:49:45 +01:00
using System.Net;
using System.Net.Sockets;
2019-06-12 21:56:55 +02:00
using System.Text;
using System.Threading;
namespace Capnp.Net.Runtime.Tests
{
[TestClass]
public class TcpRpcStress: TestBase
{
void Repeat(int count, Action action)
{
for (int i = 0; i < count; i++)
{
Logger.LogTrace("Repetition {0}", i);
action();
}
}
[TestMethod]
public void ResolveMain()
{
Repeat(5000, () =>
{
(var server, var client) = SetupClientServerPair();
using (server)
using (client)
{
2020-04-11 15:48:02 +02:00
//client.WhenConnected.Wait();
2019-06-12 21:56:55 +02:00
var counters = new Counters();
var impl = new TestMoreStuffImpl(counters);
server.Main = impl;
using (var main = client.GetMain<ITestMoreStuff>())
{
var resolving = main as IResolvingCapability;
Assert.IsTrue(resolving.WhenResolved.WrappedTask.Wait(MediumNonDbgTimeout));
2019-06-12 21:56:55 +02:00
}
}
});
}
[TestMethod]
public void Cancel()
{
var t = new TcpRpcPorted();
Repeat(1000, t.Cancel);
}
[TestMethod]
public void Embargo()
{
var t = new TcpRpcPorted();
Repeat(100,
() =>
NewLocalhostTcpTestbed(TcpRpcTestOptions.ClientTracer | TcpRpcTestOptions.ClientFluctStream)
.RunTest(Testsuite.EmbargoOnPromisedAnswer));
}
2019-06-12 21:56:55 +02:00
[TestMethod]
public void EmbargoServer()
{
2019-06-12 21:56:55 +02:00
var t2 = new TcpRpcInterop();
2020-04-10 19:23:16 +02:00
Repeat(20, t2.EmbargoServer);
2019-06-12 21:56:55 +02:00
}
[TestMethod]
public void EmbargoNull()
{
// Some code paths are really rare during this test, therefore increased repetition count.
var t = new TcpRpcPorted();
Repeat(1000, t.EmbargoNull);
var t2 = new TcpRpcInterop();
Repeat(100, t2.EmbargoNullServer);
}
[TestMethod]
public void RetainAndRelease()
{
var t = new TcpRpcPorted();
Repeat(100, t.RetainAndRelease);
}
[TestMethod]
public void PipelineAfterReturn()
{
var t = new TcpRpc();
Repeat(100, t.PipelineAfterReturn);
}
2020-01-31 21:40:25 +01:00
[TestMethod]
public void ScatteredTransfer()
{
(var addr, int port) = TcpManager.Instance.GetLocalAddressAndPort();
using (var server = new TcpRpcServer(addr, port))
using (var client = new TcpRpcClient())
2020-01-31 21:40:25 +01:00
{
server.InjectMidlayer(s => new ScatteringStream(s, 7));
client.InjectMidlayer(s => new ScatteringStream(s, 10));
client.Connect(addr.ToString(), port);
//client.WhenConnected.Wait();
var counters = new Counters();
server.Main = new TestInterfaceImpl(counters);
using (var main = client.GetMain<ITestInterface>())
2020-01-31 21:40:25 +01:00
{
for (int i = 0; i < 100; i++)
2020-01-31 21:40:25 +01:00
{
var request1 = main.Foo(123, true, default);
var request3 = Assert.ThrowsExceptionAsync<RpcException>(() => main.Bar(default));
var s = new TestAllTypes();
Common.InitTestMessage(s);
var request2 = main.Baz(s, default);
Assert.IsTrue(request1.Wait(MediumNonDbgTimeout));
Assert.IsTrue(request2.Wait(MediumNonDbgTimeout));
Assert.IsTrue(request3.Wait(MediumNonDbgTimeout));
Assert.AreEqual("foo", request1.Result);
Assert.AreEqual(2, counters.CallCount);
counters.CallCount = 0;
2020-01-31 21:40:25 +01:00
}
}
}
}
2019-06-12 21:56:55 +02:00
}
}