From 958ead90548b10cdd8ec15bafc0f4ec3ec6ba489 Mon Sep 17 00:00:00 2001 From: Stephen Toub Date: Tue, 18 Jun 2019 18:06:45 -0400 Subject: [PATCH] Fix GetLogInformation_UsingLogName_DoesNotThrow test (dotnet/corefx#38653) The test was doing multiple reads from the underlying log and expecting them to be equivalent. That's not guaranteed, as it's a global machine resource. Commit migrated from https://github.com/dotnet/corefx/commit/475056abaaf3b1e9e29088c992157b415a800e54 --- .../Diagnostics/Reader/EventLogInformationTests.cs | 45 +++++++--------------- 1 file changed, 14 insertions(+), 31 deletions(-) diff --git a/src/libraries/System.Diagnostics.EventLog/tests/System/Diagnostics/Reader/EventLogInformationTests.cs b/src/libraries/System.Diagnostics.EventLog/tests/System/Diagnostics/Reader/EventLogInformationTests.cs index 07b9405..e766219 100644 --- a/src/libraries/System.Diagnostics.EventLog/tests/System/Diagnostics/Reader/EventLogInformationTests.cs +++ b/src/libraries/System.Diagnostics.EventLog/tests/System/Diagnostics/Reader/EventLogInformationTests.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information. using System.Diagnostics.Eventing.Reader; +using Microsoft.DotNet.XUnitExtensions; using Xunit; namespace System.Diagnostics.Tests @@ -25,50 +26,32 @@ namespace System.Diagnostics.Tests [InlineData("Application")] public void GetLogInformation_UsingLogName_DoesNotThrow(string logName) { - DateTime? creationTime, lastAccessTime, lastWriteTime; - long? fileSize, recordCount, oldestRecordNumber; - int? attributes; - bool? isLogFull; using (var session = new EventLogSession()) { - EventLogConfiguration configuration = null; + EventLogConfiguration configuration; try { configuration = new EventLogConfiguration(logName, session); } catch (EventLogNotFoundException) { - configuration?.Dispose(); - return; + throw new SkipTestException(nameof(EventLogNotFoundException)); } - EventLogInformation logInfo = session.GetLogInformation(configuration.LogName, PathType.LogName); - creationTime = logInfo.CreationTime; - lastAccessTime = logInfo.LastAccessTime; - lastWriteTime = logInfo.LastWriteTime; - fileSize = logInfo.FileSize; - attributes = logInfo.Attributes; - recordCount = logInfo.RecordCount; - oldestRecordNumber = logInfo.OldestRecordNumber; - isLogFull = logInfo.IsLogFull; - - configuration.Dispose(); - } - using (var session = new EventLogSession()) - { - using (var configuration = new EventLogConfiguration(logName, session)) + using (configuration) { EventLogInformation logInfo = session.GetLogInformation(configuration.LogName, PathType.LogName); - Assert.Equal(creationTime, logInfo.CreationTime); - Assert.Equal(lastAccessTime, logInfo.LastAccessTime); - Assert.Equal(lastWriteTime, logInfo.LastWriteTime); - Assert.Equal(fileSize, logInfo.FileSize); - Assert.Equal(attributes, logInfo.Attributes); - Assert.Equal(recordCount, logInfo.RecordCount); - Assert.Equal(oldestRecordNumber, logInfo.OldestRecordNumber); - Assert.Equal(isLogFull, logInfo.IsLogFull); + + Assert.Equal(logInfo.CreationTime, logInfo.CreationTime); + Assert.Equal(logInfo.LastAccessTime, logInfo.LastAccessTime); + Assert.Equal(logInfo.LastWriteTime, logInfo.LastWriteTime); + Assert.Equal(logInfo.FileSize, logInfo.FileSize); + Assert.Equal(logInfo.Attributes, logInfo.Attributes); + Assert.Equal(logInfo.RecordCount, logInfo.RecordCount); + Assert.Equal(logInfo.OldestRecordNumber, logInfo.OldestRecordNumber); + Assert.Equal(logInfo.IsLogFull, logInfo.IsLogFull); } } } } -} \ No newline at end of file +} -- 2.7.4