HTTP timeouts should cause some tests to be skipped, not failed
A number of the HTTP external tests can inconstantly fail. As the HTTP API is one that doesn't change often, this failure creates noise. With the goal of increasing the signal from the unit tests, these tests are now skipped if they timeout. A notice is added when running the external http tests so that the developer knows what skipped tests may mean here. See #33968 git-svn-id: https://develop.svn.wordpress.org/trunk@34848 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
f3f892ce46
commit
ba06fc4f5b
@ -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'] );
|
||||
|
@ -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'] ) );
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user