Skip to content

Commit 0e4909a

Browse files
authored
Fix some outerloop tests (#62559)
* serialport * Fix OpenOrCreate_DeleteOnClose_UsableAsMutex * logging * impersonated * ping
1 parent 8ae1c49 commit 0e4909a

File tree

7 files changed

+28
-10
lines changed

7 files changed

+28
-10
lines changed

src/libraries/Common/tests/TestUtilities/System/PlatformDetection.Windows.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,8 @@ public static bool IsInAppContainer
235235
}
236236
}
237237

238+
public static bool CanRunImpersonatedTests => PlatformDetection.IsNotWindowsNanoServer && PlatformDetection.IsWindowsAndElevated;
239+
238240
private static int s_isWindowsElevated = -1;
239241
public static bool IsWindowsAndElevated
240242
{

src/libraries/Common/tests/TestUtilities/System/WindowsIdentityFixture.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using System.Security.Principal;
1111
using System.Threading.Tasks;
1212
using Microsoft.Win32.SafeHandles;
13+
using Xunit;
1314

1415
namespace System
1516
{
@@ -37,6 +38,8 @@ public sealed partial class WindowsTestAccount : IDisposable
3738

3839
public WindowsTestAccount(string userName)
3940
{
41+
Assert.True(PlatformDetection.IsWindowsAndElevated);
42+
4043
_userName = userName;
4144
CreateUser();
4245
}
@@ -77,6 +80,10 @@ private void CreateUser()
7780
throw new Win32Exception((int)result);
7881
}
7982
}
83+
else if (result != 0)
84+
{
85+
throw new Win32Exception((int)result);
86+
}
8087

8188
const int LOGON32_PROVIDER_DEFAULT = 0;
8289
const int LOGON32_LOGON_INTERACTIVE = 2;

src/libraries/System.IO.FileSystem/tests/FileStream/DeleteOnClose.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4+
using System.Diagnostics;
45
using System.Threading;
56
using System.Threading.Tasks;
67
using Xunit;
@@ -63,19 +64,21 @@ public async Task OpenOrCreate_DeleteOnClose_UsableAsMutex()
6364
}
6465
};
6566

67+
var sw = Stopwatch.StartNew();
6668
var tasks = new Task[50];
6769
for (int i = 0; i < tasks.Length; i++)
6870
{
6971
tasks[i] = Task.Run(lockFile);
7072
}
7173

7274
// Wait for 1000 locks.
73-
cts.CancelAfter(TimeSpan.FromSeconds(120)); // Test timeout (reason for outerloop)
75+
cts.CancelAfter(TimeSpan.FromSeconds(240)); // Test timeout (reason for outerloop)
7476
Volatile.Write(ref locksRemaining, 500);
7577
await Task.WhenAll(tasks);
78+
sw.Stop();
7679

7780
Assert.True(exclusive, "Exclusive");
78-
Assert.False(cts.IsCancellationRequested, "Test cancelled");
81+
Assert.False(cts.IsCancellationRequested, $"Test cancelled with {locksRemaining}/500 locks remaining after {sw.Elapsed.TotalSeconds} seconds");
7982
Assert.False(File.Exists(path), "File exists");
8083
}
8184
}

src/libraries/System.IO.Ports/tests/SerialPort/DosDevices.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System.Collections;
55
using System.Collections.Generic;
6+
using System.ComponentModel;
67
using System.Runtime.InteropServices;
78

89
namespace System.IO.Ports.Tests
@@ -127,14 +128,20 @@ private static char[] CallQueryDosDevice(string name, out int dataSize)
127128
buffer = new char[buffer.Length * 2];
128129
dataSize = QueryDosDevice(null, buffer, buffer.Length);
129130
}
131+
else if (lastError == ERROR_ACCESS_DENIED) // Access denied eg for "MSSECFLTSYS" - just skip
132+
{
133+
dataSize = 0;
134+
break;
135+
}
130136
else
131137
{
132-
throw new Exception("Unknown Win32 Error: " + lastError);
138+
throw new Exception($"Error {lastError} calling QueryDosDevice for '{name}' with buffer size {buffer.Length}. {new Win32Exception((int)lastError).Message}");
133139
}
134140
}
135141
return buffer;
136142
}
137143

144+
public const int ERROR_ACCESS_DENIED = 5;
138145
public const int ERROR_INSUFFICIENT_BUFFER = 122;
139146
public const int ERROR_MORE_DATA = 234;
140147

src/libraries/System.Net.Http/tests/FunctionalTests/ImpersonatedAuthTests.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ namespace System.Net.Http.Functional.Tests
1414
{
1515
public class ImpersonatedAuthTests: IClassFixture<WindowsIdentityFixture>
1616
{
17-
public static bool CanRunImpersonatedTests = PlatformDetection.IsWindows && PlatformDetection.IsNotWindowsNanoServer;
1817
private readonly WindowsIdentityFixture _fixture;
1918
private readonly ITestOutputHelper _output;
2019

@@ -28,11 +27,11 @@ public ImpersonatedAuthTests(WindowsIdentityFixture windowsIdentityFixture, ITe
2827
}
2928

3029
[OuterLoop]
31-
[ConditionalTheory(nameof(CanRunImpersonatedTests))]
30+
[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.CanRunImpersonatedTests))]
3231
[InlineData(true)]
3332
[InlineData(false)]
3433
[PlatformSpecific(TestPlatforms.Windows)]
35-
public async Task DefaultHandler_ImpersonificatedUser_Success(bool useNtlm)
34+
public async Task DefaultHandler_ImpersonatedUser_Success(bool useNtlm)
3635
{
3736
await LoopbackServer.CreateClientAndServerAsync(
3837
async uri =>

src/libraries/System.Net.Ping/tests/FunctionalTests/PingTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -854,7 +854,7 @@ public async Task SendPingToExternalHostWithLowTtlTest()
854854
options.Ttl = 1;
855855
// This should always fail unless host is one IP hop away.
856856
pingReply = await ping.SendPingAsync(host, TestSettings.PingTimeout, TestSettings.PayloadAsBytesShort, options);
857-
Assert.Equal(IPStatus.TimeExceeded, pingReply.Status);
857+
Assert.True(pingReply.Status == IPStatus.TimeExceeded || pingReply.Status == IPStatus.TtlExpired);
858858
Assert.NotEqual(IPAddress.Any, pingReply.Address);
859859
}
860860

src/libraries/System.Security.Principal.Windows/tests/WindowsIdentityImpersonatedTests.netcoreapp.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public WindowsIdentityImpersonatedTests(WindowsIdentityFixture windowsIdentityFi
2626
Assert.False(string.IsNullOrEmpty(_fixture.TestAccount.AccountName));
2727
}
2828

29-
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsNanoServer))]
29+
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.CanRunImpersonatedTests))]
3030
[OuterLoop]
3131
public async Task RunImpersonatedAsync_TaskAndTaskOfT()
3232
{
@@ -60,7 +60,7 @@ void Asserts(WindowsIdentity currentWindowsIdentity)
6060
}
6161
}
6262

63-
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsNanoServer))]
63+
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.CanRunImpersonatedTests))]
6464
[OuterLoop]
6565
public void RunImpersonated_NameResolution()
6666
{
@@ -78,7 +78,7 @@ public void RunImpersonated_NameResolution()
7878
});
7979
}
8080

81-
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsNanoServer))]
81+
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.CanRunImpersonatedTests))]
8282
[OuterLoop]
8383
public async Task RunImpersonatedAsync_NameResolution()
8484
{

0 commit comments

Comments
 (0)