|
|
@ -1,6 +1,7 @@
|
|
|
|
using System;
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
using System.Threading;
|
|
|
|
using NLog;
|
|
|
|
using NLog;
|
|
|
|
using NLog.Targets;
|
|
|
|
using NLog.Targets;
|
|
|
|
using NUnit.Framework;
|
|
|
|
using NUnit.Framework;
|
|
|
@ -11,17 +12,27 @@ namespace NzbDrone.Test.Common
|
|
|
|
{
|
|
|
|
{
|
|
|
|
private static List<LogEventInfo> _logs = new List<LogEventInfo>();
|
|
|
|
private static List<LogEventInfo> _logs = new List<LogEventInfo>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static ManualResetEventSlim _waitEvent = new ManualResetEventSlim();
|
|
|
|
|
|
|
|
|
|
|
|
protected override void Write(LogEventInfo logEvent)
|
|
|
|
protected override void Write(LogEventInfo logEvent)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
lock (_logs)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (logEvent.Level >= LogLevel.Warn)
|
|
|
|
if (logEvent.Level >= LogLevel.Warn)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_logs.Add(logEvent);
|
|
|
|
_logs.Add(logEvent);
|
|
|
|
|
|
|
|
_waitEvent.Set();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static void Reset()
|
|
|
|
public static void Reset()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_logs = new List<LogEventInfo>();
|
|
|
|
lock (_logs)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
_logs.Clear();
|
|
|
|
|
|
|
|
_waitEvent.Reset();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static void AssertNoUnexpectedLogs()
|
|
|
|
public static void AssertNoUnexpectedLogs()
|
|
|
@ -47,6 +58,29 @@ namespace NzbDrone.Test.Common
|
|
|
|
return errors;
|
|
|
|
return errors;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static void WaitForErrors(int count, int msec)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
while (true)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
lock (_logs)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var levelLogs = _logs.Where(l => l.Level == LogLevel.Error).ToList();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (levelLogs.Count >= count)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_waitEvent.Reset();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!_waitEvent.Wait(msec))
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Expected(LogLevel.Error, count);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static void ExpectedErrors(int count)
|
|
|
|
public static void ExpectedErrors(int count)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Expected(LogLevel.Error, count);
|
|
|
|
Expected(LogLevel.Error, count);
|
|
|
@ -73,6 +107,8 @@ namespace NzbDrone.Test.Common
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static void MarkInconclusive(Type exception)
|
|
|
|
public static void MarkInconclusive(Type exception)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
lock (_logs)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var inconclusiveLogs = _logs.Where(l => l.Exception != null && l.Exception.GetType() == exception).ToList();
|
|
|
|
var inconclusiveLogs = _logs.Where(l => l.Exception != null && l.Exception.GetType() == exception).ToList();
|
|
|
|
|
|
|
|
|
|
|
@ -82,8 +118,11 @@ namespace NzbDrone.Test.Common
|
|
|
|
Assert.Inconclusive(GetLogsString(inconclusiveLogs));
|
|
|
|
Assert.Inconclusive(GetLogsString(inconclusiveLogs));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static void MarkInconclusive(string text)
|
|
|
|
public static void MarkInconclusive(string text)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
lock (_logs)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var inconclusiveLogs = _logs.Where(l => l.FormattedMessage.ToLower().Contains(text.ToLower())).ToList();
|
|
|
|
var inconclusiveLogs = _logs.Where(l => l.FormattedMessage.ToLower().Contains(text.ToLower())).ToList();
|
|
|
|
|
|
|
|
|
|
|
@ -93,8 +132,11 @@ namespace NzbDrone.Test.Common
|
|
|
|
Assert.Inconclusive(GetLogsString(inconclusiveLogs));
|
|
|
|
Assert.Inconclusive(GetLogsString(inconclusiveLogs));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static void Expected(LogLevel level, int count)
|
|
|
|
private static void Expected(LogLevel level, int count)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
lock (_logs)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var levelLogs = _logs.Where(l => l.Level == level).ToList();
|
|
|
|
var levelLogs = _logs.Where(l => l.Level == level).ToList();
|
|
|
|
|
|
|
|
|
|
|
@ -113,11 +155,15 @@ namespace NzbDrone.Test.Common
|
|
|
|
|
|
|
|
|
|
|
|
levelLogs.ForEach(c => _logs.Remove(c));
|
|
|
|
levelLogs.ForEach(c => _logs.Remove(c));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static void Ignore(LogLevel level)
|
|
|
|
private static void Ignore(LogLevel level)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
lock (_logs)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var levelLogs = _logs.Where(l => l.Level == level).ToList();
|
|
|
|
var levelLogs = _logs.Where(l => l.Level == level).ToList();
|
|
|
|
levelLogs.ForEach(c => _logs.Remove(c));
|
|
|
|
levelLogs.ForEach(c => _logs.Remove(c));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|