public void TestPolledRpc() { Console.WriteLine("TestPolledRpc"); var def = new RpcDefinition(1, "myfunc1", new List <RpcParamDef> { new RpcParamDef("param1", Value.MakeDouble(0.0)) }, new List <RpcResultsDef> { new RpcResultsDef("result1", NtType.Double) }); RemoteProcedureCall.CreatePolledRpc("func1", def); Console.WriteLine("Calling RPC"); long call1Uid = RemoteProcedureCall.CallRpc("func1", RemoteProcedureCall.PackRpcValues(new [] { Value.MakeDouble(2.0) })); RpcCallInfo info; bool polled = RemoteProcedureCall.PollRpc(true, TimeSpan.FromSeconds(1), out info); Assert.That(polled, Is.True); IList <byte> toSendBack = Callback1(info.Name, info.Params, new ConnectionInfo()); Assert.That(toSendBack.Count, Is.Not.EqualTo(0)); RemoteProcedureCall.PostRpcResponse(info.RpcId, info.CallUid, toSendBack); Console.WriteLine("Waiting for RPC Result"); byte[] result = null; RemoteProcedureCall.GetRpcResult(true, call1Uid, out result); var call1Result = RemoteProcedureCall.UnpackRpcValues(result, new [] { NtType.Double }); Assert.AreNotEqual(0, call1Result.Count, "RPC Result empty"); Console.WriteLine(call1Result[0].ToString()); }
public void TestPolledRpcNonBlockingWithTimeout() { Console.WriteLine("TestPolledRpcNonBlockingWithTimeout"); var def = new RpcDefinition(1, "myfunc1", new List <RpcParamDef> { new RpcParamDef("param1", Value.MakeDouble(0.0)) }, new List <RpcResultsDef> { new RpcResultsDef("result1", NtType.Double) }); RemoteProcedureCall.CreatePolledRpc("func1", def); Console.WriteLine("Calling RPC"); RpcCallInfo info; bool polled = RemoteProcedureCall.PollRpc(false, TimeSpan.FromSeconds(1), out info); Assert.That(polled, Is.False); }
public void TestPolledRpcTimeout() { Console.WriteLine("TestPolledRpcTimeout"); var def = new RpcDefinition(1, "myfunc1", new List <RpcParamDef> { new RpcParamDef("param1", Value.MakeDouble(0.0)) }, new List <RpcResultsDef> { new RpcResultsDef("result1", NtType.Double) }); RemoteProcedureCall.CreatePolledRpc("func1", def); Console.WriteLine("Calling RPC"); TimeSpan timeoutTime = TimeSpan.FromSeconds(1); Stopwatch sw = Stopwatch.StartNew(); RpcCallInfo info; bool polled = RemoteProcedureCall.PollRpc(true, timeoutTime, out info); sw.Stop(); Assert.That(polled, Is.False); TimeSpan tolerance = TimeSpan.FromSeconds(0.25); Assert.That(sw.Elapsed < timeoutTime + tolerance); Assert.That(sw.Elapsed > timeoutTime - tolerance); }