Merge pull request #18398 from lidizheng/fix-18244-take-2

Use C-Core API to perform time conversion
pull/18353/head
Lidi Zheng 6 years ago committed by GitHub
commit 47c1479b8c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      src/python/grpcio/grpc/_cython/_cygrpc/grpc.pxi
  2. 2
      src/python/grpcio/grpc/_cython/_cygrpc/time.pxd.pxi
  3. 13
      src/python/grpcio/grpc/_cython/_cygrpc/time.pyx.pxi
  4. 4
      src/python/grpcio_tests/commands.py
  5. 8
      src/python/grpcio_tests/tests/unit/_cython/_channel_test.py

@ -53,6 +53,10 @@ cdef extern from "grpc/grpc.h":
void *grpc_slice_start_ptr "GRPC_SLICE_START_PTR" (grpc_slice s) nogil
size_t grpc_slice_length "GRPC_SLICE_LENGTH" (grpc_slice s) nogil
const int GPR_MS_PER_SEC
const int GPR_US_PER_SEC
const int GPR_NS_PER_SEC
ctypedef enum gpr_clock_type:
GPR_CLOCK_MONOTONIC
GPR_CLOCK_REALTIME
@ -74,6 +78,8 @@ cdef extern from "grpc/grpc.h":
gpr_clock_type target_clock) nogil
gpr_timespec gpr_time_from_millis(int64_t ms, gpr_clock_type type) nogil
gpr_timespec gpr_time_from_nanos(int64_t ns, gpr_clock_type type) nogil
double gpr_timespec_to_micros(gpr_timespec t) nogil
gpr_timespec gpr_time_add(gpr_timespec a, gpr_timespec b) nogil

@ -13,7 +13,7 @@
# limitations under the License.
cdef gpr_timespec _timespec_from_time(object time)
cdef gpr_timespec _timespec_from_time(object time) except *
cdef double _time_from_timespec(gpr_timespec timespec) except *

@ -13,18 +13,17 @@
# limitations under the License.
cdef gpr_timespec _timespec_from_time(object time):
cdef gpr_timespec timespec
cdef gpr_timespec _timespec_from_time(object time) except *:
if time is None:
return gpr_inf_future(GPR_CLOCK_REALTIME)
else:
timespec.seconds = time
timespec.nanoseconds = (time - float(timespec.seconds)) * 1e9
timespec.clock_type = GPR_CLOCK_REALTIME
return timespec
return gpr_time_from_nanos(
<int64_t>(<double>time * GPR_NS_PER_SEC),
GPR_CLOCK_REALTIME,
)
cdef double _time_from_timespec(gpr_timespec timespec) except *:
cdef gpr_timespec real_timespec = gpr_convert_clock_type(
timespec, GPR_CLOCK_REALTIME)
return <double>real_timespec.seconds + <double>real_timespec.nanoseconds / 1e9
return gpr_timespec_to_micros(real_timespec) / GPR_US_PER_SEC

@ -147,7 +147,9 @@ class TestGevent(setuptools.Command):
# TODO(https://github.com/grpc/grpc/issues/17330) enable these three tests
'channelz._channelz_servicer_test.ChannelzServicerTest.test_many_subchannels',
'channelz._channelz_servicer_test.ChannelzServicerTest.test_many_subchannels_and_sockets',
'channelz._channelz_servicer_test.ChannelzServicerTest.test_streaming_rpc'
'channelz._channelz_servicer_test.ChannelzServicerTest.test_streaming_rpc',
# TODO(https://github.com/grpc/grpc/issues/15411) enable this test
'unit._cython._channel_test.ChannelTest.test_negative_deadline_connectivity'
)
description = 'run tests with gevent. Assumes grpc/gevent are installed'
user_options = []

@ -57,6 +57,14 @@ class ChannelTest(unittest.TestCase):
def test_multiple_channels_lonely_connectivity(self):
_in_parallel(_create_loop_destroy, ())
def test_negative_deadline_connectivity(self):
channel = _channel()
connectivity = channel.check_connectivity_state(True)
channel.watch_connectivity_state(connectivity, -3.14)
channel.close(cygrpc.StatusCode.ok, 'Channel close!')
# NOTE(lidiz) The negative timeout should not trigger SIGABRT.
# Bug report: https://github.com/grpc/grpc/issues/18244
if __name__ == '__main__':
unittest.main(verbosity=2)

Loading…
Cancel
Save