Skip to content

Commit

Permalink
Fix smoke and acceptance tests (#3531)
Browse files Browse the repository at this point in the history
  • Loading branch information
nohwnd committed Mar 31, 2022
1 parent e033f6e commit 149507c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 126 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class DotnetArchitectureSwitchTestsWindowsOnly : AcceptanceTestBase
[DataRow("X86", "X64")]
public void Use_EnvironmentVariables(string architectureFrom, string architectureTo)
{
SetTestEnvironment(_testEnvironment, new RunnerInfo { RunnerFramework = "netcoreapp2.1" });
string dotnetPath = GetDownloadedDotnetMuxerFromTools(architectureFrom);
string dotnetPathTo = GetDownloadedDotnetMuxerFromTools(architectureTo);
var vstestConsolePath = GetDotnetRunnerPath();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,10 @@ public async Task CancelTestDiscovery(RunnerInfo runnerInfo)
// Setup
var testAssemblies = new List<string>
{
GetAssetFullPath("DiscoveryTestProject.dll"),
// This is fast to discover.
GetAssetFullPath("SimpleTestProject.dll"),
// This is slow to discover to keep us discovering while we cancel.
GetAssetFullPath("DiscoveryTestProject.dll"),
};

SetTestEnvironment(_testEnvironment, runnerInfo);
Expand All @@ -226,20 +228,23 @@ public async Task CancelTestDiscovery(RunnerInfo runnerInfo)
discoveryEvents.Setup(events => events.HandleDiscoveredTests(It.IsAny<IEnumerable<TestCase>>()))
.Callback((IEnumerable<TestCase> testcases) =>
{
Console.WriteLine($"Received test case {testcases.Single()}");
// As soon as we get first test call cancel. That way we know there is discovery in progress.
discoveredTests.AddRange(testcases);
if (!alreadyCancelled)
{
cancellationCalled = sw.Elapsed;
// Calling cancel many times crashes. https://github.com/microsoft/vstest/issues/3526
alreadyCancelled = true;
Console.WriteLine($"Cancelling at {cancellationCalled.TotalMilliseconds} ms.");
_vstestConsoleWrapper.CancelDiscovery();
}
});
var isTestCancelled = false;
discoveryEvents.Setup(events => events.HandleDiscoveryComplete(It.IsAny<long>(), It.IsAny<IEnumerable<TestCase>>(), It.IsAny<bool>()))
.Callback((long _, IEnumerable<TestCase> testcases, bool isAborted) =>
{
Console.WriteLine($"Discovery complete at {sw.ElapsedMilliseconds} ms, with isAborted: {isAborted}.");
isTestCancelled = isAborted;
if (testcases != null)
{
Expand All @@ -257,9 +262,11 @@ public async Task CancelTestDiscovery(RunnerInfo runnerInfo)
</RunSettings>";

// Act
Console.WriteLine("Starting Discovery.");
await Task.Run(() => _vstestConsoleWrapper.DiscoverTests(testAssemblies, runSettingsXml, discoveryEvents.Object));
Console.WriteLine("Discovery finished.");

// Assert.
// Assert
Assert.IsTrue(isTestCancelled, "Discovery was not cancelled");

// TODO: Review how much time it takes to actually cancel. It is not 2s on CI server. Are we waiting for anything?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class DotnetHostArchitectureVerifierTests : IntegrationTestBase
[DataRow("X86")]
public void VerifyHostArchitecture(string architecture)
{
_testEnvironment.RunnerFramework = "netcoreapp2.1";
string dotnetPath = GetDownloadedDotnetMuxerFromTools(architecture);
var vstestConsolePath = GetDotnetRunnerPath();
var dotnetRunnerPath = TempDirectory.CreateDirectory("dotnetrunner");
Expand Down
131 changes: 7 additions & 124 deletions test/TestAssets/DiscoveryTestProject/LongDiscoveryTestClass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,130 +11,13 @@ namespace DiscoveryTestProject3
public class LongDiscoveryTestClass
{
// This is for discovery cancellation test.
// 20 tests below to be discovered until we reach the X_ Y_ Z_LongDiscoveryTestMethod which haver attribute that
// takes a very long time to create, which prolongs the discovery time and keeps us discovering while we
// are cancelling the discovery from the test.
#region 20 empty tests
// LongDiscoveryTestMethod has attribute attribute that
// takes a very long time to create, which prolongs the
// discovery time and keeps us discovering while we
// are cancelling the discovery from the CancelTestDiscovery test.

[TestMethod]
public void TestMethod1()
{
}

[TestMethod]
public void TestMethod2()
{
}

[TestMethod]
public void TestMethod3()
{
}

[TestMethod]
public void TestMethod4()
{
}

[TestMethod]
public void TestMethod5()
{
}

[TestMethod]
public void TestMethod6()
{
}

[TestMethod]
public void TestMethod7()
{
}

[TestMethod]
public void TestMethod8()
{
}

[TestMethod]
public void TestMethod9()
{
}

[TestMethod]
public void TestMethod10()
{
}

[TestMethod]
public void TestMethod11()
{
}

[TestMethod]
public void TestMethod12()
{
}

[TestMethod]
public void TestMethod13()
{
}

[TestMethod]
public void TestMethod14()
{
}

[TestMethod]
public void TestMethod15()
{
}

[TestMethod]
public void TestMethod16()
{
}

[TestMethod]
public void TestMethod17()
{
}

[TestMethod]
public void TestMethod18()
{
}

[TestMethod]
public void TestMethod19()
{
}

[TestMethod]
public void TestMethod20()
{
}

#endregion

// X_ to make it discover last.
[TestMethodWithDelay]
public void X_LongDiscoveryTestMethod()
{

}

// Y_ to make it discover last.
[TestMethodWithDelay]
public void Y_LongDiscoveryTestMethod()
{

}

// Z_ to make it discover last.
[TestMethodWithDelay]
public void Z_LongDiscoveryTestMethod()
public void LongDiscoveryTestMethod()
{

}
Expand All @@ -145,8 +28,8 @@ internal class TestMethodWithDelayAttribute : TestMethodAttribute
public TestMethodWithDelayAttribute()
{
// This will be multiplied by 3 because the framework will internally create this
// attribute 3 times. And by another 3 because we have 3 slow tests.
Thread.Sleep(100);
// attribute 3 times.
Thread.Sleep(1000);
}
}
}

0 comments on commit 149507c

Please sign in to comment.