Skip to content

Commit 2dd2f37

Browse files
authored
Improve some flaky tests (#4381)
1 parent 68fd5bd commit 2dd2f37

File tree

3 files changed

+20
-11
lines changed

3 files changed

+20
-11
lines changed

test/IntegrationTests/MSTest.Acceptance.IntegrationTests/RunsettingsTests.cs

+1-7
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

44
using System.Globalization;
5-
using System.Runtime.InteropServices;
65

76
using Microsoft.Testing.Platform.Acceptance.IntegrationTests;
87
using Microsoft.Testing.Platform.Acceptance.IntegrationTests.Helpers;
@@ -38,11 +37,6 @@ public sealed class RunSettingsTests : AcceptanceTestBase<RunSettingsTests.TestA
3837
[DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))]
3938
public async Task UnsupportedRunSettingsEntriesAreFlagged(string tfm)
4039
{
41-
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && tfm == TargetFrameworks.NetFramework.First())
42-
{
43-
return;
44-
}
45-
4640
var testHost = TestHost.LocateFrom(AssetFixture.ProjectPath, TestAssetFixture.ProjectName, tfm);
4741
TestHostResult testHostResult = await testHost.ExecuteAsync("--settings my.runsettings");
4842

@@ -101,7 +95,7 @@ public sealed class TestAssetFixture() : TestAssetFixtureBase(AcceptanceFixture.
10195
{
10296
yield return (ProjectName, ProjectName,
10397
SourceCode
104-
.PatchTargetFrameworks(TargetFrameworks.NetCurrent, TargetFrameworks.NetFramework.First())
98+
.PatchTargetFrameworks(TargetFrameworks.All)
10599
.PatchCodeWithReplace("$MSTestVersion$", MSTestVersion));
106100
}
107101

test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/RetryFailedTestsTests.cs

+12-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
// Licensed under dual-license. See LICENSE.PLATFORMTOOLS.txt file in the project root for full license information.
44
#pragma warning restore IDE0073 // The file header does not match the required text
55

6+
using System.Runtime.InteropServices;
7+
68
namespace Microsoft.Testing.Platform.Acceptance.IntegrationTests;
79

810
[TestClass]
@@ -131,11 +133,18 @@ public async Task RetryFailedTests_MaxTestsCount_Succeeds(string tfm, bool fail)
131133
}
132134
}
133135

134-
// We use crash dump, not supported in NetFramework at the moment
135136
[TestMethod]
137+
// We use crash dump, not supported in NetFramework at the moment
136138
[DynamicData(nameof(TargetFrameworks.NetForDynamicData), typeof(TargetFrameworks))]
137139
public async Task RetryFailedTests_MoveFiles_Succeeds(string tfm)
138-
=> await RetryHelper.RetryAsync(
140+
{
141+
// TODO: Crash dump is not working properly on macos, so we skip the test for now
142+
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
143+
{
144+
return;
145+
}
146+
147+
await RetryHelper.RetryAsync(
139148
async () =>
140149
{
141150
var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.TargetAssetPath, AssetName, tfm);
@@ -171,6 +180,7 @@ public async Task RetryFailedTests_MoveFiles_Succeeds(string tfm)
171180
Assert.Fail($"Expected 1 or 2 dump files, but found {dumpFilesCount}");
172181
}
173182
}, 3, TimeSpan.FromSeconds(5));
183+
}
174184

175185
public sealed class TestAssetFixture() : TestAssetFixtureBase(AcceptanceFixture.NuGetGlobalPackagesFolder)
176186
{

test/UnitTests/Microsoft.Testing.Platform.UnitTests/Logging/FileLoggerTests.cs

+7-2
Original file line numberDiff line numberDiff line change
@@ -176,12 +176,17 @@ public async Task Log_WhenSyncFlush_StreamWriterIsCalledOnlyWhenLogLevelAllowsIt
176176

177177
if (LogTestHelpers.IsLogEnabled(defaultLogLevel, currentLogLevel))
178178
{
179-
if (_memoryStream.Length == 0)
179+
await _memoryStream.FlushAsync();
180+
int iteration = 0;
181+
while (_memoryStream.Length == 0 && iteration < 10)
180182
{
181-
await Task.Delay(1000);
183+
iteration++;
184+
await Task.Delay(200);
182185
}
183186

184187
await _memoryStream.FlushAsync();
188+
189+
_mockConsole.Verify(x => x.WriteLine(It.IsAny<string>()), Times.Never);
185190
Assert.AreEqual($"[00:00:00.000 Test - {currentLogLevel}] Message{Environment.NewLine}", Encoding.Default.GetString(_memoryStream.ToArray()));
186191
}
187192
else

0 commit comments

Comments
 (0)