Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sast/x unit latest client and latest service test case #506

Draft
wants to merge 9 commits into
base: sast/XUnitCutoverPilot
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,31 @@
using Halibut.Tests.TestServices;
using Halibut.Tests.TestServices.Async;
using Halibut.TestUtils.Contracts;
using NUnit.Framework;
using Xunit;

namespace Halibut.Tests.Diagnostics
{
public static class ExceptionReturnedByHalibutProxyExtensionMethodFixture
{
public class WhenGivenA
{
[Test]
[Fact]
public void MethodNotFoundHalibutClientException_ItIsNotANetworkError()
{
new MethodNotFoundHalibutClientException("").IsNetworkError()
.Should()
.Be(HalibutNetworkExceptionType.NotANetworkError);
}

[Test]
[Fact]
public void ServiceNotFoundHalibutClientException_ItIsNotANetworkError()
{
new ServiceNotFoundHalibutClientException("").IsNetworkError()
.Should()
.Be(HalibutNetworkExceptionType.NotANetworkError);
}

[Test]
[Fact]
public void AmbiguousMethodMatchHalibutClientException_ItIsNotANetworkError()
{
new AmbiguousMethodMatchHalibutClientException("").IsNetworkError()
Expand All @@ -44,9 +44,10 @@ public void AmbiguousMethodMatchHalibutClientException_ItIsNotANetworkError()
}
}

public class WhenTheHalibutProxyThrowsAnException : BaseTest
public class WhenTheHalibutProxyThrowsAnException : BaseTestXUnit
{
[LatestClientAndLatestServiceTestCases(testNetworkConditions:false)]
[Theory]
[LatestClientAndLatestServiceTestCasesXUnit(testNetworkConditions:false)]
public async Task WhenTheConnectionTerminatesWaitingForAResponse(ClientAndServiceTestCase clientAndServiceTestCase)
{
await using (var clientAndService = await clientAndServiceTestCase.CreateTestCaseBuilder()
Expand Down Expand Up @@ -74,8 +75,9 @@ public async Task WhenTheConnectionTerminatesWaitingForAResponse(ClientAndServic
because: "This isn't the best message, really the connection was closed before we got the data we were expecting resulting in us reading past the end of the stream");
}
}

[LatestClientAndLatestServiceTestCases(testNetworkConditions:false,

[Theory]
[LatestClientAndLatestServiceTestCasesXUnit(testNetworkConditions:false,
testWebSocket:false // Since websockets do not timeout
)]
public async Task WhenTheConnectionPausesWaitingForAResponse(ClientAndServiceTestCase clientAndServiceTestCase)
Expand All @@ -101,8 +103,8 @@ public async Task WhenTheConnectionPausesWaitingForAResponse(ClientAndServiceTes
}
}

[Test]
[LatestClientAndLatestServiceTestCases(testNetworkConditions: false, testListening:false, testWebSocket: false)]
[Theory]
[LatestClientAndLatestServiceTestCasesXUnit(testNetworkConditions: false, testListening:false, testWebSocket: false)]
public async Task BecauseThePollingRequestWasNotCollected(ClientAndServiceTestCase clientAndServiceTestCase)
{
var services = new DelegateServiceFactory();
Expand All @@ -121,8 +123,8 @@ public async Task BecauseThePollingRequestWasNotCollected(ClientAndServiceTestCa
}
}

[Test]
[LatestClientAndLatestServiceTestCases(testNetworkConditions: false, testPolling: false, testWebSocket: false)]
[Theory]
[LatestClientAndLatestServiceTestCasesXUnit(testNetworkConditions: false, testPolling: false, testWebSocket: false)]
public async Task BecauseTheListeningTentacleIsNotResponding(ClientAndServiceTestCase clientAndServiceTestCase)
{
await using (var clientAndService = await clientAndServiceTestCase.CreateTestCaseBuilder()
Expand All @@ -138,8 +140,8 @@ public async Task BecauseTheListeningTentacleIsNotResponding(ClientAndServiceTes
}
}

[Test]
[LatestClientAndLatestServiceTestCases(testNetworkConditions: false, testWebSocket: false, testPolling: false)]
[Theory]
[LatestClientAndLatestServiceTestCasesXUnit(testNetworkConditions: false, testWebSocket: false, testPolling: false)]
public async Task BecauseTheProxyIsNotResponding_TheExceptionShouldBeANetworkError(ClientAndServiceTestCase clientAndServiceTestCase)
{
await using (var clientAndService = await clientAndServiceTestCase.CreateTestCaseBuilder()
Expand All @@ -161,8 +163,8 @@ public async Task BecauseTheProxyIsNotResponding_TheExceptionShouldBeANetworkErr
}
}

[Test]
[LatestClientAndLatestServiceTestCases(testNetworkConditions: false, testPolling: false, testWebSocket: false)]
[Theory]
[LatestClientAndLatestServiceTestCasesXUnit(testNetworkConditions: false, testPolling: false, testWebSocket: false)]
public async Task BecauseOfAInvalidCertificateException_WhenConnectingToListening_ItIsNotANetworkError(ClientAndServiceTestCase clientAndServiceTestCase)
{
await using (var clientAndService = await clientAndServiceTestCase.CreateTestCaseBuilder()
Expand All @@ -181,8 +183,8 @@ public async Task BecauseOfAInvalidCertificateException_WhenConnectingToListenin
}
}

[Test]
[LatestClientAndLatestServiceTestCases(testNetworkConditions: false)]
[Theory]
[LatestClientAndLatestServiceTestCasesXUnit(testNetworkConditions: false)]
public async Task BecauseTheDataStreamHadAnErrorOpeningTheFileWithFileStream_WhenSending_ItIsNotANetworkError(ClientAndServiceTestCase clientAndServiceTestCase)
{
await using (var clientAndService = await clientAndServiceTestCase.CreateTestCaseBuilder()
Expand All @@ -208,8 +210,8 @@ public async Task BecauseTheDataStreamHadAnErrorOpeningTheFileWithFileStream_Whe
}
}

[Test]
[LatestClientAndLatestServiceTestCases(testNetworkConditions: false)]
[Theory]
[LatestClientAndLatestServiceTestCasesXUnit(testNetworkConditions: false)]
public async Task BecauseTheDataStreamThrowAFileNotFoundException_WhenSending_ItIsNotANetworkError(ClientAndServiceTestCase clientAndServiceTestCase)
{
await using (var clientAndService = await clientAndServiceTestCase.CreateTestCaseBuilder()
Expand All @@ -222,7 +224,7 @@ public async Task BecauseTheDataStreamThrowAFileNotFoundException_WhenSending_It
_ => throw new FileNotFoundException(),
async (_, _) =>
{
await Task.CompletedTask.ConfigureAwait(false);
await Task.CompletedTask;
throw new FileNotFoundException();
});

Expand All @@ -234,8 +236,8 @@ public async Task BecauseTheDataStreamThrowAFileNotFoundException_WhenSending_It
}
}

[Test]
[LatestAndPreviousClientAndServiceVersionsTestCases(testNetworkConditions: false)]
[Theory]
[LatestAndPreviousClientAndServiceVersionsTestCasesXUnit(testNetworkConditions: false)]
public async Task BecauseTheServiceThrowAnException_ItIsNotANetworkError(ClientAndServiceTestCase clientAndServiceTestCase)
{
await using (var clientAndService = await clientAndServiceTestCase.CreateTestCaseBuilder()
Expand Down
4 changes: 4 additions & 0 deletions source/Halibut.Tests/Halibut.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@
<PackageReference Include="Serilog" Version="2.12.0" />
<PackageReference Include="Serilog.Sinks.ColoredConsole" Version="3.0.1" />
<PackageReference Include="xunit" Version="2.5.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<PropertyGroup Condition=" '$(TargetFramework)' == 'net48' ">
Expand Down
4 changes: 4 additions & 0 deletions source/Halibut.Tests/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using System;
using System.Reflection;
using Halibut.Tests.Support.TestAttributes;
using Halibut.Tests.Util;
using NUnit.Framework;
using Xunit;

// Information about this assembly is defined by the following attributes.
// Change them to the values specific to your project.
Expand All @@ -11,3 +13,5 @@
[assembly: FixtureLifeCycle(LifeCycle.InstancePerTestCase)]
[assembly: TestTimeout]
[assembly: CustomLevelOfParallelism]
[assembly: TestFramework("Halibut.Tests.Util." + nameof(ParallelTestFramework), "Halibut.Tests")]
[assembly: CollectionBehavior(MaxParallelThreads = 2)]
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using Xunit.Abstractions;

namespace Halibut.Tests.Support.BackwardsCompatibility
{
Expand All @@ -22,11 +23,15 @@ public static class PreviousVersions
#endif
}

public class HalibutVersion : IEquatable<HalibutVersion>
public class HalibutVersion : IEquatable<HalibutVersion>, IXunitSerializable
{
readonly Version pollingVersion;
readonly Version listeningVersion;
readonly Version pollingOverWebSocketVersion;
Version pollingVersion;
Version listeningVersion;
Version pollingOverWebSocketVersion;

public HalibutVersion()
{
}

internal HalibutVersion(
Version version,
Expand Down Expand Up @@ -77,6 +82,20 @@ public override int GetHashCode()
return hashCode;
}
}

public void Deserialize(IXunitSerializationInfo info)
{
pollingVersion = Version.Parse(info.GetValue<string>(nameof(pollingVersion)));
listeningVersion = Version.Parse(info.GetValue<string>(nameof(listeningVersion)));
pollingOverWebSocketVersion = Version.Parse(info.GetValue<string>(nameof(pollingOverWebSocketVersion)));
}

public void Serialize(IXunitSerializationInfo info)
{
info.AddValue(nameof(pollingVersion), pollingVersion.ToString());
info.AddValue(nameof(listeningVersion), listeningVersion.ToString());
info.AddValue(nameof(pollingOverWebSocketVersion), pollingOverWebSocketVersion.ToString());
}
}

public class HalibutVersions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,18 @@ private IEnumerable<ITestCaseData> GetTestCasesFor(IMethodInfo method)
{
parms.Properties.Add(PropertyNames.Category, testCase.ServiceConnectionType.ToString());
parms.Properties.Add(PropertyNames.Category, testCase.SyncOrAsync.ToString());
}
else if (item is IEnumerable enumerableItem)
{
foreach (var itemFromEnumerable in enumerableItem)
{
if (itemFromEnumerable is ClientAndServiceTestCase testCaseFromEnumerable)
{
parms.Properties.Add(PropertyNames.Category, testCaseFromEnumerable.ServiceConnectionType.ToString());
parms.Properties.Add(PropertyNames.Category, testCaseFromEnumerable.SyncOrAsync.ToString());
break;
}
}
}

data.Add(parms);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Halibut.Tests.Support.BackwardsCompatibility;
using Halibut.Tests.Support.TestCases;
using Halibut.Util;
using Xunit.Sdk;
using static Halibut.Tests.Support.TestAttributes.LatestAndPreviousClientAndServiceVersionsTestCasesAttribute;

namespace Halibut.Tests.Support.TestAttributes
{
Expand All @@ -17,17 +20,18 @@ public LatestAndPreviousClientAndServiceVersionsTestCasesAttribute(
bool testPolling = true,
bool testAsyncAndSyncClients = true,
bool testAsyncServicesAsWell = false // False means only the sync service will be tested.
) :
) :
base(
typeof(LatestAndPreviousClientAndServiceVersionsTestCases),
nameof(LatestAndPreviousClientAndServiceVersionsTestCases.GetEnumerator),
new object[] { testWebSocket, testNetworkConditions, testListening, testPolling, testAsyncAndSyncClients, testAsyncServicesAsWell})
new object[] { testWebSocket, testNetworkConditions, testListening, testPolling, testAsyncAndSyncClients, testAsyncServicesAsWell })
{
}
static class LatestAndPreviousClientAndServiceVersionsTestCases

public static class LatestAndPreviousClientAndServiceVersionsTestCases
{
public static IEnumerable GetEnumerator(bool testWebSocket, bool testNetworkConditions, bool testListening, bool testPolling, bool testAsyncAndSyncClients, bool testAsyncServicesAsWell)
//TODO: @server-at-scale - When NUnit is removed, remove this class, and make this method the body of LatestAndPreviousClientAndServiceVersionsTestCasesXUnitAttribute.GetData
public static IEnumerable<object[]> GetEnumerator(bool testWebSocket, bool testNetworkConditions, bool testListening, bool testPolling, bool testAsyncAndSyncClients, bool testAsyncServicesAsWell)
{
var serviceConnectionTypes = ServiceConnectionTypes.All.ToList();

Expand All @@ -51,15 +55,16 @@ public static IEnumerable GetEnumerator(bool testWebSocket, bool testNetworkCond
{
clientProxyTypesToTest = ForceClientProxyTypeValues.All;
}

var serviceAsyncHalibutFeatureTestCases = AsyncHalibutFeatureValues.All().ToList();
if (!testAsyncServicesAsWell)
{
serviceAsyncHalibutFeatureTestCases.Remove(AsyncHalibutFeature.Enabled);
}

var builder = new ClientAndServiceTestCasesBuilder(
new[] {
new[]
{
ClientAndServiceTestVersion.Latest(),
ClientAndServiceTestVersion.ClientOfVersion(PreviousVersions.v5_0_236_Used_In_Tentacle_6_3_417.ClientVersion),
ClientAndServiceTestVersion.ServiceOfVersion(PreviousVersions.v5_0_236_Used_In_Tentacle_6_3_417.ServiceVersion),
Expand All @@ -69,10 +74,53 @@ public static IEnumerable GetEnumerator(bool testWebSocket, bool testNetworkCond
testNetworkConditions ? NetworkConditionTestCase.All : new[] { NetworkConditionTestCase.NetworkConditionPerfect },
clientProxyTypesToTest,
serviceAsyncHalibutFeatureTestCases
);
);

return builder.Build();
}
}
}

//TODO: @server-at-scale - When NUnit is removed, replace the above LatestAndPreviousClientAndServiceVersionsTestCasesAttribute with this.
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true, Inherited = false)]
public class LatestAndPreviousClientAndServiceVersionsTestCasesXUnitAttribute : DataAttribute
{
readonly bool testWebSocket;
readonly bool testNetworkConditions;
readonly bool testListening;
readonly bool testPolling;
readonly bool testAsyncAndSyncClients;
readonly bool testAsyncServicesAsWell;

public LatestAndPreviousClientAndServiceVersionsTestCasesXUnitAttribute(
bool testWebSocket = true,
bool testNetworkConditions = true,
bool testListening = true,
bool testPolling = true,
bool testAsyncAndSyncClients = true,
bool testAsyncServicesAsWell = false // False means only the sync service will be tested.
)
{
this.testWebSocket = testWebSocket;
this.testNetworkConditions = testNetworkConditions;
this.testListening = testListening;
this.testPolling = testPolling;
this.testAsyncAndSyncClients = testAsyncAndSyncClients;
this.testAsyncServicesAsWell = testAsyncServicesAsWell;
}

public override IEnumerable<object[]> GetData(MethodInfo testMethod)
{
//TODO: @server-at-scale - When NUnit is removed, move LatestClientAndLatestServiceTestCases.GetEnumerator into here.

return LatestAndPreviousClientAndServiceVersionsTestCases.GetEnumerator(
testWebSocket,
testNetworkConditions,
testListening,
testPolling,
testAsyncAndSyncClients,
testAsyncServicesAsWell);
}
}

}
Loading