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

Adding A log presence check before trying to delete #36779

Merged
merged 2 commits into from
May 21, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@
// See the LICENSE file in the project root for more information.

using Xunit;
using Microsoft.DotNet.XUnitExtensions;

namespace System.Diagnostics.Tests
{
public class EventLogSourceCreationTests
{
[ActiveIssue("https://github.com/dotnet/runtime/issues/36135")]
[ConditionalFact(typeof(Helpers), nameof(Helpers.IsElevatedAndSupportsEventLogs))]
public void CheckSourceExistenceAndDeletion()
{
Expand All @@ -23,13 +21,13 @@ public void CheckSourceExistenceAndDeletion()
finally
{
EventLog.DeleteEventSource(source);
Helpers.Retry(() => EventLog.Delete(log)); // unlike other tests, throw if delete fails
if (EventLog.Exists(log))
Helpers.Retry(() => EventLog.Delete(log));
Copy link
Member

Choose a reason for hiding this comment

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

I know this was here before but just curious why is this being retried?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Eventlog delete operation changes the registry and we require locks for that. As in our tests, multiple threads are trying to achieve the same, sometimes it fails while waiting.

}

Assert.False(EventLog.SourceExists(source));
}

[ActiveIssue("https://github.com/dotnet/runtime/issues/36135")]
[ConditionalFact(typeof(Helpers), nameof(Helpers.IsElevatedAndSupportsEventLogs))]
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework)]
public void LogNameWithSame8FirstChars_NetCore()
Expand All @@ -50,13 +48,15 @@ public void LogNameWithSame8FirstChars_NetCore()
finally
{
EventLog.DeleteEventSource(firstSource);
Helpers.Retry(() => EventLog.Delete(firstLog));
if (EventLog.Exists(firstLog))
Helpers.Retry(() => EventLog.Delete(firstLog));

EventLog.DeleteEventSource(secondSource);
Helpers.Retry(() => EventLog.Delete(secondLog));
if (EventLog.Exists(secondLog))
Helpers.Retry(() => EventLog.Delete(secondLog));
}
}

[ActiveIssue("https://github.com/dotnet/runtime/issues/36135")]
[ConditionalFact(typeof(Helpers), nameof(Helpers.IsElevatedAndSupportsEventLogs))]
[SkipOnTargetFramework(~TargetFrameworkMonikers.NetFramework)]
public void LogNameWithSame8FirstChars_NetFramework()
Expand All @@ -75,7 +75,8 @@ public void LogNameWithSame8FirstChars_NetFramework()
finally
{
EventLog.DeleteEventSource(firstSource);
Helpers.Retry(() => EventLog.Delete(firstLog));
if (EventLog.Exists(firstLog))
Helpers.Retry(() => EventLog.Delete(firstLog));
}
}

Expand Down Expand Up @@ -145,7 +146,6 @@ public void SourceDataNull()
Assert.Throws<ArgumentNullException>(() => EventLog.CreateEventSource(null));
}

[ActiveIssue("https://github.com/dotnet/runtime/issues/36135")]
[ConditionalFact(typeof(Helpers), nameof(Helpers.IsElevatedAndSupportsEventLogs))]
public void SourceAlreadyExistsWhenCreatingSource()
{
Expand All @@ -160,7 +160,8 @@ public void SourceAlreadyExistsWhenCreatingSource()
finally
{
EventLog.DeleteEventSource(source);
Helpers.RetrySilently(() => EventLog.Delete(log));
if (EventLog.Exists(log))
Helpers.RetrySilently(() => EventLog.Delete(log));
}
}

Expand Down