Event Log Target unit tests improvement #575
Merged
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.
I've noticed that EventLogTarget tests run relatively slow on my machine: approximately 5 sec per every test in the
EventLogTargetTests
fixture.When I digged into the tests, I've found 2 issues:
EventLogTarget.Source
property is not specified explicitly, and that results in AppDomain name being used as the source name. When the unit test runner executes tests, it creates an app domain with a random name (namely, random Guid). So on every test run a new source is created, thus polluting system registry with source names, that will never be used again.To prevent this I've set fixed source name
NLog.UnitTests
.EventLog.EntryWritten
event have a handler attached, which collects all events written to this log. Then these collected entries are used to find the event entry being tested.