Skip to content

Commit

Permalink
Test
Browse files Browse the repository at this point in the history
  • Loading branch information
yyjdelete committed Mar 11, 2018
1 parent 846d2e9 commit 7bcf537
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
6 changes: 3 additions & 3 deletions build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,16 @@ Task("Test")
.IsDependentOn("Compile")
.Does(() =>
{
var projects = GetFiles("./test/**/*.csproj")
var projects = GetFiles("./test/DotNetty.Common.Tests/*.csproj")
- GetFiles("./test/**/*.Microbench.csproj")
- GetFiles("./test/**/*.Performance.csproj");
foreach(var project in projects)
{
DotNetCoreTest(project.FullPath, new DotNetCoreTestSettings
{
Configuration = configuration//,
//Verbose = false
Configuration = configuration,
Verbose = true
});
// if (IsRunningOnWindows())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,23 @@
namespace DotNetty.Common.Tests.Internal.Logging
{
using System;
using System.Runtime.CompilerServices;
using DotNetty.Common.Internal.Logging;
using DotNetty.Tests.Common;
using Microsoft.Extensions.Logging;
using Moq;
using Xunit;
using Xunit.Abstractions;

[CollectionDefinition(nameof(InternalLoggerFactoryTest), DisableParallelization = true)]
public class InternalLoggerFactoryTest
{
protected readonly ITestOutputHelper Output;

protected InternalLoggerFactoryTest(ITestOutputHelper output)
{
this.Output = output;
}
// todo: CodeContracts on CI
//[Fact]
//public void ShouldNotAllowNullDefaultFactory()
Expand All @@ -34,6 +42,7 @@ public void ShouldGetInstance()
[Fact]
public void TestMockReturned()
{
Output.WriteLine("TestMockReturned, Pre:" + RuntimeHelpers.GetHashCode(InternalLoggerFactory.DefaultFactory));
Mock<ILogger> mock;
using (SetupMockLogger(out mock))
{
Expand All @@ -43,20 +52,27 @@ public void TestMockReturned()

Assert.True(logger.TraceEnabled);
mock.Verify(x => x.IsEnabled(LogLevel.Trace), Times.Once);
Output.WriteLine("TestMockReturned, Finish:" + RuntimeHelpers.GetHashCode(InternalLoggerFactory.DefaultFactory));
}
Output.WriteLine("TestMockReturned, Post:" + RuntimeHelpers.GetHashCode(InternalLoggerFactory.DefaultFactory));
}

static IDisposable SetupMockLogger(out Mock<ILogger> loggerMock)
IDisposable SetupMockLogger(out Mock<ILogger> loggerMock)
{
ILoggerFactory oldLoggerFactory = InternalLoggerFactory.DefaultFactory;
Output.WriteLine($"SetupMockLogger,oldLoggerFactory={RuntimeHelpers.GetHashCode(oldLoggerFactory)}");
var loggerFactory = new LoggerFactory();
Output.WriteLine($"SetupMockLogger,loggerFactory={RuntimeHelpers.GetHashCode(loggerFactory)}");
var factoryMock = new Mock<ILoggerProvider>(MockBehavior.Strict);
ILoggerProvider mockFactory = factoryMock.Object;
loggerMock = new Mock<ILogger>(MockBehavior.Strict);
loggerFactory.AddProvider(mockFactory);
factoryMock.Setup(x => x.CreateLogger("mock")).Returns(loggerMock.Object);
InternalLoggerFactory.DefaultFactory = loggerFactory;
return new Disposable(() => InternalLoggerFactory.DefaultFactory = oldLoggerFactory);
return new Disposable(() => {
InternalLoggerFactory.DefaultFactory = oldLoggerFactory;
Output.WriteLine($"SetupMockLogger,Dispose to={RuntimeHelpers.GetHashCode(oldLoggerFactory)}");
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public void TestScheduleTimeoutShouldRunAfterDelay()
[Fact] // (timeout = 3000)
public void TestStopTimer()
{
Output.WriteLine($"{System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(DotNetty.Common.Internal.Logging.InternalLoggerFactory.DefaultFactory)}");
var latch = new CountdownEvent(3);
ITimer timerProcessed = new HashedWheelTimer();
for (int i = 0; i < 3; i++)
Expand Down

0 comments on commit 7bcf537

Please sign in to comment.