public void TestOrdering() { Lifetime.Using(lifetime => { SynchronousScheduler.Instance.SetActive(lifetime); var serverProtocol = Server(lifetime); var clientProtocol = Client(lifetime, serverProtocol); var sp = new RdProperty <int>().Static(1); sp.Bind(lifetime, serverProtocol, Top); var cp = new RdProperty <int>().Static(1); cp.Bind(lifetime, clientProtocol, Top); var log = new List <int>(); sp.Advise(lifetime, it => log.Add(it)); sp.SetValue(1); sp.SetValue(2); sp.SetValue(3); sp.SetValue(4); sp.SetValue(5); while (log.Count < 5) { Thread.Sleep(10); } CollectionAssert.AreEqual(new[] { 1, 2, 3, 4, 5 }, log); }); }
public void TestRunWithSlowpokeServer() { Lifetime.Using(lifetime => { SynchronousScheduler.Instance.SetActive(lifetime); var port = FindFreePort(); var clientProtocol = Client(lifetime, port); var cp = new RdProperty <int>().Static(1); cp.Bind(lifetime, clientProtocol, Top); cp.SetValue(1); Thread.Sleep(2000); var serverProtocol = Server(lifetime, port); var sp = new RdProperty <int>().Static(1); sp.Bind(lifetime, serverProtocol, Top); var prev = sp.Maybe; cp.SetValue(4); Thread.Sleep(200); WaitAndAssert(sp, 4, prev); }); }
public void TestBigBuffer() { Lifetime.Using(lifetime => { SynchronousScheduler.Instance.SetActive(lifetime); var serverProtocol = Server(lifetime); var clientProtocol = Client(lifetime, serverProtocol); var sp = new RdProperty <string>().Static(1); sp.Bind(lifetime, serverProtocol, Top); var cp = new RdProperty <string>().Static(1); cp.Bind(lifetime, clientProtocol, Top); cp.SetValue("1"); WaitAndAssert(sp, "1"); sp.SetValue(new string('a', 100000)); WaitAndAssert(cp, new string('a', 100000), "1"); cp.SetValue("a"); WaitAndAssert(sp, "a", new string('a', 100000)); cp.SetValue("ab"); WaitAndAssert(sp, "ab", "a"); cp.SetValue("abc"); WaitAndAssert(sp, "abc", "ab"); }); }
public void TestClientWithoutServerWithDelayAndMessages() { Lifetime.Using(lifetime => { SynchronousScheduler.Instance.SetActive(lifetime); var protocol = Client(lifetime, FindFreePort()); Thread.Sleep(100); var p = new RdProperty <int>().Static(1); p.Bind(lifetime, protocol, Top); p.SetValue(1); p.SetValue(2); Thread.Sleep(50); }); }
public void TestReconnect() { Lifetime.Using(lifetime => { SynchronousScheduler.Instance.SetActive(lifetime); var serverProtocol = Server(lifetime, null); var sp = new RdProperty <int>().Static(1); sp.Bind(lifetime, serverProtocol, Top); sp.IsMaster = false; var wire = serverProtocol.Wire as SocketWire.Base; int clientCount = 0; wire.NotNull().Connected.WhenTrue(lifetime, _ => { clientCount++; }); Assert.AreEqual(0, clientCount); Lifetime.Using(lf => { var clientProtocol = Client(lf, serverProtocol); var cp = new RdProperty <int>().Static(1); cp.IsMaster = true; cp.Bind(lf, clientProtocol, Top); cp.SetValue(1); WaitAndAssert(sp, 1); Assert.AreEqual(1, clientCount); }); Lifetime.Using(lf => { sp = new RdProperty <int>().Static(2); sp.Bind(lifetime, serverProtocol, Top); var clientProtocol = Client(lf, serverProtocol); var cp = new RdProperty <int>().Static(2); cp.Bind(lf, clientProtocol, Top); cp.SetValue(2); WaitAndAssert(sp, 2); Assert.AreEqual(2, clientCount); }); Lifetime.Using(lf => { var clientProtocol = Client(lf, serverProtocol); var cp = new RdProperty <int>().Static(2); cp.Bind(lf, clientProtocol, Top); cp.SetValue(3); WaitAndAssert(sp, 3, 2); Assert.AreEqual(3, clientCount); }); }); }
public void TestBasicRun() { Lifetime.Using(lifetime => { SynchronousScheduler.Instance.SetActive(lifetime); var serverProtocol = Server(lifetime); var clientProtocol = Client(lifetime, serverProtocol); var sp = new RdProperty <int>().Static(1); sp.Bind(lifetime, serverProtocol, Top); var cp = new RdProperty <int>().Static(1); cp.Bind(lifetime, clientProtocol, Top); cp.SetValue(1); WaitAndAssert(sp, 1); }); }