diff --git a/build.cake b/build.cake index fdf8059e9..047f7c235 100644 --- a/build.cake +++ b/build.cake @@ -79,7 +79,7 @@ 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"); @@ -87,8 +87,8 @@ Task("Test") { DotNetCoreTest(project.FullPath, new DotNetCoreTestSettings { - Configuration = configuration//, - //Verbose = false + Configuration = configuration, + Verbosity = DotNetCoreVerbosity.Normal }); // if (IsRunningOnWindows()) diff --git a/build.ps1 b/build.ps1 index 7bc2068b5..25fc3dee1 100644 --- a/build.ps1 +++ b/build.ps1 @@ -1,10 +1,44 @@ -$CakeVersion = "0.17.0" +<# +.SYNOPSIS +This is a Powershell script to bootstrap a Cake build. +.DESCRIPTION +This Powershell script will download NuGet if missing, restore NuGet tools (including Cake) +and execute your Cake build script with the parameters you provide. +.PARAMETER Configuration +The build configuration to use. +.PARAMETER Verbosity +Specifies the amount of information to be displayed. +.PARAMETER WhatIf +Performs a dry run of the build script. +No tasks will be executed. +.PARAMETER ScriptArgs +Remaining arguments are added here. +.LINK +https://cakebuild.net +#> + +[CmdletBinding()] +Param( + [ValidateSet("Release", "Debug")] + [string]$Configuration = "Release", + [ValidateSet("Quiet", "Minimal", "Normal", "Verbose", "Diagnostic")] + [string]$Verbosity = "Verbose", + [switch]$WhatIf, + [Parameter(Position=0,Mandatory=$false,ValueFromRemainingArguments=$true)] + [string[]]$ScriptArgs +) + +$CakeVersion = "0.26.1" +$DotNetChannel = "Current"; $DotNetVersion = "1.0.1"; -$DotNetInstallerUri = "https://raw.githubusercontent.com/dotnet/cli/rel/1.0.1/scripts/obtain/dotnet-install.ps1"; +$DotNetInstallerUri = "https://dot.net/v1/dotnet-install.ps1"; +$NugetUrl = "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe" -# Make sure tools folder exists -$PSScriptRoot = $pwd +# Temporarily skip verification of addins. +$ENV:CAKE_SETTINGS_SKIPVERIFICATION='true' +# Make sure tools folder exists +$PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent $ToolPath = Join-Path $PSScriptRoot "tools" if (!(Test-Path $ToolPath)) { Write-Verbose "Creating tools directory..." @@ -15,6 +49,23 @@ if (!(Test-Path $ToolPath)) { # INSTALL .NET CORE CLI ########################################################################### +Function Remove-PathVariable([string]$VariableToRemove) +{ + $path = [Environment]::GetEnvironmentVariable("PATH", "User") + if ($path -ne $null) + { + $newItems = $path.Split(';', [StringSplitOptions]::RemoveEmptyEntries) | Where-Object { "$($_)" -inotlike $VariableToRemove } + [Environment]::SetEnvironmentVariable("PATH", [System.String]::Join(';', $newItems), "User") + } + + $path = [Environment]::GetEnvironmentVariable("PATH", "Process") + if ($path -ne $null) + { + $newItems = $path.Split(';', [StringSplitOptions]::RemoveEmptyEntries) | Where-Object { "$($_)" -inotlike $VariableToRemove } + [Environment]::SetEnvironmentVariable("PATH", [System.String]::Join(';', $newItems), "Process") + } +} + # Get .NET Core CLI path if installed. $FoundDotNetCliVersion = $null; if (Get-Command dotnet -ErrorAction SilentlyContinue) { @@ -27,50 +78,52 @@ if($FoundDotNetCliVersion -ne $DotNetVersion) { mkdir -Force $InstallPath | Out-Null; } (New-Object System.Net.WebClient).DownloadFile($DotNetInstallerUri, "$InstallPath\dotnet-install.ps1"); - & $InstallPath\dotnet-install.ps1 -Channel preview -Version $DotNetVersion -InstallDir $InstallPath; - - $env:DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1 - $env:DOTNET_CLI_TELEMETRY_OPTOUT=1 + & $InstallPath\dotnet-install.ps1 -Channel $DotNetChannel -Version $DotNetVersion -InstallDir $InstallPath; - & dotnet --info + Remove-PathVariable "$InstallPath" + $env:PATH = "$InstallPath;$env:PATH" } +$env:DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1 +$env:DOTNET_CLI_TELEMETRY_OPTOUT=1 + ########################################################################### -# INSTALL CAKE +# INSTALL NUGET ########################################################################### -Add-Type -AssemblyName System.IO.Compression.FileSystem -Function Unzip { - param([string]$zipfile, [string]$outpath) - - [System.IO.Compression.ZipFile]::ExtractToDirectory($zipfile, $outpath) +# Make sure nuget.exe exists. +$NugetPath = Join-Path $ToolPath "nuget.exe" +if (!(Test-Path $NugetPath)) { + Write-Host "Downloading NuGet.exe..." + (New-Object System.Net.WebClient).DownloadFile($NugetUrl, $NugetPath); } +########################################################################### +# INSTALL CAKE +########################################################################### # Make sure Cake has been installed. -$CakePath = Join-Path $ToolPath "Cake.CoreCLR.$CakeVersion/Cake.dll" +$CakePath = Join-Path $ToolPath "Cake.$CakeVersion/Cake.exe" if (!(Test-Path $CakePath)) { Write-Host "Installing Cake..." - (New-Object System.Net.WebClient).DownloadFile("https://www.nuget.org/api/v2/package/Cake.CoreCLR/$CakeVersion", "$ToolPath\Cake.CoreCLR.zip") - Unzip "$ToolPath\Cake.CoreCLR.zip" "$ToolPath/Cake.CoreCLR.$CakeVersion" - Remove-Item "$ToolPath\Cake.CoreCLR.zip" -} - -########################################################################### -# INSTALL NUGET -########################################################################### - -# Make sure NuGet has been installed. -$NugetPath = Join-Path $PSScriptRoot ".nuget/nuget.exe" -if (!(Test-Path $NugetPath)) { - Write-Host "Installing Nuget..." - (New-Object System.Net.WebClient).DownloadFile("https://www.nuget.org/nuget.exe", $NugetPath) - & "$NugetPath" update -self + Invoke-Expression "&`"$NugetPath`" install Cake -Version $CakeVersion -OutputDirectory `"$ToolPath`"" | Out-Null; + if ($LASTEXITCODE -ne 0) { + Throw "An error occurred while restoring Cake from NuGet." + } } ########################################################################### # RUN BUILD SCRIPT ########################################################################### -& dotnet "$CakePath" $args -exit $LASTEXITCODE \ No newline at end of file +# Build the argument list. +$Arguments = @{ + configuration=$Configuration; + verbosity=$Verbosity; + dryrun=$WhatIf; +}.GetEnumerator() | %{"--{0}=`"{1}`"" -f $_.key, $_.value }; + +# Start Cake +Write-Host "Running build script..." +Invoke-Expression "& `"$CakePath`" `"build.cake`" $Arguments $ScriptArgs" +exit $LASTEXITCODE diff --git a/build.sh b/build.sh index a4285f820..a6a3529dd 100644 --- a/build.sh +++ b/build.sh @@ -1,31 +1,96 @@ -#!/bin/bash +#!/usr/bin/env bash +########################################################################## +# This is the Cake bootstrapper script for Linux and OS X. +# This file was downloaded from https://github.com/cake-build/resources +# Feel free to change this file to fit your needs. +########################################################################## -SCRIPT_PATH="${BASH_SOURCE[0]}"; -if ([ -h "${SCRIPT_PATH}" ]) then - while([ -h "${SCRIPT_PATH}" ]) do SCRIPT_PATH=`readlink "${SCRIPT_PATH}"`; done +# Define directories. +SCRIPT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) +TOOLS_DIR=$SCRIPT_DIR/tools +NUGET_EXE=$TOOLS_DIR/nuget.exe +NUGET_URL=https://dist.nuget.org/win-x86-commandline/latest/nuget.exe +CAKE_VERSION=0.26.1 +CAKE_EXE=$TOOLS_DIR/Cake.$CAKE_VERSION/Cake.exe + +# Temporarily skip verification of addins. +export CAKE_SETTINGS_SKIPVERIFICATION='true' + +# Define default arguments. +TARGET="Travis" +CONFIGURATION="Release" +VERBOSITY="verbose" +DRYRUN= +SCRIPT_ARGUMENTS=() + +# Parse arguments. +for i in "$@"; do + case $1 in + -t|--target) TARGET="$2"; shift ;; + -c|--configuration) CONFIGURATION="$2"; shift ;; + -v|--verbosity) VERBOSITY="$2"; shift ;; + -d|--dryrun) DRYRUN="-dryrun" ;; + --) shift; SCRIPT_ARGUMENTS+=("$@"); break ;; + *) SCRIPT_ARGUMENTS+=("$1") ;; + esac + shift +done + +# Make sure the tools folder exist. +if [ ! -d "$TOOLS_DIR" ]; then + mkdir "$TOOLS_DIR" fi -pushd . > /dev/null -cd `dirname ${SCRIPT_PATH}` > /dev/null -SCRIPT_PATH=`pwd`; -popd > /dev/null - -if ! [ -f $SCRIPT_PATH/.nuget/nuget.exe ] - then - wget "https://www.nuget.org/nuget.exe" -P $SCRIPT_PATH/.nuget/ + +########################################################################### +# INSTALL .NET CORE CLI +########################################################################### + +echo "Installing .NET CLI..." +if [ ! -d "$SCRIPT_DIR/.dotnet" ]; then + mkdir "$SCRIPT_DIR/.dotnet" fi +curl -Lsfo "$SCRIPT_DIR/.dotnet/dotnet-install.sh" https://dot.net/v1/dotnet-install.sh +sudo bash "$SCRIPT_DIR/.dotnet/dotnet-install.sh" --version 1.0.1 --install-dir .dotnet --no-path +export PATH="$SCRIPT_DIR/.dotnet":$PATH +export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1 +export DOTNET_CLI_TELEMETRY_OPTOUT=1 +"$SCRIPT_DIR/.dotnet/dotnet" --info -mono $SCRIPT_PATH/.nuget/nuget.exe update -self +########################################################################### +# INSTALL NUGET +########################################################################### -mono $SCRIPT_PATH/.nuget/nuget.exe install FAKE -OutputDirectory $SCRIPT_PATH/packages -ExcludeVersion -Version 4.25.4 +# Download NuGet if it does not exist. +if [ ! -f "$NUGET_EXE" ]; then + echo "Downloading NuGet..." + curl -Lsfo "$NUGET_EXE" $NUGET_URL + if [ $? -ne 0 ]; then + echo "An error occurred while downloading nuget.exe." + exit 1 + fi +fi -mono $SCRIPT_PATH/.nuget/nuget.exe install xunit.runners -OutputDirectory $SCRIPT_PATH/packages/FAKE -ExcludeVersion -Version 2.1.0 -mono $SCRIPT_PATH/.nuget/nuget.exe install NBench.Runner -OutputDirectory packages -ExcludeVersion -Version 0.2.2 +########################################################################### +# INSTALL CAKE +########################################################################### -if ! [ -e $SCRIPT_PATH/packages/SourceLink.Fake/tools/SourceLink.fsx ] ; then - mono $SCRIPT_PATH/.nuget/nuget.exe install SourceLink.Fake -OutputDirectory $SCRIPT_PATH/packages -ExcludeVersion +if [ ! -f "$CAKE_EXE" ]; then + mono "$NUGET_EXE" install Cake -Version $CAKE_VERSION -OutputDirectory "$TOOLS_DIR" + if [ $? -ne 0 ]; then + echo "An error occured while installing Cake." + exit 1 + fi +fi +# Make sure that Cake has been installed. +if [ ! -f "$CAKE_EXE" ]; then + echo "Could not find Cake.exe at '$CAKE_EXE'." + exit 1 fi -export encoding=utf-8 +########################################################################### +# RUN BUILD SCRIPT +########################################################################### -mono $SCRIPT_PATH/packages/FAKE/tools/FAKE.exe build.fsx "$@" +# Start Cake +exec mono "$CAKE_EXE" build.cake --verbosity=$VERBOSITY --configuration=$CONFIGURATION --target=$TARGET $DRYRUN "${SCRIPT_ARGUMENTS[@]}" diff --git a/test/DotNetty.Common.Tests/Internal/Logging/InternalLoggerFactoryTest.cs b/test/DotNetty.Common.Tests/Internal/Logging/InternalLoggerFactoryTest.cs index 67234facb..88115efce 100644 --- a/test/DotNetty.Common.Tests/Internal/Logging/InternalLoggerFactoryTest.cs +++ b/test/DotNetty.Common.Tests/Internal/Logging/InternalLoggerFactoryTest.cs @@ -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; + + public InternalLoggerFactoryTest(ITestOutputHelper output) + { + this.Output = output; + } // todo: CodeContracts on CI //[Fact] //public void ShouldNotAllowNullDefaultFactory() @@ -34,6 +42,7 @@ public void ShouldGetInstance() [Fact] public void TestMockReturned() { + Output.WriteLine("TestMockReturned, Pre:" + RuntimeHelpers.GetHashCode(InternalLoggerFactory.DefaultFactory)); Mock mock; using (SetupMockLogger(out mock)) { @@ -43,20 +52,28 @@ 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)); + Assert.True(false, "To See The Log"); } - static IDisposable SetupMockLogger(out Mock loggerMock) + IDisposable SetupMockLogger(out Mock 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(MockBehavior.Strict); ILoggerProvider mockFactory = factoryMock.Object; loggerMock = new Mock(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)}"); + }); } } } \ No newline at end of file diff --git a/test/DotNetty.Common.Tests/Utilities/HashedWheelTimerTest.cs b/test/DotNetty.Common.Tests/Utilities/HashedWheelTimerTest.cs index 440793dc0..42403e840 100644 --- a/test/DotNetty.Common.Tests/Utilities/HashedWheelTimerTest.cs +++ b/test/DotNetty.Common.Tests/Utilities/HashedWheelTimerTest.cs @@ -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++) @@ -77,6 +78,7 @@ public void TestStopTimer() } Thread.Sleep(1000); // sleep for a second Assert.NotEqual(0, timerUnprocessed.StopAsync().Result.Count); // Number of unprocessed timeouts should be greater than 0 + Assert.True(false, "To See The Log"); } [Fact] // (timeout = 3000)