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

Don't throw from RemoteExecutor on SkipTestExceptions #65105

Merged
merged 1 commit into from
Feb 10, 2022
Merged
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 @@ -8,6 +8,7 @@
using System.Security.Authentication;
using System.Threading.Tasks;
using Microsoft.DotNet.RemoteExecutor;
using Microsoft.DotNet.XUnitExtensions;
using Xunit;

namespace System.Net.Security.Tests
Expand All @@ -28,61 +29,69 @@ public static void EventSource_ExistsWithCorrectId()

[OuterLoop]
[ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))]
[SkipOnPlatform(TestPlatforms.iOS | TestPlatforms.tvOS, "X509 certificate store is not supported on iOS or tvOS.")] // Match SslStream_StreamToStream_Authentication_Success
public static void EventSource_SuccessfulHandshake_LogsStartStop()
{
RemoteExecutor.Invoke(async () =>
{
using var listener = new TestEventListener("System.Net.Security", EventLevel.Verbose, eventCounterInterval: 0.1d);
listener.AddActivityTracking();

var events = new ConcurrentQueue<(EventWrittenEventArgs Event, Guid ActivityId)>();
await listener.RunWithCallbackAsync(e =>
try
{
events.Enqueue((e, e.ActivityId));
using var listener = new TestEventListener("System.Net.Security", EventLevel.Verbose, eventCounterInterval: 0.1d);
listener.AddActivityTracking();

if (e.EventName == "HandshakeStart")
var events = new ConcurrentQueue<(EventWrittenEventArgs Event, Guid ActivityId)>();
await listener.RunWithCallbackAsync(e =>
{
// Wait for a new counter group so that current-tls-handshakes is guaranteed a non-zero value
WaitForEventCountersAsync(events).GetAwaiter().GetResult();
}
},
async () =>
{
// Invoke tests that'll cause some events to be generated
var test = new SslStreamStreamToStreamTest_Async();
await test.SslStream_StreamToStream_Authentication_Success();
await WaitForEventCountersAsync(events);
});
Assert.DoesNotContain(events, ev => ev.Event.EventId == 0); // errors from the EventSource itself
events.Enqueue((e, e.ActivityId));

if (e.EventName == "HandshakeStart")
{
// Wait for a new counter group so that current-tls-handshakes is guaranteed a non-zero value
WaitForEventCountersAsync(events).GetAwaiter().GetResult();
}
},
async () =>
{
// Invoke tests that'll cause some events to be generated
var test = new SslStreamStreamToStreamTest_Async();
await test.SslStream_StreamToStream_Authentication_Success();
await WaitForEventCountersAsync(events);
});
Assert.DoesNotContain(events, ev => ev.Event.EventId == 0); // errors from the EventSource itself

(EventWrittenEventArgs Event, Guid ActivityId)[] starts = events.Where(e => e.Event.EventName == "HandshakeStart").ToArray();
Assert.Equal(2, starts.Length);
Assert.All(starts, s => Assert.Equal(2, s.Event.Payload.Count));
Assert.All(starts, s => Assert.NotEqual(Guid.Empty, s.ActivityId));
(EventWrittenEventArgs Event, Guid ActivityId)[] starts = events.Where(e => e.Event.EventName == "HandshakeStart").ToArray();
Assert.Equal(2, starts.Length);
Assert.All(starts, s => Assert.Equal(2, s.Event.Payload.Count));
Assert.All(starts, s => Assert.NotEqual(Guid.Empty, s.ActivityId));

// isServer
(EventWrittenEventArgs Event, Guid ActivityId) serverStart = Assert.Single(starts, s => (bool)s.Event.Payload[0]);
(EventWrittenEventArgs Event, Guid ActivityId) clientStart = Assert.Single(starts, s => !(bool)s.Event.Payload[0]);
// isServer
(EventWrittenEventArgs Event, Guid ActivityId) serverStart = Assert.Single(starts, s => (bool)s.Event.Payload[0]);
(EventWrittenEventArgs Event, Guid ActivityId) clientStart = Assert.Single(starts, s => !(bool)s.Event.Payload[0]);

// targetHost
Assert.Empty(Assert.IsType<string>(serverStart.Event.Payload[1]));
Assert.NotEmpty(Assert.IsType<string>(clientStart.Event.Payload[1]));
// targetHost
Assert.Empty(Assert.IsType<string>(serverStart.Event.Payload[1]));
Assert.NotEmpty(Assert.IsType<string>(clientStart.Event.Payload[1]));

Assert.NotEqual(serverStart.ActivityId, clientStart.ActivityId);
Assert.NotEqual(serverStart.ActivityId, clientStart.ActivityId);

(EventWrittenEventArgs Event, Guid ActivityId)[] stops = events.Where(e => e.Event.EventName == "HandshakeStop").ToArray();
Assert.Equal(2, stops.Length);
(EventWrittenEventArgs Event, Guid ActivityId)[] stops = events.Where(e => e.Event.EventName == "HandshakeStop").ToArray();
Assert.Equal(2, stops.Length);

EventWrittenEventArgs serverStop = Assert.Single(stops, s => s.ActivityId == serverStart.ActivityId).Event;
EventWrittenEventArgs clientStop = Assert.Single(stops, s => s.ActivityId == clientStart.ActivityId).Event;
EventWrittenEventArgs serverStop = Assert.Single(stops, s => s.ActivityId == serverStart.ActivityId).Event;
EventWrittenEventArgs clientStop = Assert.Single(stops, s => s.ActivityId == clientStart.ActivityId).Event;

SslProtocols serverProtocol = ValidateHandshakeStopEventPayload(serverStop);
SslProtocols clientProtocol = ValidateHandshakeStopEventPayload(clientStop);
Assert.Equal(serverProtocol, clientProtocol);
SslProtocols serverProtocol = ValidateHandshakeStopEventPayload(serverStop);
SslProtocols clientProtocol = ValidateHandshakeStopEventPayload(clientStop);
Assert.Equal(serverProtocol, clientProtocol);

Assert.DoesNotContain(events, e => e.Event.EventName == "HandshakeFailed");
Assert.DoesNotContain(events, e => e.Event.EventName == "HandshakeFailed");

VerifyEventCounters(events, shouldHaveFailures: false);
VerifyEventCounters(events, shouldHaveFailures: false);
}
catch (SkipTestException)
{
// Don't throw inside RemoteExecutor if SslStream_StreamToStream_Authentication_Success chose to skip the test
}
}).Dispose();
}

Expand Down