Merge pull request #17862 from jerrycmh/memory_leak_test

Memory Leak Test for php unit tests
pull/18105/head
Stanley Cheung 6 years ago committed by GitHub
commit 0c91494fa0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      src/php/bin/run_tests.sh
  2. 90
      src/php/tests/MemoryLeakTest/MemoryLeakTest.php
  3. 10
      src/php/tests/unit_tests/CallTest.php
  4. 5
      templates/tools/dockerfile/php_valgrind.include
  5. 1
      templates/tools/dockerfile/test/php7_jessie_x64/Dockerfile.template
  6. 6
      tools/dockerfile/test/php7_jessie_x64/Dockerfile

@ -28,3 +28,10 @@ php $extension_dir -d max_execution_time=300 $(which phpunit) -v --debug \
php $extension_dir -d max_execution_time=300 $(which phpunit) -v --debug \
../tests/unit_tests/PersistentChannelTests
export ZEND_DONT_UNLOAD_MODULES=1
export USE_ZEND_ALLOC=0
# Detect whether valgrind is executable
if [ -x "$(command -v valgrind)" ]; then
valgrind --error-exitcode=10 --leak-check=yes php $extension_dir -d max_execution_time=300 \
../tests/MemoryLeakTest/MemoryLeakTest.php
fi

@ -0,0 +1,90 @@
<?php
/*
*
* 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.
*
*/
//==============Channel Test====================
function callbackFunc($context)
{
return [];
}
function callbackFunc2($context)
{
return ["k1" => "v1"];
}
function assertConnecting($state)
{
assert(($state == GRPC\CHANNEL_CONNECTING || $state == GRPC\CHANNEL_TRANSIENT_FAILURE) == true);
}
function waitUntilNotIdle($channel) {
for ($i = 0; $i < 10; $i++) {
$now = Grpc\Timeval::now();
$deadline = $now->add(new Grpc\Timeval(10000));
if ($channel->watchConnectivityState(GRPC\CHANNEL_IDLE,
$deadline)) {
return true;
}
}
assert(true == false);
}
// Set up
$channel = new Grpc\Channel('localhost:0', ['credentials' => Grpc\ChannelCredentials::createInsecure()]);
// Test InsecureCredentials
assert('Grpc\Channel' == get_class($channel));
// Test ConnectivityState
$state = $channel->getConnectivityState();
assert(0 == $state);
// Test GetConnectivityStateWithInt
$state = $channel->getConnectivityState(123);
assert(0 == $state);
// Test GetConnectivityStateWithString
$state = $channel->getConnectivityState('hello');
assert(0 == $state);
// Test GetConnectivityStateWithBool
$state = $channel->getConnectivityState(true);
assert(0 == $state);
$channel->close();
// Test GetTarget
$channel = new Grpc\Channel('localhost:8888', ['credentials' => Grpc\ChannelCredentials::createInsecure()]);
$target = $channel->getTarget();
assert(is_string($target) == true);
$channel->close();
// Test WatchConnectivityState
$channel = new Grpc\Channel('localhost:0', ['credentials' => Grpc\ChannelCredentials::createInsecure()]);
$now = Grpc\Timeval::now();
$deadline = $now->add(new Grpc\Timeval(100*1000));
$state = $channel->watchConnectivityState(1, $deadline);
assert($state == true);
unset($now);
unset($deadline);
$channel->close();

@ -86,6 +86,16 @@ class CallTest extends PHPUnit_Framework_TestCase
$this->assertTrue($result->send_metadata);
}
public function testAddMultiAndMultiValueMetadata()
{
$batch = [
Grpc\OP_SEND_INITIAL_METADATA => ['key1' => ['value1', 'value2'],
'key2' => ['value3', 'value4'],],
];
$result = $this->call->startBatch($batch);
$this->assertTrue($result->send_metadata);
}
public function testGetPeer()
{
$this->assertTrue(is_string($this->call->getPeer()));

@ -0,0 +1,5 @@
#=================
# PHP Test dependencies
RUN apt-get update && apt-get install -y ${'\\'}
valgrind

@ -19,6 +19,7 @@
<%include file="../../php7_deps.include"/>
<%include file="../../gcp_api_libraries.include"/>
<%include file="../../python_deps.include"/>
<%include file="../../php_valgrind.include"/>
<%include file="../../run_tests_addons.include"/>
# Define the default command.
CMD ["bash"]

@ -79,6 +79,12 @@ RUN pip install --upgrade pip==10.0.1
RUN pip install virtualenv
RUN pip install futures==2.2.0 enum34==1.0.4 protobuf==3.5.2.post1 six==1.10.0 twisted==17.5.0
#=================
# PHP Test dependencies
RUN apt-get update && apt-get install -y \
valgrind
RUN mkdir /var/local/jenkins

Loading…
Cancel
Save