Tests: Use WP_HTTP_UnitTestCase::skipTestOnTimeout() in more HTTP tests.

Adjust it to handle more types of timeouts, e.g. "Resolving timed out", "Connection timed out".

See #44613.

git-svn-id: https://develop.svn.wordpress.org/trunk@43511 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov 2018-07-19 19:09:56 +00:00
parent ffdc5e6827
commit 0ba13ec260

View File

@ -28,7 +28,7 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase {
$this->markTestSkipped( 'HTTP timeout' );
}
if ( 0 === strpos( $response->get_error_message(), 'Operation timed out after' ) ) {
if ( false !== strpos( $response->get_error_message(), 'timed out after' ) ) {
$this->markTestSkipped( 'HTTP timeout' );
}
@ -74,6 +74,8 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase {
function test_redirect_on_301() {
// 5 : 5 & 301
$res = wp_remote_request( $this->redirection_script . '?code=301&rt=' . 5, array( 'redirection' => 5 ) );
$this->skipTestOnTimeout( $res );
$this->assertNotWPError( $res );
$this->assertEquals( 200, (int) $res['response']['code'] );
}
@ -81,6 +83,8 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase {
function test_redirect_on_302() {
// 5 : 5 & 302
$res = wp_remote_request( $this->redirection_script . '?code=302&rt=' . 5, array( 'redirection' => 5 ) );
$this->skipTestOnTimeout( $res );
$this->assertNotWPError( $res );
$this->assertEquals( 200, (int) $res['response']['code'] );
}
@ -91,6 +95,8 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase {
function test_redirect_on_301_no_redirect() {
// 5 > 0 & 301
$res = wp_remote_request( $this->redirection_script . '?code=301&rt=' . 5, array( 'redirection' => 0 ) );
$this->skipTestOnTimeout( $res );
$this->assertNotWPError( $res );
$this->assertEquals( 301, (int) $res['response']['code'] );
}
@ -101,6 +107,8 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase {
function test_redirect_on_302_no_redirect() {
// 5 > 0 & 302
$res = wp_remote_request( $this->redirection_script . '?code=302&rt=' . 5, array( 'redirection' => 0 ) );
$this->skipTestOnTimeout( $res );
$this->assertNotWPError( $res );
$this->assertEquals( 302, (int) $res['response']['code'] );
}
@ -108,6 +116,8 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase {
function test_redirections_equal() {
// 5 - 5
$res = wp_remote_request( $this->redirection_script . '?rt=' . 5, array( 'redirection' => 5 ) );
$this->skipTestOnTimeout( $res );
$this->assertNotWPError( $res );
$this->assertEquals( 200, (int) $res['response']['code'] );
}
@ -115,6 +125,8 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase {
function test_no_head_redirections() {
// No redirections on HEAD request:
$res = wp_remote_request( $this->redirection_script . '?code=302&rt=' . 1, array( 'method' => 'HEAD' ) );
$this->skipTestOnTimeout( $res );
$this->assertNotWPError( $res );
$this->assertEquals( 302, (int) $res['response']['code'] );
}
@ -130,6 +142,8 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase {
'method' => 'HEAD',
)
);
$this->skipTestOnTimeout( $res );
$this->assertNotWPError( $res );
$this->assertEquals( 200, (int) $res['response']['code'] );
}
@ -137,18 +151,24 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase {
function test_redirections_greater() {
// 10 > 5
$res = wp_remote_request( $this->redirection_script . '?rt=' . 10, array( 'redirection' => 5 ) );
$this->skipTestOnTimeout( $res );
$this->assertWPError( $res );
}
function test_redirections_greater_edgecase() {
// 6 > 5 (close edgecase)
$res = wp_remote_request( $this->redirection_script . '?rt=' . 6, array( 'redirection' => 5 ) );
$this->skipTestOnTimeout( $res );
$this->assertWPError( $res );
}
function test_redirections_less_edgecase() {
// 4 < 5 (close edgecase)
$res = wp_remote_request( $this->redirection_script . '?rt=' . 4, array( 'redirection' => 5 ) );
$this->skipTestOnTimeout( $res );
$this->assertNotWPError( $res );
}
@ -158,6 +178,8 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase {
function test_redirections_zero_redirections_specified() {
// 0 redirections asked for, Should return the document?
$res = wp_remote_request( $this->redirection_script . '?code=302&rt=' . 5, array( 'redirection' => 0 ) );
$this->skipTestOnTimeout( $res );
$this->assertNotWPError( $res );
$this->assertEquals( 302, (int) $res['response']['code'] );
}
@ -170,6 +192,8 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase {
function test_location_header_on_201() {
// Prints PASS on initial load, FAIL if the client follows the specified redirection
$res = wp_remote_request( $this->redirection_script . '?201-location=true' );
$this->skipTestOnTimeout( $res );
$this->assertNotWPError( $res );
$this->assertEquals( 'PASS', $res['body'] );
}
@ -189,6 +213,8 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase {
'timeout' => 30,
)
);
$this->skipTestOnTimeout( $res );
$this->assertEquals( 'PASS', wp_remote_retrieve_body( $res ) );
$this->assertTrue( ! empty( $res['headers']['location'] ) );
}
@ -205,6 +231,7 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase {
);
$res = wp_remote_request( $this->redirection_script . '?header-check', array( 'headers' => $headers ) );
$this->skipTestOnTimeout( $res );
$this->assertNotWPError( $res );
$headers = array();
@ -241,7 +268,6 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase {
}
$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..)
@ -270,7 +296,6 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase {
}
$this->skipTestOnTimeout( $res );
$this->assertNotWPError( $res );
$this->assertEquals( $size, $filesize ); // Check that the file is written to disk correctly without any extra characters
@ -293,7 +318,6 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase {
);
$this->skipTestOnTimeout( $res );
$this->assertNotWPError( $res );
$this->assertEquals( $size, strlen( $res['body'] ) );
}
@ -309,6 +333,8 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase {
$url = 'http://api.wordpress.org/core/tests/1.0/redirection.php?post-redirect-to-method=1';
$res = wp_remote_post( add_query_arg( 'response_code', $response_code, $url ), array( 'timeout' => 30 ) );
$this->skipTestOnTimeout( $res );
$this->assertEquals( $method, wp_remote_retrieve_body( $res ) );
}
@ -354,6 +380,8 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase {
);
$res = wp_remote_get( $url, $args );
$this->skipTestOnTimeout( $res );
$this->assertEquals( 'PASS', wp_remote_retrieve_body( $res ) );
}
@ -375,6 +403,7 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase {
remove_filter( 'http_request_args', array( $this, 'filter_http_request_args' ) );
$this->skipTestOnTimeout( $res );
$this->assertNotEmpty( $this->http_request_args['sslcertificates'] );
$this->assertNotWPError( $res );
}
@ -388,10 +417,13 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase {
$url = 'http://api.wordpress.org/core/tests/1.0/redirection.php?multiple-location-headers=1';
$res = wp_remote_head( $url, array( 'timeout' => 30 ) );
$this->skipTestOnTimeout( $res );
$this->assertInternalType( 'array', wp_remote_retrieve_header( $res, 'location' ) );
$this->assertCount( 2, wp_remote_retrieve_header( $res, 'location' ) );
$res = wp_remote_get( $url, array( 'timeout' => 30 ) );
$this->skipTestOnTimeout( $res );
$this->assertEquals( 'PASS', wp_remote_retrieve_body( $res ) );
}
@ -405,6 +437,8 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase {
$url = 'http://api.wordpress.org/core/tests/1.0/redirection.php?cookie-test=1';
$res = wp_remote_get( $url );
$this->skipTestOnTimeout( $res );
$this->assertEquals( 'PASS', wp_remote_retrieve_body( $res ) );
}
@ -420,6 +454,8 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase {
}
$res = wp_remote_get( 'https://wordpress.org/' );
$this->skipTestOnTimeout( $res );
$this->assertNotWPError( $res );
}
@ -433,6 +469,8 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase {
$url = str_replace( $path, '/' . $path, $url );
$res = wp_remote_request( $url );
$this->skipTestOnTimeout( $res );
$this->assertNotWPError( $res );
}