support 32bit timeout

pull/23994/head
root 4 years ago
parent dca24b8de5
commit 8f6fdec0fc
  1. 39
      src/php/docker/i386/Dockerfile
  2. 26
      src/php/ext/grpc/timeval.c
  3. 13
      src/php/tests/unit_tests/TimevalTest.php

@ -0,0 +1,39 @@
# Copyright 2020 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.
FROM i386/php:7.2
RUN apt-get -qq update && apt-get -qq install -y \
autoconf automake git libtool pkg-config \
valgrind wget zlib1g-dev
ARG MAKEFLAGS=-j8
WORKDIR /tmp
RUN wget https://phar.phpunit.de/phpunit-5.7.27.phar && \
mv phpunit-5.7.27.phar /usr/local/bin/phpunit && \
chmod +x /usr/local/bin/phpunit
WORKDIR /github/grpc
COPY . .
RUN pear package && \
find . -name grpc-*.tgz | xargs -I{} pecl install {}
CMD ["/github/grpc/src/php/bin/run_tests.sh", "--skip-persistent-channel-tests", "--ignore-valgrind-undef-errors"]

@ -55,19 +55,27 @@ zval *grpc_php_wrap_timeval(gpr_timespec wrapped TSRMLS_DC) {
/**
* Constructs a new instance of the Timeval class
* @param long $microseconds The number of microseconds in the interval
* @param number $microseconds The number of microseconds in the interval
*/
PHP_METHOD(Timeval, __construct) {
wrapped_grpc_timeval *timeval =
PHP_GRPC_GET_WRAPPED_OBJECT(wrapped_grpc_timeval, getThis());
php_grpc_long microseconds;
/* "l" == 1 long */
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &microseconds) ==
FAILURE) {
zend_throw_exception(spl_ce_InvalidArgumentException,
"Timeval expects a long", 1 TSRMLS_CC);
return;
int64_t microseconds = 0;
/* parse $microseconds as long */
if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET,
ZEND_NUM_ARGS() TSRMLS_CC, "l",
&microseconds) == FAILURE) {
double microsecondsDouble = 0.0;
/* parse $microseconds as double */
if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET,
ZEND_NUM_ARGS() TSRMLS_CC, "d",
&microsecondsDouble) == FAILURE) {
zend_throw_exception(spl_ce_InvalidArgumentException,
"Timeval expects a long or double", 1 TSRMLS_CC);
return;
}
microseconds = (int64_t)microsecondsDouble;
}
gpr_timespec time = gpr_time_from_micros(microseconds, GPR_TIMESPAN);
memcpy(&timeval->wrapped, &time, sizeof(gpr_timespec));

@ -67,6 +67,19 @@ class TimevalTest extends PHPUnit_Framework_TestCase
$this->time = new Grpc\Timeval(123.456);
$this->assertNotNull($this->time);
$this->assertSame('Grpc\Timeval', get_class($this->time));
$timeFromInt = new Grpc\Timeval(123);
$this->assertSame(0, Grpc\Timeval::compare($this->time, $timeFromInt));
}
public function testConstructorWithBigInt()
{
$this->time = new Grpc\Timeval(7200000000); // > 2^32
$this->assertNotNull($this->time);
$this->assertSame('Grpc\Timeval', get_class($this->time));
$halfHour = new Grpc\Timeval(1800000000); // < 2^31
$hour = $halfHour->add($halfHour);
$twoHour = $hour->add($hour);
$this->assertSame(0, Grpc\Timeval::compare($this->time, $twoHour));
}
public function testCompareSame()

Loading…
Cancel
Save