mirror of https://github.com/grpc/grpc.git
Merge pull request #8825 from jtattermusch/manual_upmerge_101
Manual upmerge from v1.0.xpull/8846/head^2
commit
6ff81e91c9
49 changed files with 1007 additions and 194 deletions
@ -0,0 +1,79 @@ |
||||
@rem Copyright 2016, Google Inc. |
||||
@rem All rights reserved. |
||||
@rem |
||||
@rem Redistribution and use in source and binary forms, with or without |
||||
@rem modification, are permitted provided that the following conditions are |
||||
@rem met: |
||||
@rem |
||||
@rem * Redistributions of source code must retain the above copyright |
||||
@rem notice, this list of conditions and the following disclaimer. |
||||
@rem * Redistributions in binary form must reproduce the above |
||||
@rem copyright notice, this list of conditions and the following disclaimer |
||||
@rem in the documentation and/or other materials provided with the |
||||
@rem distribution. |
||||
@rem * Neither the name of Google Inc. nor the names of its |
||||
@rem contributors may be used to endorse or promote products derived from |
||||
@rem this software without specific prior written permission. |
||||
@rem |
||||
@rem THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
@rem "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
@rem LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
@rem A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
@rem OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
@rem SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
@rem LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
@rem DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
@rem THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
@rem (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
@rem OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
|
||||
@rem Current package versions |
||||
set VERSION=1.0.1 |
||||
set PROTOBUF_VERSION=3.0.0 |
||||
|
||||
@rem Adjust the location of nuget.exe |
||||
set NUGET=C:\nuget\nuget.exe |
||||
set DOTNET=C:\dotnet\dotnet.exe |
||||
|
||||
set -ex |
||||
|
||||
mkdir -p ..\..\artifacts\ |
||||
|
||||
@rem Collect the artifacts built by the previous build step if running on Jenkins |
||||
@rem TODO(jtattermusch): is there a better way to do this? |
||||
xcopy /Y /I ..\..\architecture=x86,language=csharp,platform=windows\artifacts\* nativelibs\windows_x86\ |
||||
xcopy /Y /I ..\..\architecture=x64,language=csharp,platform=windows\artifacts\* nativelibs\windows_x64\ |
||||
xcopy /Y /I ..\..\architecture=x86,language=csharp,platform=linux\artifacts\* nativelibs\linux_x86\ |
||||
xcopy /Y /I ..\..\architecture=x64,language=csharp,platform=linux\artifacts\* nativelibs\linux_x64\ |
||||
xcopy /Y /I ..\..\architecture=x86,language=csharp,platform=macos\artifacts\* nativelibs\macosx_x86\ |
||||
xcopy /Y /I ..\..\architecture=x64,language=csharp,platform=macos\artifacts\* nativelibs\macosx_x64\ |
||||
|
||||
@rem Collect protoc artifacts built by the previous build step |
||||
xcopy /Y /I ..\..\architecture=x86,language=protoc,platform=windows\artifacts\* protoc_plugins\windows_x86\ |
||||
xcopy /Y /I ..\..\architecture=x64,language=protoc,platform=windows\artifacts\* protoc_plugins\windows_x64\ |
||||
xcopy /Y /I ..\..\architecture=x86,language=protoc,platform=linux\artifacts\* protoc_plugins\linux_x86\ |
||||
xcopy /Y /I ..\..\architecture=x64,language=protoc,platform=linux\artifacts\* protoc_plugins\linux_x64\ |
||||
xcopy /Y /I ..\..\architecture=x86,language=protoc,platform=macos\artifacts\* protoc_plugins\macosx_x86\ |
||||
xcopy /Y /I ..\..\architecture=x64,language=protoc,platform=macos\artifacts\* protoc_plugins\macosx_x64\ |
||||
|
||||
%DOTNET% restore . || goto :error |
||||
|
||||
%DOTNET% pack --configuration Release Grpc.Core\project.json --output ..\..\artifacts || goto :error |
||||
%DOTNET% pack --configuration Release Grpc.Auth\project.json --output ..\..\artifacts || goto :error |
||||
%DOTNET% pack --configuration Release Grpc.HealthCheck\project.json --output ..\..\artifacts || goto :error |
||||
|
||||
%NUGET% pack Grpc.nuspec -Version "1.0.1" -OutputDirectory ..\..\artifacts || goto :error |
||||
%NUGET% pack Grpc.Tools.nuspec -Version "1.0.1" -OutputDirectory ..\..\artifacts |
||||
|
||||
@rem copy resulting nuget packages to artifacts directory |
||||
xcopy /Y /I *.nupkg ..\..\artifacts\ || goto :error |
||||
|
||||
@rem create a zipfile with the artifacts as well |
||||
powershell -Command "Add-Type -Assembly 'System.IO.Compression.FileSystem'; [System.IO.Compression.ZipFile]::CreateFromDirectory('..\..\artifacts', 'csharp_nugets_windows_dotnetcli.zip');" |
||||
xcopy /Y /I csharp_nugets_windows_dotnetcli.zip ..\..\artifacts\ || goto :error |
||||
|
||||
goto :EOF |
||||
|
||||
:error |
||||
echo Failed! |
||||
exit /b %errorlevel% |
@ -0,0 +1,144 @@ |
||||
# Copyright 2015, Google Inc. |
||||
# All rights reserved. |
||||
# |
||||
# Redistribution and use in source and binary forms, with or without |
||||
# modification, are permitted provided that the following conditions are |
||||
# met: |
||||
# |
||||
# * Redistributions of source code must retain the above copyright |
||||
# notice, this list of conditions and the following disclaimer. |
||||
# * Redistributions in binary form must reproduce the above |
||||
# copyright notice, this list of conditions and the following disclaimer |
||||
# in the documentation and/or other materials provided with the |
||||
# distribution. |
||||
# * Neither the name of Google Inc. nor the names of its |
||||
# contributors may be used to endorse or promote products derived from |
||||
# this software without specific prior written permission. |
||||
# |
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
|
||||
require 'grpc' |
||||
|
||||
Thread.abort_on_exception = true |
||||
|
||||
describe GRPC::Pool do |
||||
Pool = GRPC::Pool |
||||
|
||||
describe '#new' do |
||||
it 'raises if a non-positive size is used' do |
||||
expect { Pool.new(0) }.to raise_error |
||||
expect { Pool.new(-1) }.to raise_error |
||||
expect { Pool.new(Object.new) }.to raise_error |
||||
end |
||||
|
||||
it 'is constructed OK with a positive size' do |
||||
expect { Pool.new(1) }.not_to raise_error |
||||
end |
||||
end |
||||
|
||||
describe '#ready_for_work?' do |
||||
it 'before start it is not ready' do |
||||
p = Pool.new(1) |
||||
expect(p.ready_for_work?).to be(false) |
||||
end |
||||
|
||||
it 'it stops being ready after all workers jobs waiting or running' do |
||||
p = Pool.new(5) |
||||
p.start |
||||
job = proc { sleep(3) } # sleep so workers busy when done scheduling |
||||
5.times do |
||||
expect(p.ready_for_work?).to be(true) |
||||
p.schedule(&job) |
||||
end |
||||
expect(p.ready_for_work?).to be(false) |
||||
end |
||||
|
||||
it 'it becomes ready again after jobs complete' do |
||||
p = Pool.new(5) |
||||
p.start |
||||
job = proc {} |
||||
5.times do |
||||
expect(p.ready_for_work?).to be(true) |
||||
p.schedule(&job) |
||||
end |
||||
expect(p.ready_for_work?).to be(false) |
||||
sleep 5 # give the pool time do get at least one task done |
||||
expect(p.ready_for_work?).to be(true) |
||||
end |
||||
end |
||||
|
||||
describe '#schedule' do |
||||
it 'return if the pool is already stopped' do |
||||
p = Pool.new(1) |
||||
p.stop |
||||
job = proc {} |
||||
expect { p.schedule(&job) }.to_not raise_error |
||||
end |
||||
|
||||
it 'adds jobs that get run by the pool' do |
||||
p = Pool.new(1) |
||||
p.start |
||||
o, q = Object.new, Queue.new |
||||
job = proc { q.push(o) } |
||||
p.schedule(&job) |
||||
expect(q.pop).to be(o) |
||||
p.stop |
||||
end |
||||
|
||||
it 'it throws an error if all of the workers have tasks to do' do |
||||
p = Pool.new(5) |
||||
p.start |
||||
job = proc {} |
||||
5.times do |
||||
expect(p.ready_for_work?).to be(true) |
||||
p.schedule(&job) |
||||
end |
||||
expect { p.schedule(&job) }.to raise_error |
||||
expect { p.schedule(&job) }.to raise_error |
||||
end |
||||
end |
||||
|
||||
describe '#stop' do |
||||
it 'works when there are no scheduled tasks' do |
||||
p = Pool.new(1) |
||||
expect { p.stop }.not_to raise_error |
||||
end |
||||
|
||||
it 'stops jobs when there are long running jobs' do |
||||
p = Pool.new(1) |
||||
p.start |
||||
o, q = Object.new, Queue.new |
||||
job = proc do |
||||
sleep(5) # long running |
||||
q.push(o) |
||||
end |
||||
p.schedule(&job) |
||||
sleep(1) # should ensure the long job gets scheduled |
||||
expect { p.stop }.not_to raise_error |
||||
end |
||||
end |
||||
|
||||
describe '#start' do |
||||
it 'runs jobs as they are scheduled' do |
||||
p = Pool.new(5) |
||||
o, q = Object.new, Queue.new |
||||
p.start |
||||
n = 5 # arbitrary |
||||
n.times do |
||||
p.schedule(o, &q.method(:push)) |
||||
expect(q.pop).to be(o) |
||||
end |
||||
p.stop |
||||
end |
||||
end |
||||
end |
Loading…
Reference in new issue