aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Nicolas "Pixel" Noble <pixel@nobis-crew.org>2016-03-10 23:39:47 +0100
committerGravatar Nicolas "Pixel" Noble <pixel@nobis-crew.org>2016-03-10 23:39:47 +0100
commit9f0f1e3f6173be491c8b5d074d539ea051288771 (patch)
tree109114633aaee67029525017bcbacecc26cfab01
parent280eedd2e58aa4d1cacf56eb2102a7be5f4b0841 (diff)
parentfbdf51b07e56d0794776e40bc3a4a054e1883f0e (diff)
Merge branch 'master' into pre-0.13.1-downmerge
-rw-r--r--CONTRIBUTING.md8
-rw-r--r--setup.py7
-rw-r--r--src/cpp/README.md74
-rw-r--r--src/ruby/.rubocop.yml3
-rw-r--r--src/ruby/lib/grpc/generic/rpc_server.rb97
-rw-r--r--src/ruby/spec/generic/rpc_server_spec.rb25
-rw-r--r--tools/run_tests/artifact_targets.py20
-rwxr-xr-xtools/run_tests/build_python.sh6
-rwxr-xr-xtools/run_tests/run_python.sh2
-rwxr-xr-xtools/run_tests/run_tests.py2
10 files changed, 164 insertions, 80 deletions
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 3f7519a1d7..b4e958d3b2 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -45,9 +45,13 @@ In order to run most of the available tests, one would need to run:
`./tools/run_tests/run_tests.py`
-If you want to run all the possible tests for any of the languages {c, c++, node, php, python}, do this:
+If you want to run tests for any of the languages {c, c++, csharp, node, objc, php, python, ruby}, do this:
-`./tools/run_tests/run_tests.py -l <lang> -c all`
+`./tools/run_tests/run_tests.py -l <lang>`
+
+To know about the list of available commands, do this:
+
+`./tools/run_tests/run_tests.py -h`
## Adding or removing source code
diff --git a/setup.py b/setup.py
index 7b8e2ba0d9..45ff2cec89 100644
--- a/setup.py
+++ b/setup.py
@@ -108,8 +108,13 @@ if "linux" in sys.platform or "darwin" in sys.platform:
def cython_extensions(package_names, module_names, extra_sources, include_dirs,
libraries, define_macros, build_with_cython=False):
+ # Set compiler directives linetrace argument only if we care about tracing;
+ # this is due to Cython having different behavior between linetrace being
+ # False and linetrace being unset. See issue #5689.
+ cython_compiler_directives = {}
if ENABLE_CYTHON_TRACING:
define_macros = define_macros + [('CYTHON_TRACE_NOGIL', 1)]
+ cython_compiler_directives['linetrace'] = True
file_extension = 'pyx' if build_with_cython else 'c'
module_files = [os.path.join(PYTHON_STEM,
name.replace('.', '/') + '.' + file_extension)
@@ -129,7 +134,7 @@ def cython_extensions(package_names, module_names, extra_sources, include_dirs,
return Cython.Build.cythonize(
extensions,
include_path=include_dirs,
- compiler_directives={'linetrace': bool(ENABLE_CYTHON_TRACING)})
+ compiler_directives=cython_compiler_directives)
else:
return extensions
diff --git a/src/cpp/README.md b/src/cpp/README.md
index baeba08315..83d37aa2ed 100644
--- a/src/cpp/README.md
+++ b/src/cpp/README.md
@@ -6,3 +6,77 @@ This directory contains source code for C++ implementation of gRPC.
#Status
Beta
+
+#Pre-requisites
+
+##Linux
+
+```sh
+ $ [sudo] apt-get install build-essential autoconf libtool
+```
+
+##Mac OSX
+
+For a Mac system, git is not available by default. You will first need to
+install Xcode from the Mac AppStore and then run the following command from a
+terminal:
+
+```sh
+ $ [sudo] xcode-select --install
+```
+
+##Protoc
+
+By default gRPC uses [protocol buffers](https://github.com/google/protobuf),
+you will need the `protoc` compiler to generate stub server and client code.
+
+If you compile gRPC from source, as described below, this also installs the
+`protoc` compiler.
+
+If it hasn't been installed, you can run the following commands to install it.
+
+```sh
+$ cd grpc/third_party/protobuf
+$ sudo make install # 'make' should have been run by core grpc
+```
+
+Alternatively, you can download `protoc` binaries from
+[the protocol buffers Github repository](https://github.com/google/protobuf/releases).
+
+#Installation
+
+Currently to install gRPC for C++, you need to build from source as described
+below.
+
+#Build from Source
+
+```sh
+ $ git clone https://github.com/grpc/grpc.git
+ $ cd grpc
+ $ git submodule update --init
+ $ make
+ $ [sudo] make install
+```
+
+#Documentation
+
+You can find out how to build and run our simplest gRPC C++ example in our
+[C++ quick start](https://github.com/grpc/grpc/tree/{{ site.data.config.grpc_release_branch }}/examples/cpp).
+
+For more detailed documentation on using gRPC in C++ , see our main
+documentation site at [grpc.io](http://grpc.io), specifically:
+
+* [Overview](http://www.grpc.io/docs/): An introduction to gRPC with a simple
+ Hello World example in all our supported languages, including C++.
+* [gRPC Basics - C++](http://www.grpc.io/docs/tutorials/basic/c.html):
+ A tutorial that steps you through creating a simple gRPC C++ example
+ application.
+* [Asynchronous Basics - C++](http://www.grpc.io/docs/tutorials/async/helloasync-cpp.html):
+ A tutorial that shows you how to use gRPC C++'s asynchronous/non-blocking
+ APIs.
+
+
+# Examples
+
+Code examples for gRPC C++ live in this repository's
+[examples/cpp](https://github.com/grpc/grpc/tree/{{ site.data.config.grpc_release_branch }}/examples/cpp) directory.
diff --git a/src/ruby/.rubocop.yml b/src/ruby/.rubocop.yml
index ff5cf8db83..d13ce42655 100644
--- a/src/ruby/.rubocop.yml
+++ b/src/ruby/.rubocop.yml
@@ -15,3 +15,6 @@ Metrics/CyclomaticComplexity:
Metrics/PerceivedComplexity:
Max: 8
+
+Metrics/ClassLength:
+ Max: 250
diff --git a/src/ruby/lib/grpc/generic/rpc_server.rb b/src/ruby/lib/grpc/generic/rpc_server.rb
index ef2997c991..b30d19dd2b 100644
--- a/src/ruby/lib/grpc/generic/rpc_server.rb
+++ b/src/ruby/lib/grpc/generic/rpc_server.rb
@@ -107,7 +107,9 @@ module GRPC
# Starts running the jobs in the thread pool.
def start
- fail 'already stopped' if @stopped
+ @stop_mutex.synchronize do
+ fail 'already stopped' if @stopped
+ end
until @workers.size == @size.to_i
next_thread = Thread.new do
catch(:exit) do # allows { throw :exit } to kill a thread
@@ -264,10 +266,10 @@ module GRPC
@pool = Pool.new(@pool_size)
@run_cond = ConditionVariable.new
@run_mutex = Mutex.new
- @running = false
+ # running_state can take 4 values: :not_started, :running, :stopping, and
+ # :stopped. State transitions can only proceed in that order.
+ @running_state = :not_started
@server = RpcServer.setup_srv(server_override, @cq, **kw)
- @stopped = false
- @stop_mutex = Mutex.new
end
# stops a running server
@@ -275,27 +277,42 @@ module GRPC
# the call has no impact if the server is already stopped, otherwise
# server's current call loop is it's last.
def stop
- return unless @running
- @stop_mutex.synchronize do
- @stopped = true
+ @run_mutex.synchronize do
+ fail 'Cannot stop before starting' if @running_state == :not_started
+ return if @running_state != :running
+ transition_running_state(:stopping)
end
deadline = from_relative_time(@poll_period)
- return if @server.close(@cq, deadline)
- deadline = from_relative_time(@poll_period)
@server.close(@cq, deadline)
@pool.stop
end
- # determines if the server has been stopped
- def stopped?
- @stop_mutex.synchronize do
- return @stopped
+ def running_state
+ @run_mutex.synchronize do
+ return @running_state
+ end
+ end
+
+ # Can only be called while holding @run_mutex
+ def transition_running_state(target_state)
+ state_transitions = {
+ not_started: :running,
+ running: :stopping,
+ stopping: :stopped
+ }
+ if state_transitions[@running_state] == target_state
+ @running_state = target_state
+ else
+ fail "Bad server state transition: #{@running_state}->#{target_state}"
end
end
- # determines if the server is currently running
def running?
- @running
+ running_state == :running
+ end
+
+ def stopped?
+ running_state == :stopped
end
# Is called from other threads to wait for #run to start up the server.
@@ -304,13 +321,11 @@ module GRPC
#
# @param timeout [Numeric] number of seconds to wait
# @result [true, false] true if the server is running, false otherwise
- def wait_till_running(timeout = 0.1)
- end_time, sleep_period = Time.now + timeout, (1.0 * timeout) / 100
- while Time.now < end_time
- @run_mutex.synchronize { @run_cond.wait(@run_mutex) } unless running?
- sleep(sleep_period)
+ def wait_till_running(timeout = nil)
+ @run_mutex.synchronize do
+ @run_cond.wait(@run_mutex, timeout) if @running_state == :not_started
+ return @running_state == :running
end
- running?
end
# Runs the server in its own thread, then waits for signal INT or TERM on
@@ -360,11 +375,14 @@ module GRPC
# @param service [Object|Class] a service class or object as described
# above
def handle(service)
- fail 'cannot add services if the server is running' if running?
- fail 'cannot add services if the server is stopped' if stopped?
- cls = service.is_a?(Class) ? service : service.class
- assert_valid_service_class(cls)
- add_rpc_descs_for(service)
+ @run_mutex.synchronize do
+ unless @running_state == :not_started
+ fail 'cannot add services if the server has been started'
+ end
+ cls = service.is_a?(Class) ? service : service.class
+ assert_valid_service_class(cls)
+ add_rpc_descs_for(service)
+ end
end
# runs the server
@@ -375,16 +393,13 @@ module GRPC
# - #running? returns true after this is called, until #stop cause the
# the server to stop.
def run
- if rpc_descs.size.zero?
- GRPC.logger.warn('did not run as no services were present')
- return
- end
@run_mutex.synchronize do
- @running = true
- @run_cond.signal
+ fail 'cannot run without registering services' if rpc_descs.size.zero?
+ @pool.start
+ @server.start
+ transition_running_state(:running)
+ @run_cond.broadcast
end
- @pool.start
- @server.start
loop_handle_server_calls
end
@@ -413,9 +428,9 @@ module GRPC
# handles calls to the server
def loop_handle_server_calls
- fail 'not running' unless @running
+ fail 'not started' if running_state == :not_started
loop_tag = Object.new
- until stopped?
+ while running_state == :running
begin
an_rpc = @server.request_call(@cq, loop_tag, INFINITE_FUTURE)
break if (!an_rpc.nil?) && an_rpc.call.nil?
@@ -430,11 +445,14 @@ module GRPC
rescue Core::CallError, RuntimeError => e
# these might happen for various reasonse. The correct behaviour of
# the server is to log them and continue, if it's not shutting down.
- GRPC.logger.warn("server call failed: #{e}") unless stopped?
+ if running_state == :running
+ GRPC.logger.warn("server call failed: #{e}")
+ end
next
end
end
- @running = false
+ # @running_state should be :stopping here
+ @run_mutex.synchronize { transition_running_state(:stopped) }
GRPC.logger.info("stopped: #{self}")
end
@@ -484,9 +502,10 @@ module GRPC
cls.assert_rpc_descs_have_methods
end
+ # This should be called while holding @run_mutex
def add_rpc_descs_for(service)
cls = service.is_a?(Class) ? service : service.class
- specs, handlers = rpc_descs, rpc_handlers
+ specs, handlers = (@rpc_descs ||= {}), (@rpc_handlers ||= {})
cls.rpc_descs.each_pair do |name, spec|
route = "/#{cls.service_name}/#{name}".to_sym
fail "already registered: rpc #{route} from #{spec}" if specs.key? route
diff --git a/src/ruby/spec/generic/rpc_server_spec.rb b/src/ruby/spec/generic/rpc_server_spec.rb
index be6331d68b..dfaec6d6ed 100644
--- a/src/ruby/spec/generic/rpc_server_spec.rb
+++ b/src/ruby/spec/generic/rpc_server_spec.rb
@@ -1,4 +1,4 @@
-# Copyright 2015, Google Inc.
+# Copyright 2015-2016, Google Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -220,19 +220,10 @@ describe GRPC::RpcServer do
@srv = RpcServer.new(**opts)
end
- after(:each) do
- @srv.stop
- end
-
it 'starts out false' do
expect(@srv.stopped?).to be(false)
end
- it 'stays false after a #stop is called before #run' do
- @srv.stop
- expect(@srv.stopped?).to be(false)
- end
-
it 'stays false after the server starts running', server: true do
@srv.handle(EchoService)
t = Thread.new { @srv.run }
@@ -247,8 +238,8 @@ describe GRPC::RpcServer do
t = Thread.new { @srv.run }
@srv.wait_till_running
@srv.stop
- expect(@srv.stopped?).to be(true)
t.join
+ expect(@srv.stopped?).to be(true)
end
end
@@ -266,9 +257,7 @@ describe GRPC::RpcServer do
server_override: @server
}
r = RpcServer.new(**opts)
- r.run
- expect(r.running?).to be(false)
- r.stop
+ expect { r.run }.to raise_error(RuntimeError)
end
it 'is true after run is called with a registered service' do
@@ -293,10 +282,6 @@ describe GRPC::RpcServer do
@srv = RpcServer.new(**@opts)
end
- after(:each) do
- @srv.stop
- end
-
it 'raises if #run has already been called' do
@srv.handle(EchoService)
t = Thread.new { @srv.run }
@@ -528,10 +513,6 @@ describe GRPC::RpcServer do
@srv = RpcServer.new(**server_opts)
end
- after(:each) do
- @srv.stop
- end
-
it 'should be added to BadStatus when requests fail', server: true do
service = FailingService.new
@srv.handle(service)
diff --git a/tools/run_tests/artifact_targets.py b/tools/run_tests/artifact_targets.py
index 288a3f0154..e61c46d8b5 100644
--- a/tools/run_tests/artifact_targets.py
+++ b/tools/run_tests/artifact_targets.py
@@ -69,16 +69,6 @@ def create_jobspec(name, cmdline, environ=None, shell=False,
return jobspec
-def macos_arch_env(arch):
- """Returns environ specifying -arch arguments for make."""
- if arch == 'x86':
- arch_arg = '-arch i386'
- elif arch == 'x64':
- arch_arg = '-arch x86_64'
- else:
- raise Exception('Unsupported arch')
- return {'CFLAGS': arch_arg, 'LDFLAGS': arch_arg}
-
_MACOS_COMPAT_FLAG = '-mmacosx-version-min=10.7'
_ARCH_FLAG_MAP = {
@@ -191,13 +181,17 @@ class CSharpExtArtifact:
environ = {'CONFIG': 'opt',
'EMBED_OPENSSL': 'true',
'EMBED_ZLIB': 'true',
- 'CFLAGS': '-DGPR_BACKWARDS_COMPATIBILITY_MODE'}
+ 'CFLAGS': '-DGPR_BACKWARDS_COMPATIBILITY_MODE',
+ 'LDFLAGS': ''}
if self.platform == 'linux':
return create_docker_jobspec(self.name,
'tools/dockerfile/grpc_artifact_linux_%s' % self.arch,
- 'tools/run_tests/build_artifact_csharp.sh')
+ 'tools/run_tests/build_artifact_csharp.sh',
+ environ=environ)
else:
- environ.update(macos_arch_env(self.arch))
+ archflag = _ARCH_FLAG_MAP[self.arch]
+ environ['CFLAGS'] += ' %s %s' % (archflag, _MACOS_COMPAT_FLAG)
+ environ['LDFLAGS'] += ' %s' % archflag
return create_jobspec(self.name,
['tools/run_tests/build_artifact_csharp.sh'],
environ=environ)
diff --git a/tools/run_tests/build_python.sh b/tools/run_tests/build_python.sh
index f120fc7ed6..79a148faf1 100755
--- a/tools/run_tests/build_python.sh
+++ b/tools/run_tests/build_python.sh
@@ -40,7 +40,11 @@ export PATH=$ROOT/bins/$CONFIG:$ROOT/bins/$CONFIG/protobuf:$PATH
export CFLAGS="-I$ROOT/include -std=gnu99"
export LDFLAGS="-L$ROOT/libs/$CONFIG"
export GRPC_PYTHON_BUILD_WITH_CYTHON=1
-export GRPC_PYTHON_ENABLE_CYTHON_TRACING=1
+
+if [ "$CONFIG" = "gcov" ]
+then
+ export GRPC_PYTHON_ENABLE_CYTHON_TRACING=1
+fi
tox --notest
diff --git a/tools/run_tests/run_python.sh b/tools/run_tests/run_python.sh
index ace49e1514..d4b7250cbb 100755
--- a/tools/run_tests/run_python.sh
+++ b/tools/run_tests/run_python.sh
@@ -40,10 +40,10 @@ export PATH=$ROOT/bins/$CONFIG:$ROOT/bins/$CONFIG/protobuf:$PATH
export CFLAGS="-I$ROOT/include -std=c89"
export LDFLAGS="-L$ROOT/libs/$CONFIG"
export GRPC_PYTHON_BUILD_WITH_CYTHON=1
-export GRPC_PYTHON_ENABLE_CYTHON_TRACING=1
if [ "$CONFIG" = "gcov" ]
then
+ export GRPC_PYTHON_ENABLE_CYTHON_TRACING=1
tox
else
$ROOT/.tox/py27/bin/python $ROOT/setup.py test_lite
diff --git a/tools/run_tests/run_tests.py b/tools/run_tests/run_tests.py
index cc004f38d7..2df82adf0a 100755
--- a/tools/run_tests/run_tests.py
+++ b/tools/run_tests/run_tests.py
@@ -360,7 +360,7 @@ class PythonLanguage(object):
['tools/run_tests/run_python.sh'],
None,
environ=dict(environment.items() +
- [('GPRC_PYTHON_TESTRUNNER_FILTER', suite_name)]),
+ [('GRPC_PYTHON_TESTRUNNER_FILTER', suite_name)]),
shortname='py.test.%s' % suite_name,
timeout_seconds=5*60)
for suite_name in tests_json]