Skip to content

Commit 492f893

Browse files
committed
Test
1 parent 846d2e9 commit 492f893

File tree

5 files changed

+199
-58
lines changed

5 files changed

+199
-58
lines changed

build.cake

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,16 +79,16 @@ Task("Test")
7979
.IsDependentOn("Compile")
8080
.Does(() =>
8181
{
82-
var projects = GetFiles("./test/**/*.csproj")
82+
var projects = GetFiles("./test/DotNetty.Common.Tests/*.csproj")
8383
- GetFiles("./test/**/*.Microbench.csproj")
8484
- GetFiles("./test/**/*.Performance.csproj");
8585

8686
foreach(var project in projects)
8787
{
8888
DotNetCoreTest(project.FullPath, new DotNetCoreTestSettings
8989
{
90-
Configuration = configuration//,
91-
//Verbose = false
90+
Configuration = configuration,
91+
Verbosity = DotNetCoreVerbosity.Normal
9292
});
9393

9494
// if (IsRunningOnWindows())

build.ps1

Lines changed: 90 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,47 @@
1-
$CakeVersion = "0.17.0"
1+
<#
2+
.SYNOPSIS
3+
This is a Powershell script to bootstrap a Cake build.
4+
.DESCRIPTION
5+
This Powershell script will download NuGet if missing, restore NuGet tools (including Cake)
6+
and execute your Cake build script with the parameters you provide.
7+
.PARAMETER Target
8+
The build script target to run.
9+
.PARAMETER Configuration
10+
The build configuration to use.
11+
.PARAMETER Verbosity
12+
Specifies the amount of information to be displayed.
13+
.PARAMETER WhatIf
14+
Performs a dry run of the build script.
15+
No tasks will be executed.
16+
.PARAMETER ScriptArgs
17+
Remaining arguments are added here.
18+
.LINK
19+
https://cakebuild.net
20+
#>
21+
22+
[CmdletBinding()]
23+
Param(
24+
[string]$Target = "Default",
25+
[ValidateSet("Release", "Debug")]
26+
[string]$Configuration = "Release",
27+
[ValidateSet("Quiet", "Minimal", "Normal", "Verbose", "Diagnostic")]
28+
[string]$Verbosity = "Verbose",
29+
[switch]$WhatIf,
30+
[Parameter(Position=0,Mandatory=$false,ValueFromRemainingArguments=$true)]
31+
[string[]]$ScriptArgs
32+
)
33+
34+
$CakeVersion = "0.26.1"
35+
$DotNetChannel = "Current";
236
$DotNetVersion = "1.0.1";
3-
$DotNetInstallerUri = "https://raw.githubusercontent.com/dotnet/cli/rel/1.0.1/scripts/obtain/dotnet-install.ps1";
37+
$DotNetInstallerUri = "https://dot.net/v1/dotnet-install.ps1";
38+
$NugetUrl = "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe"
439

5-
# Make sure tools folder exists
6-
$PSScriptRoot = $pwd
40+
# Temporarily skip verification of addins.
41+
$ENV:CAKE_SETTINGS_SKIPVERIFICATION='true'
742

43+
# Make sure tools folder exists
44+
$PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent
845
$ToolPath = Join-Path $PSScriptRoot "tools"
946
if (!(Test-Path $ToolPath)) {
1047
Write-Verbose "Creating tools directory..."
@@ -15,6 +52,23 @@ if (!(Test-Path $ToolPath)) {
1552
# INSTALL .NET CORE CLI
1653
###########################################################################
1754

55+
Function Remove-PathVariable([string]$VariableToRemove)
56+
{
57+
$path = [Environment]::GetEnvironmentVariable("PATH", "User")
58+
if ($path -ne $null)
59+
{
60+
$newItems = $path.Split(';', [StringSplitOptions]::RemoveEmptyEntries) | Where-Object { "$($_)" -inotlike $VariableToRemove }
61+
[Environment]::SetEnvironmentVariable("PATH", [System.String]::Join(';', $newItems), "User")
62+
}
63+
64+
$path = [Environment]::GetEnvironmentVariable("PATH", "Process")
65+
if ($path -ne $null)
66+
{
67+
$newItems = $path.Split(';', [StringSplitOptions]::RemoveEmptyEntries) | Where-Object { "$($_)" -inotlike $VariableToRemove }
68+
[Environment]::SetEnvironmentVariable("PATH", [System.String]::Join(';', $newItems), "Process")
69+
}
70+
}
71+
1872
# Get .NET Core CLI path if installed.
1973
$FoundDotNetCliVersion = $null;
2074
if (Get-Command dotnet -ErrorAction SilentlyContinue) {
@@ -27,50 +81,53 @@ if($FoundDotNetCliVersion -ne $DotNetVersion) {
2781
mkdir -Force $InstallPath | Out-Null;
2882
}
2983
(New-Object System.Net.WebClient).DownloadFile($DotNetInstallerUri, "$InstallPath\dotnet-install.ps1");
30-
& $InstallPath\dotnet-install.ps1 -Channel preview -Version $DotNetVersion -InstallDir $InstallPath;
31-
32-
$env:DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1
33-
$env:DOTNET_CLI_TELEMETRY_OPTOUT=1
84+
& $InstallPath\dotnet-install.ps1 -Channel $DotNetChannel -Version $DotNetVersion -InstallDir $InstallPath;
3485

35-
& dotnet --info
86+
Remove-PathVariable "$InstallPath"
87+
$env:PATH = "$InstallPath;$env:PATH"
3688
}
3789

90+
$env:DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1
91+
$env:DOTNET_CLI_TELEMETRY_OPTOUT=1
92+
3893
###########################################################################
39-
# INSTALL CAKE
94+
# INSTALL NUGET
4095
###########################################################################
4196

42-
Add-Type -AssemblyName System.IO.Compression.FileSystem
43-
Function Unzip {
44-
param([string]$zipfile, [string]$outpath)
45-
46-
[System.IO.Compression.ZipFile]::ExtractToDirectory($zipfile, $outpath)
97+
# Make sure nuget.exe exists.
98+
$NugetPath = Join-Path $ToolPath "nuget.exe"
99+
if (!(Test-Path $NugetPath)) {
100+
Write-Host "Downloading NuGet.exe..."
101+
(New-Object System.Net.WebClient).DownloadFile($NugetUrl, $NugetPath);
47102
}
48103

104+
###########################################################################
105+
# INSTALL CAKE
106+
###########################################################################
49107

50108
# Make sure Cake has been installed.
51-
$CakePath = Join-Path $ToolPath "Cake.CoreCLR.$CakeVersion/Cake.dll"
109+
$CakePath = Join-Path $ToolPath "Cake.$CakeVersion/Cake.exe"
52110
if (!(Test-Path $CakePath)) {
53111
Write-Host "Installing Cake..."
54-
(New-Object System.Net.WebClient).DownloadFile("https://www.nuget.org/api/v2/package/Cake.CoreCLR/$CakeVersion", "$ToolPath\Cake.CoreCLR.zip")
55-
Unzip "$ToolPath\Cake.CoreCLR.zip" "$ToolPath/Cake.CoreCLR.$CakeVersion"
56-
Remove-Item "$ToolPath\Cake.CoreCLR.zip"
57-
}
58-
59-
###########################################################################
60-
# INSTALL NUGET
61-
###########################################################################
62-
63-
# Make sure NuGet has been installed.
64-
$NugetPath = Join-Path $PSScriptRoot ".nuget/nuget.exe"
65-
if (!(Test-Path $NugetPath)) {
66-
Write-Host "Installing Nuget..."
67-
(New-Object System.Net.WebClient).DownloadFile("https://www.nuget.org/nuget.exe", $NugetPath)
68-
& "$NugetPath" update -self
112+
Invoke-Expression "&`"$NugetPath`" install Cake -Version $CakeVersion -OutputDirectory `"$ToolPath`"" | Out-Null;
113+
if ($LASTEXITCODE -ne 0) {
114+
Throw "An error occurred while restoring Cake from NuGet."
115+
}
69116
}
70117

71118
###########################################################################
72119
# RUN BUILD SCRIPT
73120
###########################################################################
74121

75-
& dotnet "$CakePath" $args
76-
exit $LASTEXITCODE
122+
# Build the argument list.
123+
$Arguments = @{
124+
// target=$Target;
125+
configuration=$Configuration;
126+
verbosity=$Verbosity;
127+
dryrun=$WhatIf;
128+
}.GetEnumerator() | %{"--{0}=`"{1}`"" -f $_.key, $_.value };
129+
130+
# Start Cake
131+
Write-Host "Running build script..."
132+
Invoke-Expression "& `"$CakePath`" `"build.cake`" $Arguments $ScriptArgs"
133+
exit $LASTEXITCODE

build.sh

Lines changed: 85 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,96 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
2+
##########################################################################
3+
# This is the Cake bootstrapper script for Linux and OS X.
4+
# This file was downloaded from https://github.com/cake-build/resources
5+
# Feel free to change this file to fit your needs.
6+
##########################################################################
27

3-
SCRIPT_PATH="${BASH_SOURCE[0]}";
4-
if ([ -h "${SCRIPT_PATH}" ]) then
5-
while([ -h "${SCRIPT_PATH}" ]) do SCRIPT_PATH=`readlink "${SCRIPT_PATH}"`; done
8+
# Define directories.
9+
SCRIPT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
10+
TOOLS_DIR=$SCRIPT_DIR/tools
11+
NUGET_EXE=$TOOLS_DIR/nuget.exe
12+
NUGET_URL=https://dist.nuget.org/win-x86-commandline/latest/nuget.exe
13+
CAKE_VERSION=0.26.1
14+
CAKE_EXE=$TOOLS_DIR/Cake.$CAKE_VERSION/Cake.exe
15+
16+
# Temporarily skip verification of addins.
17+
export CAKE_SETTINGS_SKIPVERIFICATION='true'
18+
19+
# Define default arguments.
20+
TARGET="Travis"
21+
CONFIGURATION="Release"
22+
VERBOSITY="verbose"
23+
DRYRUN=
24+
SCRIPT_ARGUMENTS=()
25+
26+
# Parse arguments.
27+
for i in "$@"; do
28+
case $1 in
29+
-t|--target) TARGET="$2"; shift ;;
30+
-c|--configuration) CONFIGURATION="$2"; shift ;;
31+
-v|--verbosity) VERBOSITY="$2"; shift ;;
32+
-d|--dryrun) DRYRUN="-dryrun" ;;
33+
--) shift; SCRIPT_ARGUMENTS+=("$@"); break ;;
34+
*) SCRIPT_ARGUMENTS+=("$1") ;;
35+
esac
36+
shift
37+
done
38+
39+
# Make sure the tools folder exist.
40+
if [ ! -d "$TOOLS_DIR" ]; then
41+
mkdir "$TOOLS_DIR"
642
fi
7-
pushd . > /dev/null
8-
cd `dirname ${SCRIPT_PATH}` > /dev/null
9-
SCRIPT_PATH=`pwd`;
10-
popd > /dev/null
11-
12-
if ! [ -f $SCRIPT_PATH/.nuget/nuget.exe ]
13-
then
14-
wget "https://www.nuget.org/nuget.exe" -P $SCRIPT_PATH/.nuget/
43+
44+
###########################################################################
45+
# INSTALL .NET CORE CLI
46+
###########################################################################
47+
48+
echo "Installing .NET CLI..."
49+
if [ ! -d "$SCRIPT_DIR/.dotnet" ]; then
50+
mkdir "$SCRIPT_DIR/.dotnet"
1551
fi
52+
curl -Lsfo "$SCRIPT_DIR/.dotnet/dotnet-install.sh" https://dot.net/v1/dotnet-install.sh
53+
sudo bash "$SCRIPT_DIR/.dotnet/dotnet-install.sh" --version 1.0.1 --install-dir .dotnet --no-path
54+
export PATH="$SCRIPT_DIR/.dotnet":$PATH
55+
export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1
56+
export DOTNET_CLI_TELEMETRY_OPTOUT=1
57+
"$SCRIPT_DIR/.dotnet/dotnet" --info
1658

17-
mono $SCRIPT_PATH/.nuget/nuget.exe update -self
59+
###########################################################################
60+
# INSTALL NUGET
61+
###########################################################################
1862

19-
mono $SCRIPT_PATH/.nuget/nuget.exe install FAKE -OutputDirectory $SCRIPT_PATH/packages -ExcludeVersion -Version 4.25.4
63+
# Download NuGet if it does not exist.
64+
if [ ! -f "$NUGET_EXE" ]; then
65+
echo "Downloading NuGet..."
66+
curl -Lsfo "$NUGET_EXE" $NUGET_URL
67+
if [ $? -ne 0 ]; then
68+
echo "An error occurred while downloading nuget.exe."
69+
exit 1
70+
fi
71+
fi
2072

21-
mono $SCRIPT_PATH/.nuget/nuget.exe install xunit.runners -OutputDirectory $SCRIPT_PATH/packages/FAKE -ExcludeVersion -Version 2.1.0
22-
mono $SCRIPT_PATH/.nuget/nuget.exe install NBench.Runner -OutputDirectory packages -ExcludeVersion -Version 0.2.2
73+
###########################################################################
74+
# INSTALL CAKE
75+
###########################################################################
2376

24-
if ! [ -e $SCRIPT_PATH/packages/SourceLink.Fake/tools/SourceLink.fsx ] ; then
25-
mono $SCRIPT_PATH/.nuget/nuget.exe install SourceLink.Fake -OutputDirectory $SCRIPT_PATH/packages -ExcludeVersion
77+
if [ ! -f "$CAKE_EXE" ]; then
78+
mono "$NUGET_EXE" install Cake -Version $CAKE_VERSION -OutputDirectory "$TOOLS_DIR"
79+
if [ $? -ne 0 ]; then
80+
echo "An error occured while installing Cake."
81+
exit 1
82+
fi
83+
fi
2684

85+
# Make sure that Cake has been installed.
86+
if [ ! -f "$CAKE_EXE" ]; then
87+
echo "Could not find Cake.exe at '$CAKE_EXE'."
88+
exit 1
2789
fi
2890

29-
export encoding=utf-8
91+
###########################################################################
92+
# RUN BUILD SCRIPT
93+
###########################################################################
3094

31-
mono $SCRIPT_PATH/packages/FAKE/tools/FAKE.exe build.fsx "$@"
95+
# Start Cake
96+
exec mono "$CAKE_EXE" build.cake --verbosity=$VERBOSITY --configuration=$CONFIGURATION --target=$TARGET $DRYRUN "${SCRIPT_ARGUMENTS[@]}"

test/DotNetty.Common.Tests/Internal/Logging/InternalLoggerFactoryTest.cs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,23 @@
44
namespace DotNetty.Common.Tests.Internal.Logging
55
{
66
using System;
7+
using System.Runtime.CompilerServices;
78
using DotNetty.Common.Internal.Logging;
89
using DotNetty.Tests.Common;
910
using Microsoft.Extensions.Logging;
1011
using Moq;
1112
using Xunit;
13+
using Xunit.Abstractions;
1214

1315
[CollectionDefinition(nameof(InternalLoggerFactoryTest), DisableParallelization = true)]
1416
public class InternalLoggerFactoryTest
1517
{
18+
protected readonly ITestOutputHelper Output;
19+
20+
public InternalLoggerFactoryTest(ITestOutputHelper output)
21+
{
22+
this.Output = output;
23+
}
1624
// todo: CodeContracts on CI
1725
//[Fact]
1826
//public void ShouldNotAllowNullDefaultFactory()
@@ -34,6 +42,7 @@ public void ShouldGetInstance()
3442
[Fact]
3543
public void TestMockReturned()
3644
{
45+
Output.WriteLine("TestMockReturned, Pre:" + RuntimeHelpers.GetHashCode(InternalLoggerFactory.DefaultFactory));
3746
Mock<ILogger> mock;
3847
using (SetupMockLogger(out mock))
3948
{
@@ -43,20 +52,28 @@ public void TestMockReturned()
4352

4453
Assert.True(logger.TraceEnabled);
4554
mock.Verify(x => x.IsEnabled(LogLevel.Trace), Times.Once);
55+
Output.WriteLine("TestMockReturned, Finish:" + RuntimeHelpers.GetHashCode(InternalLoggerFactory.DefaultFactory));
4656
}
57+
Output.WriteLine("TestMockReturned, Post:" + RuntimeHelpers.GetHashCode(InternalLoggerFactory.DefaultFactory));
58+
Assert.True(false, "To See The Log");
4759
}
4860

49-
static IDisposable SetupMockLogger(out Mock<ILogger> loggerMock)
61+
IDisposable SetupMockLogger(out Mock<ILogger> loggerMock)
5062
{
5163
ILoggerFactory oldLoggerFactory = InternalLoggerFactory.DefaultFactory;
64+
Output.WriteLine($"SetupMockLogger,oldLoggerFactory={RuntimeHelpers.GetHashCode(oldLoggerFactory)}");
5265
var loggerFactory = new LoggerFactory();
66+
Output.WriteLine($"SetupMockLogger,loggerFactory={RuntimeHelpers.GetHashCode(loggerFactory)}");
5367
var factoryMock = new Mock<ILoggerProvider>(MockBehavior.Strict);
5468
ILoggerProvider mockFactory = factoryMock.Object;
5569
loggerMock = new Mock<ILogger>(MockBehavior.Strict);
5670
loggerFactory.AddProvider(mockFactory);
5771
factoryMock.Setup(x => x.CreateLogger("mock")).Returns(loggerMock.Object);
5872
InternalLoggerFactory.DefaultFactory = loggerFactory;
59-
return new Disposable(() => InternalLoggerFactory.DefaultFactory = oldLoggerFactory);
73+
return new Disposable(() => {
74+
InternalLoggerFactory.DefaultFactory = oldLoggerFactory;
75+
Output.WriteLine($"SetupMockLogger,Dispose to={RuntimeHelpers.GetHashCode(oldLoggerFactory)}");
76+
});
6077
}
6178
}
6279
}

test/DotNetty.Common.Tests/Utilities/HashedWheelTimerTest.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public void TestScheduleTimeoutShouldRunAfterDelay()
5454
[Fact] // (timeout = 3000)
5555
public void TestStopTimer()
5656
{
57+
Output.WriteLine($"{System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(DotNetty.Common.Internal.Logging.InternalLoggerFactory.DefaultFactory)}");
5758
var latch = new CountdownEvent(3);
5859
ITimer timerProcessed = new HashedWheelTimer();
5960
for (int i = 0; i < 3; i++)
@@ -77,6 +78,7 @@ public void TestStopTimer()
7778
}
7879
Thread.Sleep(1000); // sleep for a second
7980
Assert.NotEqual(0, timerUnprocessed.StopAsync().Result.Count); // Number of unprocessed timeouts should be greater than 0
81+
Assert.True(false, "To See The Log");
8082
}
8183

8284
[Fact] // (timeout = 3000)

0 commit comments

Comments
 (0)