Fix flaky EventLogCollector test: ensure deterministic event log entries by nohwnd · Pull Request #15607 · microsoft/vstest (original) (raw)

Problem

The test \WriteEventLogEntriesToXmlFileShouldWriteLogEntryIfPresent\ in \EventLogXmlWriterTests.cs\ was flaky for two reasons:

  1. Empty event log: It assumed the Application event log always has entries (\�ventLog.Entries[eventLog.Entries.Count - 1]), which fails on clean/quiet machines with an empty Application log.
  2. Newline serialization mismatch: It used \XElement\ to predict how \DataSet.WriteXml\ would serialize the message. \XElement.ToString()\ normalizes lone \n\ to \r\n, but \DataSet.WriteXml\ preserves the original \n, causing \string.Contains\ to return false for messages with \n\ line endings.

Fix

Closes #15601