diff --git a/tests/phpunit/includes/bootstrap.php b/tests/phpunit/includes/bootstrap.php index e74b618691..0beefd604a 100644 --- a/tests/phpunit/includes/bootstrap.php +++ b/tests/phpunit/includes/bootstrap.php @@ -164,6 +164,13 @@ class WP_PHPUnit_Util_Getopt extends PHPUnit_Util_Getopt { foreach ( $skipped_groups as $group_name => $skipped ) { echo sprintf( 'Not running %1$s tests. To execute these, use --group %1$s.', $group_name ) . PHP_EOL; } + + if ( ! isset( $skipped_groups['external-http'] ) ){ + echo PHP_EOL; + echo 'External HTTP skipped tests can be caused by timeouts.' . PHP_EOL; + echo 'If this changeset inclues changes to HTTP, make sure there are no timeouts.' . PHP_EOL; + echo PHP_EOL; + } } } new WP_PHPUnit_Util_Getopt( $_SERVER['argv'] ); diff --git a/tests/phpunit/tests/http/base.php b/tests/phpunit/tests/http/base.php index c95fac303e..337a74b50e 100644 --- a/tests/phpunit/tests/http/base.php +++ b/tests/phpunit/tests/http/base.php @@ -17,6 +17,27 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase { protected $http_request_args; + /** + * Mark test as skipped if the HTTP request times out + */ + function skipTestOnTimeout( $response ) { + if( ! is_wp_error( $response ) ){ + return; + } + if ( 'connect() timed out!' === $response->get_error_message() ){ + $this->markTestSkipped( 'HTTP timeout' ); + } + + if ( 0 === strpos( $response->get_error_message(), 'Operation timed out after' ) ){ + $this->markTestSkipped( 'HTTP timeout' ); + } + + if ( 'stream_socket_client(): unable to connect to tcp://s.w.org:80 (Connection timed out)' === $response->get_error_message() ){ + $this->markTestSkipped( 'HTTP timeout' ); + } + + } + function setUp() { if ( is_callable( array('WP_Http', '_getTransport') ) ) { @@ -198,6 +219,8 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase { unlink( $res['filename'] ); } + $this->skipTestOnTimeout ($res ); + $this->assertNotWPError( $res ); $this->assertEquals( '', $res['body'] ); // The body should be empty. $this->assertEquals( $size, $res['headers']['content-length'] ); // Check the headers are returned (and the size is the same..) @@ -219,6 +242,8 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase { unlink( $res['filename'] ); } + $this->skipTestOnTimeout ($res ); + $this->assertNotWPError( $res ); $this->assertEquals( $size, $filesize ); // Check that the file is written to disk correctly without any extra characters @@ -235,6 +260,8 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase { $res = wp_remote_request( $url, array( 'timeout' => 30, 'limit_response_size' => $size ) ); + $this->skipTestOnTimeout ($res ); + $this->assertNotWPError( $res ); $this->assertEquals( $size, strlen( $res['body'] ) ); }