This project has moved. For the latest updates, please go here.
1

Closed

Skip web socket tests if platform has no web socket support

description

I'm on Windows/7 and this platform has no web socket support. Web socket is supported from Windows 8, see https://msdn.microsoft.com/en-us/library/system.net.websockets.clientwebsocket(v=vs.110).aspx

Problem

I build the katanaproject using Visual Studio 2013 command line tools:
    set Platform=AnyCPU
    set DevDivCodeAnalysisRunType=Disabled
    call build.cmd release deploy > build.txt 2>&1
The build fails on Web Socket tests, obviously because Windows/7 does not have web socket support:
xunit.dll:     Version 1.9.2.1705
Test assembly: C:\TFS\AgpWebEngine\Dependencies.Git\katanaproject\artifacts\test\Microsoft.Owin.Host.HttpListener.Tests\Microsoft.Owin.Host.HttpListener.Tests.dll


Microsoft.Owin.Host.HttpListener.Tests.OwinWebSocketTests.WebSocketUpgradeAfterHeadersSent_Throws [FAIL]
   System.PlatformNotSupportedException : Het WebSocket-protocol wordt niet ondersteund op dit platform.
   Stack Trace:
      bij System.Net.WebSockets.ClientWebSocket..ctor()
      bij Microsoft.Owin.Host.HttpListener.Tests.OwinWebSocketTests.<WebSocketUpgradeAfterHeadersSent_Throws>d__4c.MoveNext() in c:\TFS\AgpWebEngine\Dependencies.Git\katanaproject\tests\Microsoft.Owin.Host.HttpListener.Tests\OwinWebSocketTests.cs:regel 216


Tests complete: 60 of 55
Microsoft.Owin.Host.HttpListener.Tests.OwinWebSocketTests.EndToEnd_EchoData_Success [FAIL]
   System.PlatformNotSupportedException : Het WebSocket-protocol wordt niet ondersteund op dit platform.
   Stack Trace:
      bij System.Net.WebSockets.ClientWebSocket..ctor()
      bij Microsoft.Owin.Host.HttpListener.Tests.OwinWebSocketTests.<EndToEnd_EchoData_Success>d__21.MoveNext() in c:\TFS\AgpWebEngine\Dependencies.Git\katanaproject\tests\Microsoft.Owin.Host.HttpListener.Tests\OwinWebSocketTests.cs:regel 114


Tests complete: 61 of 55
Microsoft.Owin.Host.HttpListener.Tests.OwinWebSocketTests.ErrorInWebSocket_Disconnected [FAIL]
   System.PlatformNotSupportedException : Het WebSocket-protocol wordt niet ondersteund op dit platform.
   Stack Trace:
      bij System.Net.WebSockets.ClientWebSocket..ctor()
      bij Microsoft.Owin.Host.HttpListener.Tests.OwinWebSocketTests.<ErrorInWebSocket_Disconnected>d__59.MoveNext() in c:\TFS\AgpWebEngine\Dependencies.Git\katanaproject\tests\Microsoft.Owin.Host.HttpListener.Tests\OwinWebSocketTests.cs:regel 255


Tests complete: 62 of 55
Microsoft.Owin.Host.HttpListener.Tests.OwinWebSocketTests.SubProtocol_SelectLastSubProtocol_Success [FAIL]
   System.PlatformNotSupportedException : Het WebSocket-protocol wordt niet ondersteund op dit platform.
   Stack Trace:
      bij System.Net.WebSockets.ClientWebSocket..ctor()
      bij Microsoft.Owin.Host.HttpListener.Tests.OwinWebSocketTests.<SubProtocol_SelectLastSubProtocol_Success>d__39.MoveNext() in c:\TFS\AgpWebEngine\Dependencies.Git\katanaproject\tests\Microsoft.Owin.Host.HttpListener.Tests\OwinWebSocketTests.cs:regel 168


