mirror of https://github.com/grpc/grpc.git
commit
6b4b891eb2
108 changed files with 1456 additions and 479 deletions
@ -0,0 +1,54 @@ |
||||
#region Copyright notice and license |
||||
// Copyright 2015 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 |
||||
|
||||
#if GRPC_SUPPORT_WATCH |
||||
using System.Threading.Channels; |
||||
using System.Threading.Tasks; |
||||
|
||||
using Grpc.Core; |
||||
using Grpc.Health.V1; |
||||
|
||||
namespace Grpc.HealthCheck.Tests |
||||
{ |
||||
internal class TestResponseStreamWriter : IServerStreamWriter<HealthCheckResponse> |
||||
{ |
||||
private Channel<HealthCheckResponse> _channel; |
||||
|
||||
public TestResponseStreamWriter(int maxCapacity = 1) |
||||
{ |
||||
_channel = System.Threading.Channels.Channel.CreateBounded<HealthCheckResponse>(new BoundedChannelOptions(maxCapacity) { |
||||
SingleReader = false, |
||||
SingleWriter = true, |
||||
FullMode = BoundedChannelFullMode.Wait |
||||
}); |
||||
} |
||||
|
||||
public ChannelReader<HealthCheckResponse> WrittenMessagesReader => _channel.Reader; |
||||
|
||||
public WriteOptions WriteOptions { get; set; } |
||||
|
||||
public Task WriteAsync(HealthCheckResponse message) |
||||
{ |
||||
return _channel.Writer.WriteAsync(message).AsTask(); |
||||
} |
||||
|
||||
public void Complete() |
||||
{ |
||||
_channel.Writer.Complete(); |
||||
} |
||||
} |
||||
} |
||||
#endif |
@ -0,0 +1,57 @@ |
||||
#region Copyright notice and license |
||||
// Copyright 2015 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 |
||||
|
||||
#if GRPC_SUPPORT_WATCH |
||||
using System; |
||||
using System.Threading; |
||||
using System.Threading.Tasks; |
||||
|
||||
using Grpc.Core; |
||||
|
||||
namespace Grpc.HealthCheck.Tests |
||||
{ |
||||
internal class TestServerCallContext : ServerCallContext |
||||
{ |
||||
private readonly CancellationToken _cancellationToken; |
||||
|
||||
public TestServerCallContext(CancellationToken cancellationToken) |
||||
{ |
||||
_cancellationToken = cancellationToken; |
||||
} |
||||
|
||||
protected override string MethodCore { get; } |
||||
protected override string HostCore { get; } |
||||
protected override string PeerCore { get; } |
||||
protected override DateTime DeadlineCore { get; } |
||||
protected override Metadata RequestHeadersCore { get; } |
||||
protected override CancellationToken CancellationTokenCore => _cancellationToken; |
||||
protected override Metadata ResponseTrailersCore { get; } |
||||
protected override Status StatusCore { get; set; } |
||||
protected override WriteOptions WriteOptionsCore { get; set; } |
||||
protected override AuthContext AuthContextCore { get; } |
||||
|
||||
protected override ContextPropagationToken CreatePropagationTokenCore(ContextPropagationOptions options) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
protected override Task WriteResponseHeadersAsyncCore(Metadata responseHeaders) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
} |
||||
#endif |
@ -0,0 +1,100 @@ |
||||
#region Copyright notice and license |
||||
|
||||
// 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. |
||||
|
||||
#endregion |
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Threading; |
||||
using System.Threading.Tasks; |
||||
using Grpc.Core; |
||||
using Grpc.Core.Internal; |
||||
using Grpc.Core.Utils; |
||||
using Grpc.Testing; |
||||
using NUnit.Framework; |
||||
|
||||
namespace Grpc.IntegrationTesting |
||||
{ |
||||
/// <summary> |
||||
/// Runs interop tests in-process. |
||||
/// </summary> |
||||
public class UnobservedTaskExceptionTest |
||||
{ |
||||
const string Host = "localhost"; |
||||
Server server; |
||||
Channel channel; |
||||
TestService.TestServiceClient client; |
||||
|
||||
[OneTimeSetUp] |
||||
public void Init() |
||||
{ |
||||
// Disable SO_REUSEPORT to prevent https://github.com/grpc/grpc/issues/10755 |
||||
server = new Server(new[] { new ChannelOption(ChannelOptions.SoReuseport, 0) }) |
||||
{ |
||||
Services = { TestService.BindService(new TestServiceImpl()) }, |
||||
Ports = { { Host, ServerPort.PickUnused, ServerCredentials.Insecure } } |
||||
}; |
||||
server.Start(); |
||||
|
||||
int port = server.Ports.Single().BoundPort; |
||||
channel = new Channel(Host, port, ChannelCredentials.Insecure); |
||||
client = new TestService.TestServiceClient(channel); |
||||
} |
||||
|
||||
[OneTimeTearDown] |
||||
public void Cleanup() |
||||
{ |
||||
channel.ShutdownAsync().Wait(); |
||||
server.ShutdownAsync().Wait(); |
||||
} |
||||
|
||||
[Test] |
||||
public async Task NoUnobservedTaskExceptionForAbandonedStreamingResponse() |
||||
{ |
||||
// Verify that https://github.com/grpc/grpc/issues/17458 has been fixed. |
||||
// Create a streaming response call, then cancel it without reading all the responses |
||||
// and check that no unobserved task exceptions have been thrown. |
||||
|
||||
var unobservedTaskExceptionCounter = new AtomicCounter(); |
||||
|
||||
TaskScheduler.UnobservedTaskException += (sender, e) => { |
||||
unobservedTaskExceptionCounter.Increment(); |
||||
Console.WriteLine("Detected unobserved task exception: " + e.Exception); |
||||
}; |
||||
|
||||
var bodySizes = new List<int> { 10, 10, 10, 10, 10 }; |
||||
var request = new StreamingOutputCallRequest { |
||||
ResponseParameters = { bodySizes.Select((size) => new ResponseParameters { Size = size }) } |
||||
}; |
||||
|
||||
for (int i = 0; i < 50; i++) |
||||
{ |
||||
Console.WriteLine($"Starting iteration {i}"); |
||||
using (var call = client.StreamingOutputCall(request)) |
||||
{ |
||||
// Intentionally only read the first response (we know there's more) |
||||
// The call will be cancelled as soon as we leave the "using" statement. |
||||
var firstResponse = await call.ResponseStream.MoveNext(); |
||||
} |
||||
// Make it more likely to trigger the "Unobserved task exception" warning |
||||
GC.Collect(); |
||||
} |
||||
|
||||
Assert.AreEqual(0, unobservedTaskExceptionCounter.Count); |
||||
} |
||||
} |
||||
} |
@ -1,7 +1,7 @@ |
||||
<!-- This file is generated --> |
||||
<Project> |
||||
<PropertyGroup> |
||||
<GrpcCsharpVersion>2.26.0-dev</GrpcCsharpVersion> |
||||
<GrpcCsharpVersion>2.27.0-dev</GrpcCsharpVersion> |
||||
<GoogleProtobufVersion>3.8.0</GoogleProtobufVersion> |
||||
</PropertyGroup> |
||||
</Project> |
||||
|
@ -0,0 +1,94 @@ |
||||
#!/usr/bin/env powershell |
||||
# Install Python 3.8 for x64 and x86 in order to build wheels on Windows. |
||||
|
||||
Set-StrictMode -Version 2 |
||||
|
||||
# Avoid "Could not create SSL/TLS secure channel" |
||||
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 |
||||
|
||||
function Install-Python { |
||||
Param( |
||||
[string]$PythonVersion, |
||||
[string]$PythonInstaller, |
||||
[string]$PythonInstallPath, |
||||
[string]$PythonInstallerHash |
||||
) |
||||
$PythonInstallerUrl = "https://www.python.org/ftp/python/$PythonVersion/$PythonInstaller.exe" |
||||
$PythonInstallerPath = "C:\tools\$PythonInstaller.exe" |
||||
|
||||
# Downloads installer |
||||
Write-Host "Downloading the Python installer: $PythonInstallerUrl => $PythonInstallerPath" |
||||
Invoke-WebRequest -Uri $PythonInstallerUrl -OutFile $PythonInstallerPath |
||||
|
||||
# Validates checksum |
||||
$HashFromDownload = Get-FileHash -Path $PythonInstallerPath -Algorithm MD5 |
||||
if ($HashFromDownload.Hash -ne $PythonInstallerHash) { |
||||
throw "Invalid Python installer: failed checksum!" |
||||
} |
||||
Write-Host "Python installer $PythonInstallerPath validated." |
||||
|
||||
# Installs Python |
||||
& $PythonInstallerPath /quiet InstallAllUsers=1 PrependPath=1 Include_test=0 TargetDir=$PythonInstallPath |
||||
if (-Not $?) { |
||||
throw "The Python installation exited with error!" |
||||
} |
||||
|
||||
# Validates Python binary |
||||
# NOTE(lidiz) Even if the install command finishes in the script, that |
||||
# doesn't mean the Python installation is finished. If using "ps" to check |
||||
# for running processes, you might see ongoing installers at this point. |
||||
# So, we needs this "hack" to reliably validate that the Python binary is |
||||
# functioning properly. |
||||
$ValidationStartTime = Get-Date |
||||
$EarlyExitDDL = $ValidationStartTime.addminutes(5) |
||||
$PythonBinary = "$PythonInstallPath\python.exe" |
||||
While ($True) { |
||||
$CurrentTime = Get-Date |
||||
if ($CurrentTime -ge $EarlyExitDDL) { |
||||
throw "Invalid Python installation! Timeout!" |
||||
} |
||||
& $PythonBinary -c 'print(42)' |
||||
if ($?) { |
||||
Write-Host "Python binary works properly." |
||||
break |
||||
} |
||||
Start-Sleep -Seconds 1 |
||||
} |
||||
|
||||
# Waits until the installer process is gone |
||||
$ValidationStartTime = Get-Date |
||||
$EarlyExitDDL = $ValidationStartTime.addminutes(5) |
||||
While ($True) { |
||||
$CurrentTime = Get-Date |
||||
if ($CurrentTime -ge $EarlyExitDDL) { |
||||
throw "Python installation process hangs!" |
||||
} |
||||
$InstallProcess = Get-Process -Name $PythonInstaller |
||||
if ($InstallProcess -eq $null) { |
||||
Write-Host "Installation process exits normally." |
||||
break |
||||
} |
||||
Start-Sleep -Seconds 1 |
||||
} |
||||
|
||||
# Installs pip |
||||
& $PythonBinary -m ensurepip --user |
||||
|
||||
Write-Host "Python $PythonVersion installed by $PythonInstaller at $PythonInstallPath." |
||||
} |
||||
|
||||
$Python38x86Config = @{ |
||||
PythonVersion = "3.8.0" |
||||
PythonInstaller = "python-3.8.0" |
||||
PythonInstallPath = "C:\Python38_32bit" |
||||
PythonInstallerHash = "412a649d36626d33b8ca5593cf18318c" |
||||
} |
||||
Install-Python @Python38x86Config |
||||
|
||||
$Python38x64Config = @{ |
||||
PythonVersion = "3.8.0" |
||||
PythonInstaller = "python-3.8.0-amd64" |
||||
PythonInstallPath = "C:\Python38" |
||||
PythonInstallerHash = "29ea87f24c32f5e924b7d63f8a08ee8d" |
||||
} |
||||
Install-Python @Python38x64Config |
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue