Skip to content

Conversation

@benedikt257
Copy link
Contributor

Make tests for FileLoggerProcessor system time independent

Adapted tests for FileLoggerProcessor and its test so that they are no longer system time dependent.

Description

Slightly changed the implementation of FileLoggerProcessor to allow setting a date time provider from tests. I adapted the existing unit tests by taking out any handling of possible date roll-overs during test execution and added a new test explicitly testing for that behavior.

Fixes #34807

@ghost ghost added area-runtime community-contribution Indicates that the PR has been added by a community member labels Oct 21, 2021
@dnfadmin
Copy link

dnfadmin commented Oct 21, 2021

CLA assistant check
All CLA requirements met.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reckon this initialization is kind of redundant here - the first invocation of a write will set the date to the current datetime anyhow when the absolute difference between _today and it is positive.
Kept it because it makes it consistent with the previous implementation though - let me know if you think it should be removed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like explicitly initializing it when the Processor starts, rather than when the first message is written (that is, don't remove this)

@benedikt257 benedikt257 force-pushed the 34807-filelogger-systemtime-independent branch from 1646cbf to 89be432 Compare October 21, 2021 19:49
@benedikt257 benedikt257 marked this pull request as ready for review October 21, 2021 21:22
@BrennanConroy BrennanConroy requested a review from wtgodbe October 21, 2021 23:13
Copy link
Member

@wtgodbe wtgodbe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great, thanks!

// The .NET Foundation licenses this file to you under the MIT license.

internal interface ISystemDateTime {
DateTime Now { get; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a <summary>:

/// <summary>
/// Retrieves ticks for the current system up time.
/// </summary>

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, thanks for the review!

@wtgodbe
Copy link
Member

wtgodbe commented Oct 23, 2021

CI failures are unrelated and should now be fixed - if you push another commit adding the doc comment, I expect CI will go green.

@wtgodbe wtgodbe enabled auto-merge (squash) October 25, 2021 16:12
@wtgodbe wtgodbe merged commit 3c1b067 into dotnet:main Oct 25, 2021
@ghost ghost added this to the 7.0-preview1 milestone Oct 25, 2021
@wtgodbe
Copy link
Member

wtgodbe commented Oct 25, 2021

Thanks @benedikt257!

@amcasey amcasey added area-middleware Includes: URL rewrite, redirect, response cache/compression, session, and other general middlewares and removed area-runtime labels Jun 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-middleware Includes: URL rewrite, redirect, response cache/compression, session, and other general middlewares community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Mock System Clock for FileLoggerProcessor Tests

4 participants