Tests complete: 63 of 55
Microsoft.Owin.Host.HttpListener.Tests.OwinWebSocketTests.EndToEnd_ConnectAndClose_Success [FAIL]
   System.PlatformNotSupportedException : Het WebSocket-protocol wordt niet ondersteund op dit platform.
   Stack Trace:
      bij System.Net.WebSockets.ClientWebSocket..ctor()
      bij Microsoft.Owin.Host.HttpListener.Tests.OwinWebSocketTests.<EndToEnd_ConnectAndClose_Success>d__c.MoveNext() in c:\TFS\AgpWebEngine\Dependencies.Git\katanaproject\tests\Microsoft.Owin.Host.HttpListener.Tests\OwinWebSocketTests.cs:regel 67


Tests complete: 64 of 55
64 total, 5 failed, 0 skipped, took 2.156 seconds

Solution

I modified the Web Socket tests source to skip web socket tests if platform has no web socket support. After modification all tests run to completion.

Modified tests\Microsoft.Owin.Host.HttpListener.Tests\OwinWebSocketTests.cs
    public class FactSkipWhenPlatformHasNoWebSocketSupport : FactAttribute 
    {
        public FactSkipWhenPlatformHasNoWebSocketSupport() 
        {
            if(!PlatformHasWebSocketSupport()) 
            {
                Skip = "Platform has no web socket support";
            }
        }
        /// <summary>
        /// Determine if runtime platform has web socket support.
        /// </summary>
        /// <returns>True if platform has websocket support, false otherwise.</returns>
        private static bool? _platformHasWebSocketSupport = null;
        public static bool PlatformHasWebSocketSupport() 
        {
            if (!_platformHasWebSocketSupport.HasValue)
            {
                try
                {
                    var client = new ClientWebSocket();
                    _platformHasWebSocketSupport = true;
                }
                catch
                {
                    _platformHasWebSocketSupport = false;
                }
            }
            
            return _platformHasWebSocketSupport.Value;
        }
    }

And then replaced [Fact] with [FactSkipWhenPlatformHasNoWebSocketSupport]

Output of build after modification

xxunit.dll:     Version 1.9.2.1705
Test assembly: C:\TFS\AgpWebEngine\Dependencies.Git\katanaproject\artifacts\test\Microsoft.Owin.Host.HttpListener.Tests\Microsoft.Owin.Host.HttpListener.Tests.dll

Tests complete: 59 of 55
Microsoft.Owin.Host.HttpListener.Tests.OwinWebSocketTests.ErrorInWebSocket_Disconnected [SKIP]
   Platform has no web socket support


Tests complete: 60 of 55
Microsoft.Owin.Host.HttpListener.Tests.OwinWebSocketTests.EndToEnd_ConnectAndClose_Success [SKIP]
   Platform has no web socket support


Tests complete: 61 of 55
Microsoft.Owin.Host.HttpListener.Tests.OwinWebSocketTests.SubProtocol_SelectLastSubProtocol_Success [SKIP]
   Platform has no web socket support


Tests complete: 62 of 55
Microsoft.Owin.Host.HttpListener.Tests.OwinWebSocketTests.WebSocketUpgradeAfterHeadersSent_Throws [SKIP]
   Platform has no web socket support


Tests complete: 63 of 55
Microsoft.Owin.Host.HttpListener.Tests.OwinWebSocketTests.EndToEnd_EchoData_Success [SKIP]
   Platform has no web socket support


Tests complete: 64 of 55
64 total, 0 failed, 5 skipped, took 1.753 seconds

file attachments

Closed Mar 2 at 9:50 PM by mgirgin

comments

MircoBabin wrote Aug 14, 2015 at 8:24 AM

I have attached a patch with my modifications. I'm not very familiair with Git so I don't know if this is the desired format for receiving contributions.

Tratcher wrote Aug 21, 2015 at 7:58 PM

FYI: Development of these components has moved to https://github.com/aspnet/