Skip to content

Commit 2b01b54

Browse files
rolfbjarneakoeplinger
authored andcommitted
[System] Fix ClientWebSocketTest to not throw exceptions in the constructor, but instead in the individual tests. Fixes #47167. (mono#4180)
Finding a free port on watchOS fails with a PlatformNotSupportedException, but if the exception is thrown in the constructor, the ExpectedException attribute isn't taken into account, causing the test to error out. https://bugzilla.xamarin.com/show_bug.cgi?id=47167
1 parent 0e7e6ac commit 2b01b54

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

mcs/class/System/Test/System.Net.WebSockets/ClientWebSocketTest.cs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,14 @@ namespace MonoTests.System.Net.WebSockets
1717
public class ClientWebSocketTest
1818
{
1919
const string EchoServerUrl = "ws://corefx-net.cloudapp.net/WebSocket/EchoWebSocket.ashx";
20-
int Port = NetworkHelpers.FindFreePort ();
20+
int port;
21+
int Port {
22+
get {
23+
if (port == 0)
24+
port = NetworkHelpers.FindFreePort ();
25+
return port;
26+
}
27+
}
2128
HttpListener _listener;
2229
HttpListener listener {
2330
get {
@@ -158,7 +165,12 @@ public void CloseAsyncTest ()
158165
Assert.AreEqual (WebSocketState.Closed, socket.State);
159166
}
160167

161-
[Test, ExpectedException (typeof (InvalidOperationException))]
168+
[Test]
169+
#if FEATURE_NO_BSD_SOCKETS
170+
[ExpectedException (typeof (PlatformNotSupportedException))]
171+
#else
172+
[ExpectedException (typeof (InvalidOperationException))]
173+
#endif
162174
public void SendAsyncArgTest_NotConnected ()
163175
{
164176
socket.SendAsync (new ArraySegment<byte> (new byte[0]), WebSocketMessageType.Text, true, CancellationToken.None);
@@ -172,7 +184,11 @@ public void SendAsyncArgTest_NoArray ()
172184
socket.SendAsync (new ArraySegment<byte> (), WebSocketMessageType.Text, true, CancellationToken.None);
173185
}
174186

175-
[Test, ExpectedException (typeof (InvalidOperationException))]
187+
#if FEATURE_NO_BSD_SOCKETS
188+
[ExpectedException (typeof (PlatformNotSupportedException))]
189+
#else
190+
[ExpectedException (typeof (InvalidOperationException))]
191+
#endif
176192
public void ReceiveAsyncArgTest_NotConnected ()
177193
{
178194
socket.ReceiveAsync (new ArraySegment<byte> (new byte[0]), CancellationToken.None);

0 commit comments

Comments
 (0)