Skip to content

Commit

Permalink
Adding A log presence check before trying to delete (#36779)
Browse files Browse the repository at this point in the history
* checking if log is present before deleteing

* Update src/libraries/System.Diagnostics.EventLog/tests/EventLogTests/EventLogSourceCreationTests.cs

Co-authored-by: Krzysztof Wicher <mordotymoja@gmail.com>

Co-authored-by: Krzysztof Wicher <mordotymoja@gmail.com>
  • Loading branch information
Anipik and krwq authored May 21, 2020
1 parent 6e30997 commit 96401ea
Showing 1 changed file with 11 additions and 10 deletions.
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));
}

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

0 comments on commit 96401ea

Please sign in to comment.