Skip to content

Commit

Permalink
Test
Browse files Browse the repository at this point in the history
  • Loading branch information
yyjdelete committed Mar 12, 2018
1 parent 846d2e9 commit 492f893
Show file tree
Hide file tree
Showing 5 changed files with 199 additions and 58 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,
Verbosity = DotNetCoreVerbosity.Normal
});

// if (IsRunningOnWindows())
Expand Down
123 changes: 90 additions & 33 deletions build.ps1
Original file line number Diff line number Diff line change
@@ -1,10 +1,47 @@
$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 Target
The build script target to run.
.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(
[string]$Target = "Default",
[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..."
Expand All @@ -15,6 +52,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) {
Expand All @@ -27,50 +81,53 @@ 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
# Build the argument list.
$Arguments = @{
// target=$Target;
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
105 changes: 85 additions & 20 deletions build.sh
Original file line number Diff line number Diff line change
@@ -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[@]}"
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;

public 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,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<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)}");
});
}
}
}
2 changes: 2 additions & 0 deletions test/DotNetty.Common.Tests/Utilities/HashedWheelTimerTest.cs
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 All @@ -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)
Expand Down

0 comments on commit 492f893

Please sign in to comment.