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

Event Log Target unit tests improvement #575

Merged
merged 3 commits into from
Feb 19, 2015

Conversation

ilya-g
Copy link
Contributor

@ilya-g ilya-g commented Feb 14, 2015

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:

  1. The 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.
  2. Every test in this fixture required to scan the entire Application log to find events it had written before. I've found a different approach to verify that an event is created. The 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.

Do not scan the entire Application log in every test – monitor the eventLog for new events instead.
50ms might be not enough for appveyor environment.
…ng the eventlog after logging, but now classes from System.Diagnostics.Eventing.Reader are used allowing efficient querying for events from newest to oldest.
@ilya-g
Copy link
Contributor Author

ilya-g commented Feb 15, 2015

Seems that an approach with watching for EventLog.EntryWritten event is not suitable for AppVeyor environment, so I switched back to querying the eventlog, but now with the System.Diagnostics.Eventing.Reader.EventLogReader class.

Now these tests run almost instantaneously in Visual Studio and 2 times faster in AppVeyor.

@304NotModified 304NotModified added the enhancement Improvement on existing feature label Feb 15, 2015
@304NotModified
Copy link
Member

👍

304NotModified added a commit that referenced this pull request Feb 19, 2015
Event Log Target unit tests improvement
@304NotModified 304NotModified merged commit a8d7cab into NLog:master Feb 19, 2015
@ilya-g ilya-g deleted the EventLogTestsImprovements branch February 20, 2015 01:48
@304NotModified 304NotModified modified the milestone: 4.0 Feb 21, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improvement on existing feature event-log-target
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants