This commit is contained in:
Arvind Ranasaria
2018-10-19 13:25:18 -07:00
committed by GitHub
parent 0efed221ee
commit 1ef70ef259
18 changed files with 323 additions and 338 deletions

View File

@@ -5,6 +5,7 @@
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Threading.Tasks;
using Microsoft.SqlTools.ServiceLayer.Test.Common;
using Microsoft.SqlTools.Utility;
using Xunit;
@@ -333,6 +334,33 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ServiceHost
TestTracingLevelChangeFromWarningToError(test);
}
/// <summary>
/// Tests out AutoFlush funcitonality. The verification is two fold.
/// 1st is to verify that the setting is persistent.
/// 2nd that after a lot of log entries are written with AutoFlush on, explicitly flushing and closing the Tracing does not increase the file size
/// thereby verifying that there was no leftover log entries being left behind to be flushed.
/// </summary>
[Fact]
public void LoggerAutolFlush()
{
// setup the test object
TestLogger test = new TestLogger()
{
TraceSource = MethodInfo.GetCurrentMethod().Name,
AutoFlush = true,
TracingLevel = SourceLevels.All
};
test.Initialize();
// Write 10000 lines of log
Parallel.For(0, 100, (i) => test.Write($"Message Number:{i}, Message:{test.LogMessage}"));
long logContentsSizeBeforeExplicitFlush = (new FileInfo(test.LogFileName)).Length;
// Please note that Logger.Close() first flushes the logs before closing them out.
Logger.Flush();
long logContentsSizeAfterExplicitFlush = (new FileInfo(test.LogFileName)).Length;
Assert.True(logContentsSizeBeforeExplicitFlush == logContentsSizeAfterExplicitFlush, "The length of log file with autoflush before and after explicit flush must be same");
test.Cleanup();
}
/// <summary>
/// When not use TraceSource, test to verify that upon changing TracingLevel from Error To Warning,
/// after the change, messages of Warning as well as of Error type are present in the log.