Skip to content
代码片段 群组 项目
未验证 提交 6912dda5 编辑于 作者: John Luo's avatar John Luo 提交者: GitHub
浏览文件

Add gRPC interop tests (again) (#20069)

* Revert "Revert "Add gRPC interop tests (#17040)" (#20047)"

This reverts commit 236dcd9f.

* Fix daily and quarantine Helix runs

* Cleanup
上级 0d80ffa6
No related branches found
No related tags found
无相关合并请求
显示
579 个添加9 个删除
...@@ -674,9 +674,9 @@ stages: ...@@ -674,9 +674,9 @@ stages:
# Build the shared framework # Build the shared framework
- script: ./build.cmd -ci -all -pack -arch x64 -buildNative /p:ASPNETCORE_TEST_LOG_DIR=artifacts/log /bl:artifacts/log/helix.build.x64.binlog - script: ./build.cmd -ci -all -pack -arch x64 -buildNative /p:ASPNETCORE_TEST_LOG_DIR=artifacts/log /bl:artifacts/log/helix.build.x64.binlog
displayName: Build shared fx displayName: Build shared fx
- script: .\restore.cmd -ci - script: .\restore.cmd -ci /p:BuildInteropProjects=true
displayName: Restore displayName: Restore
- script: .\build.cmd -ci -NoRestore -test -projects eng\helix\helix.proj /p:IsRequiredCheck=true /p:IsHelixJob=true /p:BuildAllProjects=true /p:BuildNative=true /p:RunTemplateTests=true /p:ASPNETCORE_TEST_LOG_DIR=artifacts/log -bl - script: .\build.cmd -ci -NoRestore -test -projects eng\helix\helix.proj /p:IsRequiredCheck=true /p:IsHelixJob=true /p:BuildAllProjects=true /p:BuildInteropProjects=true /p:BuildNative=true /p:RunTemplateTests=true /p:ASPNETCORE_TEST_LOG_DIR=artifacts/log -bl
displayName: Run build.cmd helix target displayName: Run build.cmd helix target
env: env:
HelixApiAccessToken: $(HelixApiAccessToken) # Needed for internal queues HelixApiAccessToken: $(HelixApiAccessToken) # Needed for internal queues
...@@ -699,9 +699,9 @@ stages: ...@@ -699,9 +699,9 @@ stages:
- script: ./build.cmd -ci -all -pack -arch x64 -buildNative /p:ASPNETCORE_TEST_LOG_DIR=artifacts/log /bl:artifacts/log/helix.daily.build.x64.binlog - script: ./build.cmd -ci -all -pack -arch x64 -buildNative /p:ASPNETCORE_TEST_LOG_DIR=artifacts/log /bl:artifacts/log/helix.daily.build.x64.binlog
displayName: Build shared fx displayName: Build shared fx
# Build the x86 shared framework # Build the x86 shared framework
- script: .\restore.cmd -ci - script: .\restore.cmd -ci /p:BuildInteropProjects=true
displayName: Restore displayName: Restore
- script: .\build.cmd -ci -NoRestore -test -projects eng\helix\helix.proj /p:IsHelixJob=true /p:IsHelixDaily=true /p:BuildAllProjects=true /p:BuildNative=true /p:RunTemplateTests=true /p:ASPNETCORE_TEST_LOG_DIR=artifacts/log -bl - script: .\build.cmd -ci -NoRestore -test -projects eng\helix\helix.proj /p:IsHelixJob=true /p:IsHelixDaily=true /p:BuildAllProjects=true /p:BuildInteropProjects=true /p:BuildNative=true /p:RunTemplateTests=true /p:ASPNETCORE_TEST_LOG_DIR=artifacts/log -bl
displayName: Run build.cmd helix target displayName: Run build.cmd helix target
env: env:
HelixApiAccessToken: $(HelixApiAccessToken) # Needed for internal queues HelixApiAccessToken: $(HelixApiAccessToken) # Needed for internal queues
......
...@@ -33,9 +33,9 @@ jobs: ...@@ -33,9 +33,9 @@ jobs:
# Build the shared framework # Build the shared framework
- script: ./build.cmd -ci -all -pack -arch x64 -buildNative /p:ASPNETCORE_TEST_LOG_DIR=artifacts/log /bl:artifacts/log/helix.build.x64.binlog - script: ./build.cmd -ci -all -pack -arch x64 -buildNative /p:ASPNETCORE_TEST_LOG_DIR=artifacts/log /bl:artifacts/log/helix.build.x64.binlog
displayName: Build shared fx displayName: Build shared fx
- script: .\restore.cmd -ci - script: .\restore.cmd -ci /p:BuildInteropProjects=true
displayName: Restore displayName: Restore
- script: .\build.cmd -ci -NoRestore -test -noBuildJava -projects eng\helix\helix.proj /p:RunQuarantinedTests=true /p:IsRequiredCheck=true /p:IsHelixJob=true /p:BuildAllProjects=true /p:BuildNative=true /p:RunTemplateTests=true /p:ASPNETCORE_TEST_LOG_DIR=artifacts/log -bl - script: .\build.cmd -ci -NoRestore -test -noBuildJava -projects eng\helix\helix.proj /p:RunQuarantinedTests=true /p:IsRequiredCheck=true /p:IsHelixJob=true /p:BuildAllProjects=true /p:BuildInteropProjects=true /p:BuildNative=true /p:RunTemplateTests=true /p:ASPNETCORE_TEST_LOG_DIR=artifacts/log -bl
displayName: Run build.cmd helix target displayName: Run build.cmd helix target
env: env:
HelixApiAccessToken: $(HelixApiAccessToken) # Needed for internal queues HelixApiAccessToken: $(HelixApiAccessToken) # Needed for internal queues
......
...@@ -167,5 +167,7 @@ ...@@ -167,5 +167,7 @@
<Import Project="eng\targets\Npm.Common.targets" Condition="'$(MSBuildProjectExtension)' == '.npmproj'" /> <Import Project="eng\targets\Npm.Common.targets" Condition="'$(MSBuildProjectExtension)' == '.npmproj'" />
<Import Project="eng\targets\ReferenceAssembly.targets" Condition=" $(HasReferenceAssembly) " /> <Import Project="eng\targets\ReferenceAssembly.targets" Condition=" $(HasReferenceAssembly) " />
<Import Project="eng\targets\Helix.targets" Condition="'$(IsTestProject)' == 'true'" /> <Import Project="eng\targets\Helix.targets" Condition="'$(IsTestProject)' == 'true'" />
<Import Project="eng\targets\FunctionalTestAsset.targets" Condition="'$(IsTestAssetProject)' == 'true'" />
<Import Project="eng\targets\FunctionalTestWithAssets.targets" Condition="'$(ContainsFunctionalTestAssets)' == 'true'" />
</Project> </Project>
...@@ -123,6 +123,13 @@ ...@@ -123,6 +123,13 @@
<ProjectToBuild Condition=" '$(BuildJava)' == 'true'" Include="@(JavaProjects)" Exclude="@(ProjectToExclude)" /> <ProjectToBuild Condition=" '$(BuildJava)' == 'true'" Include="@(JavaProjects)" Exclude="@(ProjectToExclude)" />
<ProjectToExclude Condition=" '$(BuildJava)' != 'true'" Include="@(JavaProjects)" /> <ProjectToExclude Condition=" '$(BuildJava)' != 'true'" Include="@(JavaProjects)" />
<!-- These interop test projects can only be restored and built after the shared framework is built -->
<InteropProjects Include="$(RepoRoot)src\Grpc\**\*.csproj"
Exclude="@(ProjectToExclude)" />
<ProjectToBuild Condition=" '$(BuildInteropProjects)' == 'true'" Include="@(InteropProjects)" Exclude="@(ProjectToExclude)" />
<ProjectToExclude Condition=" '$(BuildInteropProjects)' != 'true'" Include="@(InteropProjects)" />
<!-- <!--
Use caution to avoid deep recursion. If the globbing pattern picks up something which exceeds MAX_PATH, Use caution to avoid deep recursion. If the globbing pattern picks up something which exceeds MAX_PATH,
the entire pattern will silently fail to evaluate correctly. the entire pattern will silently fail to evaluate correctly.
......
...@@ -154,8 +154,13 @@ and are generated based on the last package release. ...@@ -154,8 +154,13 @@ and are generated based on the last package release.
<ItemGroup Label="External dependencies" Condition="'$(DotNetBuildFromSource)' != 'true'"> <ItemGroup Label="External dependencies" Condition="'$(DotNetBuildFromSource)' != 'true'">
<LatestPackageReference Include="AngleSharp" Version="$(AngleSharpPackageVersion)" /> <LatestPackageReference Include="AngleSharp" Version="$(AngleSharpPackageVersion)" />
<LatestPackageReference Include="BenchmarkDotNet" Version="$(BenchmarkDotNetPackageVersion)" /> <LatestPackageReference Include="BenchmarkDotNet" Version="$(BenchmarkDotNetPackageVersion)" />
<LatestPackageReference Include="CommandLineParser" Version="$(CommandLineParserPackageVersion)" />
<LatestPackageReference Include="FSharp.Core" Version="$(FSharpCorePackageVersion)" /> <LatestPackageReference Include="FSharp.Core" Version="$(FSharpCorePackageVersion)" />
<LatestPackageReference Include="Google.ProtoBuf" Version="$(GoogleProtoBufPackageVersion)" /> <LatestPackageReference Include="Google.Protobuf" Version="$(GoogleProtobufPackageVersion)" />
<LatestPackageReference Include="Grpc.AspNetCore" Version="$(GrpcAspNetCorePackageVersion)" />
<LatestPackageReference Include="Grpc.Auth" Version="$(GrpcAuthPackageVersion)" />
<LatestPackageReference Include="Grpc.Net.Client" Version="$(GrpcNetClientPackageVersion)" />
<LatestPackageReference Include="Grpc.Tools" Version="$(GrpcToolsPackageVersion)" />
<LatestPackageReference Include="IdentityServer4" Version="$(IdentityServer4PackageVersion)" /> <LatestPackageReference Include="IdentityServer4" Version="$(IdentityServer4PackageVersion)" />
<LatestPackageReference Include="IdentityServer4.AspNetIdentity" Version="$(IdentityServer4AspNetIdentityPackageVersion)" /> <LatestPackageReference Include="IdentityServer4.AspNetIdentity" Version="$(IdentityServer4AspNetIdentityPackageVersion)" />
<LatestPackageReference Include="IdentityServer4.EntityFramework" Version="$(IdentityServer4EntityFrameworkPackageVersion)" /> <LatestPackageReference Include="IdentityServer4.EntityFramework" Version="$(IdentityServer4EntityFrameworkPackageVersion)" />
......
...@@ -217,9 +217,13 @@ ...@@ -217,9 +217,13 @@
<AngleSharpPackageVersion>0.9.9</AngleSharpPackageVersion> <AngleSharpPackageVersion>0.9.9</AngleSharpPackageVersion>
<BenchmarkDotNetPackageVersion>0.12.0</BenchmarkDotNetPackageVersion> <BenchmarkDotNetPackageVersion>0.12.0</BenchmarkDotNetPackageVersion>
<CastleCorePackageVersion>4.2.1</CastleCorePackageVersion> <CastleCorePackageVersion>4.2.1</CastleCorePackageVersion>
<CommandLineParserPackageVersion>2.3.0</CommandLineParserPackageVersion>
<FSharpCorePackageVersion>4.2.1</FSharpCorePackageVersion> <FSharpCorePackageVersion>4.2.1</FSharpCorePackageVersion>
<GoogleProtobufPackageVersion>3.8.0</GoogleProtobufPackageVersion> <GoogleProtobufPackageVersion>3.10.0</GoogleProtobufPackageVersion>
<GrpcAspNetCorePackageVersion>2.27.0</GrpcAspNetCorePackageVersion> <GrpcAspNetCorePackageVersion>2.27.0</GrpcAspNetCorePackageVersion>
<GrpcAuthPackageVersion>2.27.0</GrpcAuthPackageVersion>
<GrpcNetClientPackageVersion>2.27.0</GrpcNetClientPackageVersion>
<GrpcToolsPackageVersion>2.27.0</GrpcToolsPackageVersion>
<IdentityServer4AspNetIdentityPackageVersion>3.0.0</IdentityServer4AspNetIdentityPackageVersion> <IdentityServer4AspNetIdentityPackageVersion>3.0.0</IdentityServer4AspNetIdentityPackageVersion>
<IdentityServer4EntityFrameworkPackageVersion>3.0.0</IdentityServer4EntityFrameworkPackageVersion> <IdentityServer4EntityFrameworkPackageVersion>3.0.0</IdentityServer4EntityFrameworkPackageVersion>
<IdentityServer4PackageVersion>3.0.0</IdentityServer4PackageVersion> <IdentityServer4PackageVersion>3.0.0</IdentityServer4PackageVersion>
......
...@@ -41,7 +41,7 @@ echo "Creating nugetRestore directory: $NUGET_RESTORE" ...@@ -41,7 +41,7 @@ echo "Creating nugetRestore directory: $NUGET_RESTORE"
mkdir $NUGET_RESTORE mkdir $NUGET_RESTORE
mkdir logs mkdir logs
ls -la ls -laR
RESET="\033[0m" RESET="\033[0m"
RED="\033[0;31m" RED="\033[0;31m"
......
<Project>
<Target Name="CollectFunctionalTestPayload" DependsOnTargets="Publish" Returns="@(DependencyPayload)" >
<ItemGroup>
<DependencyPayload Include="@(ResolvedFileToPublish)">
<RelativePath>$(MSBuildProjectName)\%(ResolvedFileToPublish.RelativePath)</RelativePath>
</DependencyPayload>
</ItemGroup>
</Target>
</Project>
\ No newline at end of file
<Project>
<ItemGroup>
<ProjectReference Include="@(FunctionalTestAssetProjectReference)" ReferenceOutputAssembly="false" />
</ItemGroup>
<Target Name="CollectTestAssetPayload" BeforeTargets="GetCopyToOutputDirectoryItems" >
<MSBuild Targets="CollectFunctionalTestPayload"
BuildInParallel="true"
SkipNonexistentTargets="true"
Projects="%(FunctionalTestAssetProjectReference.Identity)"
RebaseOutputs="True">
<Output TaskParameter="TargetOutputs" ItemName="DependencyPayload" />
</MSBuild>
<ItemGroup>
<ContentWithTargetPath
Include="@(DependencyPayload)"
Condition="'@(DependencyPayload->Count())' != '0'">
<TargetPath>%(DependencyPayload.RelativePath)</TargetPath>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</ContentWithTargetPath>
</ItemGroup>
</Target>
</Project>
\ No newline at end of file

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29505.145
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{0FFB3605-0203-450F-80C8-F82CA2E8269F}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "testassets", "testassets", "{F5841B0A-901A-448F-9CC5-4CB393CE86AF}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "InteropTests", "test\InteropTests\InteropTests.csproj", "{90BF37E6-B3F1-4EFC-A233-8288D8B32DD2}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "InteropWebsite", "test\testassets\InteropWebsite\InteropWebsite.csproj", "{3AB7E8E4-BA36-44CE-844E-39DB66E46D45}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "InteropClient", "test\testassets\InteropClient\InteropClient.csproj", "{66E6C55E-E4E3-4F4B-834A-BB34BFE00D2F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{90BF37E6-B3F1-4EFC-A233-8288D8B32DD2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{90BF37E6-B3F1-4EFC-A233-8288D8B32DD2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{90BF37E6-B3F1-4EFC-A233-8288D8B32DD2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{90BF37E6-B3F1-4EFC-A233-8288D8B32DD2}.Release|Any CPU.Build.0 = Release|Any CPU
{3AB7E8E4-BA36-44CE-844E-39DB66E46D45}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3AB7E8E4-BA36-44CE-844E-39DB66E46D45}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3AB7E8E4-BA36-44CE-844E-39DB66E46D45}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3AB7E8E4-BA36-44CE-844E-39DB66E46D45}.Release|Any CPU.Build.0 = Release|Any CPU
{66E6C55E-E4E3-4F4B-834A-BB34BFE00D2F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{66E6C55E-E4E3-4F4B-834A-BB34BFE00D2F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{66E6C55E-E4E3-4F4B-834A-BB34BFE00D2F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{66E6C55E-E4E3-4F4B-834A-BB34BFE00D2F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{90BF37E6-B3F1-4EFC-A233-8288D8B32DD2} = {0FFB3605-0203-450F-80C8-F82CA2E8269F}
{3AB7E8E4-BA36-44CE-844E-39DB66E46D45} = {F5841B0A-901A-448F-9CC5-4CB393CE86AF}
{66E6C55E-E4E3-4F4B-834A-BB34BFE00D2F} = {F5841B0A-901A-448F-9CC5-4CB393CE86AF}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {3CAE66FD-9A59-49C2-B133-1D599225259A}
EndGlobalSection
EndGlobal
.NET Core uses third-party libraries or other resources that may be
distributed under licenses different than the .NET Core software.
In the event that we accidentally failed to list a required notice, please
bring it to our attention. Post an issue or email us:
dotnet@microsoft.com
The attached notices are provided for information only.
License notice for gRPC interop tests
-------------------------------------
Copyright 2019 The gRPC Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
@ECHO OFF
SET RepoRoot=%~dp0..\..
%RepoRoot%\build.cmd -projects %~dp0**\*.*proj %*
#!/usr/bin/env bash
set -euo pipefail
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
repo_root="$DIR/../.."
"$repo_root/build.sh" --projects "$DIR/**/*.*proj" "$@"
@ECHO OFF
%~dp0..\..\startvs.cmd %~dp0Grpc.sln
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Diagnostics;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Internal;
using Xunit.Abstractions;
namespace InteropTests.Helpers
{
public class ClientProcess : IDisposable
{
private readonly Process _process;
private readonly ProcessEx _processEx;
private readonly TaskCompletionSource<object> _startTcs;
public ClientProcess(ITestOutputHelper output, string path, string serverPort, string testCase)
{
_process = new Process();
_process.StartInfo = new ProcessStartInfo
{
RedirectStandardOutput = true,
RedirectStandardError = true,
FileName = "dotnet",
Arguments = @$"{path} --use_tls false --server_port {serverPort} --client_type httpclient --test_case {testCase}"
};
_process.EnableRaisingEvents = true;
_process.OutputDataReceived += Process_OutputDataReceived;
_process.Start();
_processEx = new ProcessEx(output, _process);
_startTcs = new TaskCompletionSource<object>(TaskCreationOptions.RunContinuationsAsynchronously);
}
public Task WaitForReady()
{
return _startTcs.Task;
}
public int ExitCode => _process.ExitCode;
public Task Exited => _processEx.Exited;
private void Process_OutputDataReceived(object sender, DataReceivedEventArgs e)
{
var data = e.Data;
if (data != null)
{
if (data.Contains("Application started."))
{
_startTcs.TrySetResult(null);
}
}
}
public void Dispose()
{
_processEx.Dispose();
}
}
}
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Threading.Tasks;
using Xunit.Abstractions;
namespace InteropTests.Helpers
{
public class InteropTestsFixture : IDisposable
{
private WebsiteProcess _process;
public string Path { get; set; }
public string ServerPort { get; private set; }
public async Task EnsureStarted(ITestOutputHelper output)
{
if (_process != null)
{
return;
}
if (string.IsNullOrEmpty(Path))
{
throw new InvalidOperationException("Path has not been set.");
}
_process = new WebsiteProcess(Path, output);
await _process.WaitForReady();
ServerPort = _process.ServerPort;
}
public void Dispose()
{
_process.Dispose();
}
}
}
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Internal;
using Xunit.Abstractions;
namespace InteropTests.Helpers
{
public class WebsiteProcess : IDisposable
{
private readonly Process _process;
private readonly ProcessEx _processEx;
private readonly TaskCompletionSource<object> _startTcs;
private readonly StringBuilder _consoleOut = new StringBuilder();
private static readonly Regex NowListeningRegex = new Regex(@"^\s*Now listening on: .*:(?<port>\d*)$");
public string ServerPort { get; private set; }
public WebsiteProcess(string path, ITestOutputHelper output)
{
_process = new Process();
_process.StartInfo = new ProcessStartInfo
{
RedirectStandardOutput = true,
RedirectStandardError = true,
FileName = "dotnet",
Arguments = path
};
_process.EnableRaisingEvents = true;
_process.OutputDataReceived += Process_OutputDataReceived;
_process.Start();
_processEx = new ProcessEx(output, _process);
_startTcs = new TaskCompletionSource<object>(TaskCreationOptions.RunContinuationsAsynchronously);
}
public Task WaitForReady()
{
if (_processEx.HasExited)
{
return Task.FromException(new InvalidOperationException("Server is not running."));
}
return _startTcs.Task;
}
private void Process_OutputDataReceived(object sender, DataReceivedEventArgs e)
{
var data = e.Data;
if (data != null)
{
_consoleOut.AppendLine(data);
var m = NowListeningRegex.Match(data);
if (m.Success)
{
ServerPort = m.Groups["port"].Value;
}
if (data.Contains("Application started. Press Ctrl+C to shut down."))
{
_startTcs.TrySetResult(null);
}
}
}
public void Dispose()
{
var attributes = Assembly.GetExecutingAssembly()
.GetCustomAttributes<AssemblyMetadataAttribute>();
var serverLogPath = attributes.SingleOrDefault(a => a.Key == "ServerLogPath")?.Value;
if (!string.IsNullOrEmpty(serverLogPath))
{
File.WriteAllText(serverLogPath, _consoleOut.ToString());
}
else
{
var logDir = Path.Combine(Directory.GetCurrentDirectory(), "artifacts", "logs");
Directory.CreateDirectory(logDir);
File.WriteAllText(Path.Combine(logDir, "InteropServer.log"), _consoleOut.ToString());
}
_processEx.Dispose();
}
}
}
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using InteropTests.Helpers;
using Microsoft.AspNetCore.Testing;
using Xunit;
using Xunit.Abstractions;
namespace InteropTests
{
public class InteropTests : IClassFixture<InteropTestsFixture>
{
private static readonly TimeSpan DefaultTimeout = TimeSpan.FromSeconds(30);
private readonly string _clientPath = Path.Combine(Directory.GetCurrentDirectory(), "InteropClient", "InteropClient.dll");
private readonly InteropTestsFixture _fixture;
private readonly ITestOutputHelper _output;
public InteropTests(InteropTestsFixture fixture, ITestOutputHelper output)
{
var attributes = Assembly.GetExecutingAssembly()
.GetCustomAttributes<AssemblyMetadataAttribute>();
fixture.Path = Path.Combine(Directory.GetCurrentDirectory(), "InteropWebsite", "InteropWebsite.dll");
_fixture = fixture;
_output = output;
}
[Theory]
[MemberData(nameof(TestCaseData))]
public async Task InteropTestCase(string name)
{
await _fixture.EnsureStarted(_output).TimeoutAfter(DefaultTimeout);
using (var clientProcess = new ClientProcess(_output, _clientPath, _fixture.ServerPort, name))
{
await clientProcess.WaitForReady().TimeoutAfter(DefaultTimeout);
await clientProcess.Exited.TimeoutAfter(DefaultTimeout);
Assert.Equal(0, clientProcess.ExitCode);
}
}
#region TestData
// All interop test cases, minus GCE authentication specific tests
private static string[] AllTests = new string[]
{
"empty_unary",
"large_unary",
"client_streaming",
"server_streaming",
"ping_pong",
"empty_stream",
"cancel_after_begin",
"cancel_after_first_response",
"timeout_on_sleeping_server",
"custom_metadata",
"status_code_and_message",
"special_status_message",
"unimplemented_service",
"unimplemented_method",
"client_compressed_unary",
"client_compressed_streaming",
"server_compressed_unary",
"server_compressed_streaming"
};
public static IEnumerable<object[]> TestCaseData => AllTests.Select(t => new object[] { t });
#endregion
}
}
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<ContainsFunctionalTestAssets>true</ContainsFunctionalTestAssets>
<TargetFramework>$(DefaultNetCoreTargetFramework)</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\..\..\Shared\Process\ProcessEx.cs" Link="Helpers\ProcessEx.cs" />
<Compile Include="..\..\..\Shared\Process\ProcessExtensions.cs" Link="Helpers\ProcessExtensions.cs" />
<AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute" Condition="'$(IsHelixJob)' != 'true'">
<_Parameter1>ServerLogPath</_Parameter1>
<_Parameter2>$(ArtifactsLogDir)InteropServer.log</_Parameter2>
</AssemblyAttribute>
<FunctionalTestAssetProjectReference Include="..\testassets\InteropClient\InteropClient.csproj" />
<FunctionalTestAssetProjectReference Include="..\testassets\InteropWebsite\InteropWebsite.csproj" />
</ItemGroup>
</Project>
#region Copyright notice and license
// Copyright 2015-2016 gRPC authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#endregion
using System;
using System.Collections;
using System.Threading.Tasks;
namespace InteropTestsClient
{
internal static class Assert
{
public static void IsTrue(bool condition)
{
if (!condition)
{
throw new InvalidOperationException("Expected true but got false.");
}
}
public static void IsFalse(bool condition)
{
if (condition)
{
throw new InvalidOperationException("Expected false but got true.");
}
}
public static void AreEqual(object expected, object actual)
{
if (!Equals(expected, actual))
{
throw new InvalidOperationException($"Expected {expected} but got {actual}.");
}
}
public static void IsNotNull(object value)
{
if (value == null)
{
throw new InvalidOperationException("Expected not null but got null.");
}
}
public static void Fail()
{
throw new InvalidOperationException("Failure assert.");
}
public static async Task<TException> ThrowsAsync<TException>(Func<Task> action) where TException : Exception
{
try
{
await action();
}
catch (Exception ex)
{
if (ex.GetType() == typeof(TException))
{
return (TException)ex;
}
throw new InvalidOperationException($"Expected ${typeof(TException)} but got ${ex.GetType()}.");
}
throw new InvalidOperationException("No exception thrown.");
}
public static TException Throws<TException>(Action action) where TException : Exception
{
try
{
action();
}
catch (Exception ex)
{
if (ex.GetType() == typeof(TException))
{
return (TException)ex;
}
throw new InvalidOperationException($"Expected ${typeof(TException)} but got ${ex.GetType()}.");
}
throw new InvalidOperationException("No exception thrown.");
}
public static void Contains(object expected, ICollection actual)
{
foreach (var item in actual)
{
if (Equals(item, expected))
{
return;
}
}
throw new InvalidOperationException($"Could not find {expected} in the collection.");
}
}
internal static class CollectionAssert
{
public static void AreEqual(IList expected, IList actual)
{
if (expected.Count != actual.Count)
{
throw new InvalidOperationException($"Collection lengths differ. {expected.Count} but got {actual.Count}.");
}
for (var i = 0; i < expected.Count; i++)
{
Assert.AreEqual(expected[i]!, actual[i]!);
}
}
}
}
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册