Restore "Force conformance tests to run on the CI (#228)" (#229)

This reverts commit 57622cab6b.
This commit is contained in:
Andrew Stanton-Nurse 2018-02-26 11:39:18 -08:00 committed by GitHub
parent 9cefe7c596
commit 4a49d6dd75
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 85 additions and 6 deletions

View File

@ -5,12 +5,17 @@ environment:
global: global:
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
DOTNET_CLI_TELEMETRY_OPTOUT: 1 DOTNET_CLI_TELEMETRY_OPTOUT: 1
ASPNETCORE_WSTEST_PATH: "$(APPVEYOR_BUILD_FOLDER)/vendor/virtualenv/Scripts/wstest.exe"
cache:
- vendor\VCForPython27.msi
branches: branches:
only: only:
- master - master
- /release\/.*/ - /release\/.*/
- dev - dev
- /^(.*\/)?ci-.*$/ - /^(.*\/)?ci-.*$/
install:
- ps: .\build\setup-wstest.ps1
build_script: build_script:
- ps: .\run.ps1 default-build - ps: .\run.ps1 default-build
clone_depth: 1 clone_depth: 1

52
build/setup-wstest.ps1 Normal file
View File

@ -0,0 +1,52 @@
function has($cmd) { !!(Get-Command $cmd -ErrorAction SilentlyContinue) }
# Download VCForPython27 if necessary
$VendorDir = Join-Path (Get-Location) "vendor"
if(!(Test-Path $VendorDir)) {
mkdir $VendorDir
}
$VirtualEnvDir = Join-Path $VendorDir "virtualenv";
$ScriptsDir = Join-Path $VirtualEnvDir "Scripts"
$WsTest = Join-Path $ScriptsDir "wstest.exe"
$VCPythonMsi = Join-Path $VendorDir "VCForPython27.msi"
if(!(Test-Path $VCPythonMsi)) {
Write-Host "Downloading VCForPython27.msi"
Invoke-WebRequest -Uri https://download.microsoft.com/download/7/9/6/796EF2E4-801B-4FC4-AB28-B59FBF6D907B/VCForPython27.msi -OutFile "$VCPythonMsi"
}
else {
Write-Host "Using VCForPython27.msi from Cache"
}
# Install VCForPython27
Write-Host "Installing VCForPython27"
# Launch this way to ensure we wait for msiexec to complete. It's a Windows app so it won't block the console by default.
Start-Process msiexec "/i","$VCPythonMsi","/qn","/quiet","/norestart" -Wait
Write-Host "Installed VCForPython27"
# Install Python
if(!(has python)) {
choco install python2
}
if(!(has python)) {
throw "Failed to install python2"
}
# Install virtualenv
pip install virtualenv
# Make a virtualenv in .virtualenv
virtualenv $VirtualEnvDir
& "$ScriptsDir\python" --version
& "$ScriptsDir\pip" --version
# Install autobahn into the virtualenv
& "$ScriptsDir\pip" install autobahntestsuite
Write-Host "Using wstest from: '$WsTest'"

View File

@ -1,4 +1,4 @@
using System; using System;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;

View File

@ -1,4 +1,5 @@
using System; using System;
using System.IO;
namespace Microsoft.AspNetCore.WebSockets.ConformanceTest.Autobahn namespace Microsoft.AspNetCore.WebSockets.ConformanceTest.Autobahn
{ {
@ -9,18 +10,28 @@ namespace Microsoft.AspNetCore.WebSockets.ConformanceTest.Autobahn
{ {
private static Lazy<Wstest> _instance = new Lazy<Wstest>(Create); private static Lazy<Wstest> _instance = new Lazy<Wstest>(Create);
public static readonly string DefaultLocation = LocateWstest();
public static Wstest Default => _instance.Value; public static Wstest Default => _instance.Value;
public Wstest(string path) : base(path) { } public Wstest(string path) : base(path) { }
private static Wstest Create() private static Wstest Create()
{
var location = LocateWstest();
return (location == null || !File.Exists(location)) ? null : new Wstest(location);
}
private static string LocateWstest()
{ {
var location = Environment.GetEnvironmentVariable("ASPNETCORE_WSTEST_PATH"); var location = Environment.GetEnvironmentVariable("ASPNETCORE_WSTEST_PATH");
if (string.IsNullOrEmpty(location)) if (string.IsNullOrEmpty(location))
{ {
location = Locate("wstest"); location = Locate("wstest");
} }
return location == null ? null : new Wstest(location);
return location;
} }
} }
} }

View File

@ -9,6 +9,7 @@ using Microsoft.AspNetCore.Testing.xunit;
using Microsoft.AspNetCore.WebSockets.ConformanceTest.Autobahn; using Microsoft.AspNetCore.WebSockets.ConformanceTest.Autobahn;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Testing; using Microsoft.Extensions.Logging.Testing;
using Xunit;
using Xunit.Abstractions; using Xunit.Abstractions;
namespace Microsoft.AspNetCore.WebSockets.ConformanceTest namespace Microsoft.AspNetCore.WebSockets.ConformanceTest
@ -27,6 +28,11 @@ namespace Microsoft.AspNetCore.WebSockets.ConformanceTest
[SkipIfWsTestNotPresent] [SkipIfWsTestNotPresent]
public async Task AutobahnTestSuite() public async Task AutobahnTestSuite()
{ {
// If we're on CI, we want to actually fail if WsTest isn't installed, rather than just skipping the test
// The SkipIfWsTestNotPresent attribute ensures that this test isn't skipped on CI, so we just need to check that Wstest is present
// And we use Assert.True to provide an error message
Assert.True(Wstest.Default != null, $"The 'wstest' executable (Autobahn WebSockets Test Suite) could not be found at '{Wstest.DefaultLocation}'. Run the Build Agent setup scripts to install it or see https://github.com/crossbario/autobahn-testsuite for instructions on manual installation.");
using (StartLog(out var loggerFactory)) using (StartLog(out var loggerFactory))
{ {
var logger = loggerFactory.CreateLogger<AutobahnTests>(); var logger = loggerFactory.CreateLogger<AutobahnTests>();

View File

@ -1,4 +1,4 @@
using System; using System;
using Microsoft.AspNetCore.Testing.xunit; using Microsoft.AspNetCore.Testing.xunit;
using Microsoft.AspNetCore.WebSockets.ConformanceTest.Autobahn; using Microsoft.AspNetCore.WebSockets.ConformanceTest.Autobahn;
@ -7,7 +7,12 @@ namespace Microsoft.AspNetCore.WebSockets.ConformanceTest
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
public class SkipIfWsTestNotPresentAttribute : Attribute, ITestCondition public class SkipIfWsTestNotPresentAttribute : Attribute, ITestCondition
{ {
public bool IsMet => Wstest.Default != null; public bool IsMet => IsOnCi || Wstest.Default != null;
public string SkipReason => "Autobahn Test Suite is not installed on the host machine."; public string SkipReason => "Autobahn Test Suite is not installed on the host machine.";
private static bool IsOnCi =>
!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("TEAMCITY_VERSION")) ||
string.Equals(Environment.GetEnvironmentVariable("TRAVIS"), "true", StringComparison.OrdinalIgnoreCase) ||
string.Equals(Environment.GetEnvironmentVariable("APPVEYOR"), "true", StringComparison.OrdinalIgnoreCase);
} }
} }