-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1289 from nunit/port-1183
Fix hang when test processes fail to terminate correctly
- Loading branch information
Showing
2 changed files
with
84 additions
and
9 deletions.
There are no files selected for viewing
71 changes: 71 additions & 0 deletions
71
src/NUnitEngine/nunit.engine.tests/Transport/Tcp/TcpServerTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// Copyright (c) Charlie Poole, Rob Prouse and Contributors. MIT License - see LICENSE.txt | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Net.Sockets; | ||
using System.Text; | ||
using System.Threading; | ||
using NUnit.Framework; | ||
|
||
namespace NUnit.Engine.Communication.Transports.Tcp | ||
{ | ||
public class TcpServerTests | ||
{ | ||
private TcpServer _server; | ||
private List<Socket> _serverConnections; | ||
|
||
[SetUp] | ||
public void StartServer() | ||
{ | ||
_serverConnections = new List<Socket>(); | ||
_server = new TcpServer(); | ||
_server.ClientConnected += (c, g) => _serverConnections.Add(c); | ||
_server.Start(); | ||
} | ||
|
||
[TearDown] | ||
public void StopServer() | ||
{ | ||
_server.Stop(); | ||
} | ||
|
||
[Test] | ||
public void SingleClientConnection() | ||
{ | ||
using (TcpClient client = new TcpClient()) | ||
{ | ||
client.Connect(_server.EndPoint); | ||
client.Client.Send(new Guid().ToByteArray()); | ||
|
||
Thread.Sleep(1); // Allow the connection event to run | ||
Assert.That(_serverConnections.Count, Is.EqualTo(1), "Should have received 1 connection event"); | ||
Assert.That(_serverConnections[0].Connected, "Server is not connected to client"); | ||
|
||
Assert.True(client.Connected, "Client is not connected to server"); | ||
} | ||
} | ||
|
||
[Test] | ||
public void MultipleClientConnections() | ||
{ | ||
TcpClient[] clients = new[] { new TcpClient(), new TcpClient(), new TcpClient() }; | ||
int num = clients.Length; | ||
|
||
foreach (var client in clients) | ||
{ | ||
client.Connect(_server.EndPoint); | ||
client.Client.Send(new Guid().ToByteArray()); | ||
} | ||
|
||
Thread.Sleep(1); // Allow the connection events to run | ||
Assert.That(_serverConnections.Count, Is.EqualTo(num), $"Should have received {num} connection events"); | ||
|
||
for (int i = 0; i < num; i++) | ||
{ | ||
Assert.That(_serverConnections[i].Connected, $"Server is not connected to client {i + 1}"); | ||
Assert.True(clients[i].Connected, $"Client {i + 1} is not connected to server"); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters