public void TestSuspendResumeReadWrite() { IConnectFuture future = Connect(port, new ClientIoHandler()); future.Await(); IoSession session = future.Session; // We wait for the SessionCreated() event is fired because we // cannot guarantee that it is invoked already. while (session.GetAttribute("lock") == null) { Thread.Yield(); } Object sync = session.GetAttribute("lock"); lock (sync) { Write(session, "1"); Assert.AreEqual('1', Read(session)); Assert.AreEqual("1", GetReceived(session)); Assert.AreEqual("1", GetSent(session)); session.SuspendRead(); Thread.Sleep(100); Write(session, "2"); Assert.IsFalse(CanRead(session)); Assert.AreEqual("1", GetReceived(session)); Assert.AreEqual("12", GetSent(session)); session.SuspendWrite(); Thread.Sleep(100); Write(session, "3"); Assert.IsFalse(CanRead(session)); Assert.AreEqual("1", GetReceived(session)); Assert.AreEqual("12", GetSent(session)); session.ResumeRead(); Thread.Sleep(100); Write(session, "4"); Assert.AreEqual('2', Read(session)); Assert.AreEqual("12", GetReceived(session)); Assert.AreEqual("12", GetSent(session)); session.ResumeWrite(); Thread.Sleep(100); Assert.AreEqual('3', Read(session)); Assert.AreEqual('4', Read(session)); Write(session, "5"); Assert.AreEqual('5', Read(session)); Assert.AreEqual("12345", GetReceived(session)); Assert.AreEqual("12345", GetSent(session)); session.SuspendWrite(); Thread.Sleep(100); Write(session, "6"); Assert.IsFalse(CanRead(session)); Assert.AreEqual("12345", GetReceived(session)); Assert.AreEqual("12345", GetSent(session)); session.SuspendRead(); session.ResumeWrite(); Thread.Sleep(100); Write(session, "7"); Assert.IsFalse(CanRead(session)); Assert.AreEqual("12345", GetReceived(session)); Assert.AreEqual("1234567", GetSent(session)); session.ResumeRead(); Thread.Sleep(100); Assert.AreEqual('6', Read(session)); Assert.AreEqual('7', Read(session)); Assert.AreEqual("1234567", GetReceived(session)); Assert.AreEqual("1234567", GetSent(session)); } session.Close(true).Await(); }