Skip to content

Commit

Permalink
Don't run test if OS has no IPv6 support.
Browse files Browse the repository at this point in the history
  • Loading branch information
sipsorcery committed May 18, 2020
1 parent f580c37 commit 03422a1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 24 deletions.
6 changes: 3 additions & 3 deletions .appveyor-ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ build_script:
- dotnet build src/SIPSorcery.sln --framework netcoreapp3.1
test_script:
- dotnet test src/SIPSorcery.sln --framework netcoreapp3.1 -c Release
on_finish:
- sh: export APPVEYOR_SSH_BLOCK=true
- sh: curl -sflL 'https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-ssh.sh' | bash -e -
#on_finish:
# - sh: export APPVEYOR_SSH_BLOCK=true
# - sh: curl -sflL 'https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-ssh.sh' | bash -e -
49 changes: 28 additions & 21 deletions test/sys/net/NetServicesUnitTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -320,32 +320,39 @@ public void CheckCreateSocketFailsForInUseSocketUnitTest()
logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);
logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name);

var socket4Any = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
socket4Any.Bind(new IPEndPoint(IPAddress.Any, 0));
IPEndPoint anyEP = socket4Any.LocalEndPoint as IPEndPoint;

var socketIP6Any = new Socket(AddressFamily.InterNetworkV6, SocketType.Dgram, ProtocolType.Udp);
socketIP6Any.DualMode = true;

// Since it will be useful to detect if this behaviour ever changes add different asserts for the
// different Operating Systems.

logger.LogDebug($"Environment.OSVersion: {Environment.OSVersion}");
logger.LogDebug($"Environment.OSVersion.Platform: {Environment.OSVersion.Platform}");

if (Environment.OSVersion.Platform == PlatformID.Unix && NetServices.SupportsDualModeIPv4PacketInfo)
if (!Socket.OSSupportsIPv6)
{
Assert.Throws<SocketException>(() => socketIP6Any.Bind(new IPEndPoint(IPAddress.IPv6Any, anyEP.Port)));
logger.LogDebug("Test not executed as no IPv6 support.");
}
else
{
// No exception on Windows and no duplication on Mac since IPv6 sockets are deliberately
// created with dual mode set to false.
socketIP6Any.Bind(new IPEndPoint(IPAddress.IPv6Any, anyEP.Port));
var socket4Any = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
socket4Any.Bind(new IPEndPoint(IPAddress.Any, 0));
IPEndPoint anyEP = socket4Any.LocalEndPoint as IPEndPoint;

var socketIP6Any = new Socket(AddressFamily.InterNetworkV6, SocketType.Dgram, ProtocolType.Udp);
socketIP6Any.DualMode = true;

// Since it will be useful to detect if this behaviour ever changes add different asserts for the
// different Operating Systems.

logger.LogDebug($"Environment.OSVersion: {Environment.OSVersion}");
logger.LogDebug($"Environment.OSVersion.Platform: {Environment.OSVersion.Platform}");

if (Environment.OSVersion.Platform == PlatformID.Unix && NetServices.SupportsDualModeIPv4PacketInfo)
{
Assert.Throws<SocketException>(() => socketIP6Any.Bind(new IPEndPoint(IPAddress.IPv6Any, anyEP.Port)));
}
else
{
// No exception on Windows and no duplication on Mac since IPv6 sockets are deliberately
// created with dual mode set to false.
socketIP6Any.Bind(new IPEndPoint(IPAddress.IPv6Any, anyEP.Port));
}

Assert.True(NetServices.DoTestReceive(socket4Any, null));
Assert.False(NetServices.DoTestReceive(socketIP6Any, null));
}

Assert.True(NetServices.DoTestReceive(socket4Any, null));
Assert.False(NetServices.DoTestReceive(socketIP6Any, null));
}

/// <summary>
Expand Down

0 comments on commit 03422a1

Please sign in to comment.