public void TestConcurrentSending() { StartServer(); EndPoint serverAddress = new IPEndPoint(IPAddress.Parse("127.0.0.1"), m_Config.Port); string[] source = SEND.GetStringSource(); string[] received = new string[source.Length]; using (Socket socket = CreateClientSocket()) { socket.Connect(serverAddress); Stream socketStream = GetSocketStream(socket); using (StreamReader reader = new StreamReader(socketStream, m_Encoding, true)) using (StreamWriter writer = new StreamWriter(socketStream, m_Encoding, 1024 * 8)) { reader.ReadLine(); writer.WriteLine("SEND"); writer.Flush(); for (var i = 0; i < received.Length; i++) { var line = reader.ReadLine(); received[i] = line; Console.WriteLine(line); } } } var dict = source.ToDictionary(i => i); for (var i = 0; i < received.Length; i++) { if (!dict.Remove(received[i])) { Assert.Fail(received[i]); } } if (dict.Count > 0) { Assert.Fail(); } }
[Test]//[Test, Repeat(5)] public void TestConcurrentSending() { var configSource = StartBootstrap(DefaultServerConfig, c => new ServerConfig(c) { SendingQueueSize = 100, ClearIdleSession = false }); var serverConfig = configSource.Servers.FirstOrDefault(); EndPoint serverAddress = new IPEndPoint(IPAddress.Parse("127.0.0.1"), serverConfig.Port); string[] source = SEND.GetStringSource(); string[] received = new string[source.Length]; using (Socket socket = CreateClientSocket()) { socket.Connect(serverAddress); Stream socketStream = GetSocketStream(socket); using (StreamReader reader = new StreamReader(socketStream, m_Encoding, true)) using (ConsoleWriter writer = new ConsoleWriter(socketStream, m_Encoding, 1024 * 8)) { reader.ReadLine(); for (var j = 0; j < 1000; j++) { writer.WriteLine("SEND"); writer.Flush(); Console.WriteLine (j); int i; for (i = 0; i < received.Length; i++) { var line = reader.ReadLine(); if (line == null) break; //Console.WriteLine (i); received[i] = line; } Assert.AreEqual(received.Length, i); Console.WriteLine("ROUND"); } } } if (received.Distinct().Count() != received.Length) Assert.Fail("Duplicated record!"); var dict = source.ToDictionary(i => i); for (var i = 0; i < received.Length; i++) { if (!dict.Remove(received[i])) Assert.Fail(received[i]); } if (dict.Count > 0) Assert.Fail(); }