-
Notifications
You must be signed in to change notification settings - Fork 524
Conversation
@@ -147,7 +147,8 @@ public class AddressRegistrationTests | |||
{ | |||
host.Start(); | |||
|
|||
var debugLog = testLogger.Messages.Single(log => log.LogLevel == LogLevel.Debug); | |||
var debugLog = testLogger.Messages.Single(log => log.LogLevel == LogLevel.Debug && | |||
!log.Message.StartsWith("hosting", StringComparison.OrdinalIgnoreCase)); |
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.
Need to filter out two hosting logs "Hosting starting" and "Hosting started".
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.
Do a case-sensitive comparison. You want to be as specific as possible here.
@@ -147,7 +147,8 @@ public class AddressRegistrationTests | |||
{ | |||
host.Start(); | |||
|
|||
var debugLog = testLogger.Messages.Single(log => log.LogLevel == LogLevel.Debug); | |||
var debugLog = testLogger.Messages.Single(log => log.LogLevel == LogLevel.Debug && | |||
!log.Message.StartsWith("hosting", StringComparison.OrdinalIgnoreCase)); |
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.
Do a case-sensitive comparison. You want to be as specific as possible here.
Some thoughts:
I know those things were already there, but since you're at it... 😄 |
I agree with @CesarBS about testing both 127.0.0.1:5000 and [::1]:5000 though. |
The changes in https://github.com/aspnet/KestrelHttpServer/pull/1312/files seems to only add the ipv4 by default when no address is configured. I'll need to address #1434 and bind to both by default. I'll adapt this PR and actually change the behaviour. |
Right, I forgot that the change to hosting was going to break that. It's slightly trickier to fix than it looks since we need to special case not throwing in KestrelServer.Start if binding to only one of 127.0.0.1:5000 and [::1]:5000 fails (like on Azure Web Apps). We also need to make sure the logs aren't too scary when the binding fails. @JunTaoLuo Merge this as is. |
I see okay then I'll just merge the current changes. |
🆙📅 @CesarBS |
934c469
to
a0ee9b7
Compare
|
||
var debugLog = testLogger.Messages.Single(log => log.LogLevel == LogLevel.Debug && | ||
!log.Message.StartsWith("Hosting start", StringComparison.Ordinal)); // Filter out "Hosting starting" and "Hosting started" | ||
Assert.True(string.Equals(debugLog.Message, $"No listening endpoints were configured. Binding to {Constants.DefaultIPEndPoint} by default.", StringComparison.Ordinal)); |
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.
Can make this simpler by doing
Assert.Equal(
$"No listening endpoints were configured. Binding to {Constants.DefaultIPEndPoint} by default.",
testLogger.Messages.SingleOrDefault(log => log.LogLevel == LogLevel.Debug && !log.Message.StartsWith("Hosting start", StringComparison.Ordinal)));
var debugLog = testLogger.Messages.Single(log => log.LogLevel == LogLevel.Debug && | ||
!log.Message.StartsWith("Hosting start", StringComparison.Ordinal)); // Filter out "Hosting starting" and "Hosting started" | ||
Assert.True(string.Equals(debugLog.Message, $"No listening endpoints were configured. Binding to {Constants.DefaultIPEndPoint} by default.", StringComparison.Ordinal)); | ||
Assert.Equal($"No listening endpoints were configured. Binding to {Constants.DefaultIPEndPoint} by default.", |
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.
Even simpler (sorry, should have realized this earlier):
Assert.NotNull(testLogger.Messages.SingleOrDefault(log =>
log.LogLevel == LogLevel.Debug &&
log.Message.Equals($"No listening endpoints were configured. Binding to {Constants.DefaultIPEndPoint} by default.", StringComparison.Ordinal)));
You get your StringComparison.Ordinal
back 😝
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.
That depends on the original intention of the test. I read it as, there is only one message from Kestrel and it's the binding to default address test. With this change, it becomes, there's is only one binding to default address message but I don't care if there are other messages from Kestrel. Functionally, there's no difference since right now there is only one message on startup.
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.
All we care about is checking that the message is logged. Doesn't matter if there are other messages in there.
BTW, xUnit has Assert.Single
which makes this even shorter 😄
fe78f02
to
c959c5b
Compare
|
||
foreach (var testUrl in new[] { "http://127.0.0.1:5000", "http://localhost:5000" }) | ||
foreach (var testUrl in new[] { "http://127.0.0.1:5000", /* "http://[::1]:5000" */}) |
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.
Don't leave IPv6 commented out if it's currently not part of the default binding. We can add it if/when it becomes the default.
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.
We need to add it back soon. Similar to 4533383.
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.
When is soon?
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.
I'm working on it now
var debugLog = testLogger.Messages.Single(log => log.LogLevel == LogLevel.Debug); | ||
Assert.True(debugLog.Message.Contains("default")); | ||
Assert.Equal(5000, host.GetPort()); | ||
Assert.Single(testLogger.Messages.Where(log => log.LogLevel == LogLevel.Debug && |
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.
Use the overload that takes a collection and a predicate, then you don't need the Where
.
c959c5b
to
335b7c2
Compare
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.
🚢 when green.
335b7c2
to
7d94abd
Compare
aspnet/Hosting#917 has now been merged. So enabling this test. Will merge to feature/dev-si once approved.