-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Convert SignalR EventSource usage to new pattern #11130
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ee8c2e2
wip
BrennanConroy 35497d9
stash
BrennanConroy 1ca9ea9
Convert SignalR EventSource usage to new pattern
BrennanConroy 7b14f1a
always increment counters
BrennanConroy 6efe390
naming
BrennanConroy 420dc3d
fix name
BrennanConroy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System.Diagnostics.Tracing; | ||
|
||
namespace Microsoft.AspNetCore.Internal | ||
{ | ||
internal class TestEventListener : EventListener | ||
{ | ||
private readonly int _eventId; | ||
|
||
public TestEventListener(int eventId) | ||
{ | ||
_eventId = eventId; | ||
} | ||
|
||
public EventWrittenEventArgs EventData { get; private set; } | ||
|
||
protected override void OnEventWritten(EventWrittenEventArgs eventData) | ||
{ | ||
// The tests here run in parallel, capture the EventData that a test is explicitly | ||
// looking for and not give back other tests' data. | ||
if (eventData.EventId == _eventId) | ||
{ | ||
EventData = eventData; | ||
} | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletions
112
src/SignalR/common/Http.Connections/test/Internal/HttpConnectionsEventSourceTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.Diagnostics.Tracing; | ||
using Microsoft.AspNetCore.Internal; | ||
using Microsoft.Extensions.Internal; | ||
using Xunit; | ||
|
||
namespace Microsoft.AspNetCore.Http.Connections.Internal | ||
{ | ||
public class HttpConnectionsEventSourceTests | ||
{ | ||
[Fact] | ||
public void MatchesNameAndGuid() | ||
{ | ||
// Arrange & Act | ||
var eventSource = new HttpConnectionsEventSource(); | ||
|
||
// Assert | ||
Assert.Equal("Microsoft.AspNetCore.Http.Connections", eventSource.Name); | ||
Assert.Equal(Guid.Parse("c26fe4b6-8790-5d41-5900-0f2b6b74efaa"), eventSource.Guid); | ||
} | ||
|
||
[Fact] | ||
public void ConnectionStart() | ||
{ | ||
// Arrange | ||
var expectedEventId = 1; | ||
var eventListener = new TestEventListener(expectedEventId); | ||
var httpConnectionsEventSource = GetHttpConnectionEventSource(); | ||
eventListener.EnableEvents(httpConnectionsEventSource, EventLevel.Informational); | ||
|
||
// Act | ||
httpConnectionsEventSource.ConnectionStart("1"); | ||
|
||
// Assert | ||
var eventData = eventListener.EventData; | ||
Assert.NotNull(eventData); | ||
Assert.Equal(expectedEventId, eventData.EventId); | ||
Assert.Equal("ConnectionStart", eventData.EventName); | ||
Assert.Equal(EventLevel.Informational, eventData.Level); | ||
Assert.Same(httpConnectionsEventSource, eventData.EventSource); | ||
Assert.Equal("Started connection '{0}'.", eventData.Message); | ||
Assert.Collection(eventData.Payload, | ||
arg => | ||
{ | ||
Assert.Equal("1", arg); | ||
}); | ||
} | ||
|
||
[Fact] | ||
public void ConnectionStop() | ||
{ | ||
// Arrange | ||
var expectedEventId = 2; | ||
var eventListener = new TestEventListener(expectedEventId); | ||
var httpConnectionsEventSource = GetHttpConnectionEventSource(); | ||
eventListener.EnableEvents(httpConnectionsEventSource, EventLevel.Informational); | ||
|
||
// Act | ||
var stopWatch = ValueStopwatch.StartNew(); | ||
httpConnectionsEventSource.ConnectionStop("1", stopWatch); | ||
|
||
// Assert | ||
var eventData = eventListener.EventData; | ||
Assert.NotNull(eventData); | ||
Assert.Equal(expectedEventId, eventData.EventId); | ||
Assert.Equal("ConnectionStop", eventData.EventName); | ||
Assert.Equal(EventLevel.Informational, eventData.Level); | ||
Assert.Same(httpConnectionsEventSource, eventData.EventSource); | ||
Assert.Equal("Stopped connection '{0}'.", eventData.Message); | ||
Assert.Collection(eventData.Payload, | ||
arg => | ||
{ | ||
Assert.Equal("1", arg); | ||
}); | ||
} | ||
|
||
[Fact] | ||
public void ConnectionTimedOut() | ||
{ | ||
// Arrange | ||
var expectedEventId = 3; | ||
var eventListener = new TestEventListener(expectedEventId); | ||
var httpConnectionsEventSource = GetHttpConnectionEventSource(); | ||
eventListener.EnableEvents(httpConnectionsEventSource, EventLevel.Informational); | ||
|
||
// Act | ||
httpConnectionsEventSource.ConnectionTimedOut("1"); | ||
|
||
// Assert | ||
var eventData = eventListener.EventData; | ||
Assert.NotNull(eventData); | ||
Assert.Equal(expectedEventId, eventData.EventId); | ||
Assert.Equal("ConnectionTimedOut", eventData.EventName); | ||
Assert.Equal(EventLevel.Informational, eventData.Level); | ||
Assert.Same(httpConnectionsEventSource, eventData.EventSource); | ||
Assert.Equal("Connection '{0}' timed out.", eventData.Message); | ||
Assert.Collection(eventData.Payload, | ||
arg => | ||
{ | ||
Assert.Equal("1", arg); | ||
}); | ||
} | ||
|
||
private static HttpConnectionsEventSource GetHttpConnectionEventSource() | ||
{ | ||
return new HttpConnectionsEventSource(Guid.NewGuid().ToString()); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we're renaming anyway, this should probably be called "connections-duration-milliseconds".
If we decide that's too verbose, we should still document the units somewhere. The DisplayName should include "milliseconds" or "ms" somewhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There’s a new display units field coming