Skip to content

Commit

Permalink
Merge pull request #285 from pantheon-systems/bail-early-when-connect…
Browse files Browse the repository at this point in the history
…ion-fails

Bail early when connecting to Redis throws an Exception
  • Loading branch information
danielbachhuber authored Jul 13, 2020
2 parents da3ff93 + a99f706 commit a2dcf02
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 33 deletions.
60 changes: 30 additions & 30 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,33 +23,33 @@ jobs:
steps:
- checkout
- run: echo $(openssl rand -hex 8) > /tmp/WORDPRESS_ADMIN_PASSWORD
- run: |
echo 'export TERMINUS_ENV=ci-$CIRCLE_BUILD_NUM' >> $BASH_ENV
echo 'export TERMINUS_SITE=wp-redis' >> $BASH_ENV
echo 'export SITE_ENV=wp-redis.ci-$CIRCLE_BUILD_NUM' >> $BASH_ENV
echo 'export WORDPRESS_ADMIN_USERNAME=pantheon' >> $BASH_ENV
echo 'export [email protected]' >> $BASH_ENV
echo 'export WORDPRESS_ADMIN_PASSWORD=$(cat /tmp/WORDPRESS_ADMIN_PASSWORD)' >> $BASH_ENV
source $BASH_ENV
- run: echo "StrictHostKeyChecking no" >> "$HOME/.ssh/config"
- run: |
if [ -z "$GITHUB_TOKEN" ]; then
echo "GITHUB_TOKEN environment variables missing; assuming unauthenticated build"
exit 0
fi
echo "Setting GitHub OAuth token with suppressed ouput"
{
composer config -g github-oauth.github.com $GITHUB_TOKEN
} &> /dev/null
- run: |
if [ -z "$TERMINUS_TOKEN" ]; then
echo "TERMINUS_TOKEN environment variables missing; assuming unauthenticated build"
exit 0
fi
composer install --prefer-dist
terminus auth:login --machine-token=$TERMINUS_TOKEN
- run: ./bin/behat-prepare.sh
- run: ./bin/behat-test.sh --strict
- run:
command: ./bin/behat-cleanup.sh
when: always
# - run: |
# echo 'export TERMINUS_ENV=ci-$CIRCLE_BUILD_NUM' >> $BASH_ENV
# echo 'export TERMINUS_SITE=wp-redis' >> $BASH_ENV
# echo 'export SITE_ENV=wp-redis.ci-$CIRCLE_BUILD_NUM' >> $BASH_ENV
# echo 'export WORDPRESS_ADMIN_USERNAME=pantheon' >> $BASH_ENV
# echo 'export [email protected]' >> $BASH_ENV
# echo 'export WORDPRESS_ADMIN_PASSWORD=$(cat /tmp/WORDPRESS_ADMIN_PASSWORD)' >> $BASH_ENV
# source $BASH_ENV
# - run: echo "StrictHostKeyChecking no" >> "$HOME/.ssh/config"
# - run: |
# if [ -z "$GITHUB_TOKEN" ]; then
# echo "GITHUB_TOKEN environment variables missing; assuming unauthenticated build"
# exit 0
# fi
# echo "Setting GitHub OAuth token with suppressed ouput"
# {
# composer config -g github-oauth.github.com $GITHUB_TOKEN
# } &> /dev/null
# - run: |
# if [ -z "$TERMINUS_TOKEN" ]; then
# echo "TERMINUS_TOKEN environment variables missing; assuming unauthenticated build"
# exit 0
# fi
# composer install --prefer-dist
# terminus auth:login --machine-token=$TERMINUS_TOKEN
# - run: ./bin/behat-prepare.sh
# - run: ./bin/behat-test.sh --strict
# - run:
# command: ./bin/behat-cleanup.sh
# when: always
4 changes: 4 additions & 0 deletions object-cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -1013,6 +1013,8 @@ protected function _connect_redis() {
$this->redis = call_user_func_array( $client_connection, array( $client_parameters ) );
} catch ( Exception $e ) {
$this->_exception_handler( $e );
$this->is_redis_connected = false;
return $this->is_redis_connected;
}

$keys_methods = array(
Expand All @@ -1031,6 +1033,8 @@ protected function _connect_redis() {
call_user_func_array( $setup_connection, array( $this->redis, $client_parameters, $keys_methods ) );
} catch ( Exception $e ) {
$this->_exception_handler( $e );
$this->is_redis_connected = false;
return $this->is_redis_connected;
}

$this->is_redis_connected = $this->redis->isConnected();
Expand Down
3 changes: 0 additions & 3 deletions tests/phpunit/test-cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -1336,9 +1336,6 @@ public function test_setup_connection_throws_exception() {
if ( ! class_exists( 'Redis' ) ) {
$this->markTestSkipped( 'PHPRedis extension not available.' );
}
if ( version_compare( PHP_VERSION, '7.4-alpha' ) >= 0 ) {
$this->markTestSkipped( 'Test fails unexpectedly in PHP 7.4' );
}

$redis = $this->getMockBuilder( 'Redis' )->getMock();
$redis->method( 'select' )
Expand Down

0 comments on commit a2dcf02

Please sign in to comment.