Skip to content
Permalink
Browse files

Tests: Use `WP_HTTP_UnitTestCase::skipTestOnTimeout()` in more HTTP t…

…ests.

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

Merges [43511] to the 4.9 branch.
See #44613.

git-svn-id: https://develop.svn.wordpress.org/branches/4.9@43625 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information...
SergeyBiryukov committed Sep 3, 2018
1 parent aadaa64 commit 9e8090fcee91e195e8d260e35b0124b2e160c492
Showing with 42 additions and 4 deletions.
  1. +42 −4 tests/phpunit/tests/http/base.php
@@ -28,7 +28,7 @@ function skipTestOnTimeout( $response ) {
$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' );
}
@@ -73,13 +73,17 @@ function filter_http_request_args( array $args ) {
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'] );
}
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'] );
}
@@ -90,6 +94,8 @@ function test_redirect_on_302() {
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'] );
}
@@ -100,20 +106,26 @@ function test_redirect_on_301_no_redirect() {
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'] );
}
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'] );
}
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'] );
}
@@ -124,25 +136,33 @@ function test_no_head_redirections() {
function test_redirect_on_head() {
// Redirections on HEAD request when Requested
$res = wp_remote_request($this->redirection_script . '?rt=' . 5, array('redirection' => 5, 'method' => 'HEAD') );
$this->skipTestOnTimeout( $res );
$this->assertNotWPError( $res );
$this->assertEquals( 200, (int)$res['response']['code'] );
}
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 );
}
@@ -152,6 +172,8 @@ function test_redirections_less_edgecase() {
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'] );
}
@@ -164,6 +186,8 @@ function test_redirections_zero_redirections_specified() {
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']);
}
@@ -178,6 +202,8 @@ function test_no_redirection_on_PUT() {
// Test 301 - POST to POST
$res = wp_remote_request( $url, array( 'method' => 'PUT', 'timeout' => 30 ) );
$this->skipTestOnTimeout( $res );
$this->assertEquals( 'PASS', wp_remote_retrieve_body( $res ) );
$this->assertTrue( !empty( $res['headers']['location'] ) );
}
@@ -190,6 +216,7 @@ function test_send_headers() {
$headers = array('test1' => 'test', 'test2' => 0, 'test3' => '');
$res = wp_remote_request( $this->redirection_script . '?header-check', array('headers' => $headers) );
$this->skipTestOnTimeout( $res );
$this->assertNotWPError( $res );
$headers = array();
@@ -220,7 +247,6 @@ function test_file_stream() {
}
$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..)
@@ -243,7 +269,6 @@ function test_file_stream_limited_size() {
}
$this->skipTestOnTimeout( $res );
$this->assertNotWPError( $res );
$this->assertEquals( $size, $filesize ); // Check that the file is written to disk correctly without any extra characters
@@ -261,7 +286,6 @@ function test_request_limited_size() {
$res = wp_remote_request( $url, array( 'timeout' => 30, 'limit_response_size' => $size ) );
$this->skipTestOnTimeout( $res );
$this->assertNotWPError( $res );
$this->assertEquals( $size, strlen( $res['body'] ) );
}
@@ -277,6 +301,8 @@ function test_post_redirect_to_method_300( $response_code, $method ) {
$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 ) );
}
@@ -322,6 +348,8 @@ function test_ip_url_with_host_header() {
);
$res = wp_remote_get( $url, $args );
$this->skipTestOnTimeout( $res );
$this->assertEquals( 'PASS', wp_remote_retrieve_body( $res ) );
}
@@ -343,6 +371,7 @@ function test_https_url_without_ssl_verification() {
remove_filter( 'http_request_args', array( $this, 'filter_http_request_args' ) );
$this->skipTestOnTimeout( $res );
$this->assertNotEmpty( $this->http_request_args['sslcertificates'] );
$this->assertNotWPError( $res );
}
@@ -356,10 +385,13 @@ function test_multiple_location_headers() {
$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 ) );
}
@@ -373,6 +405,8 @@ function test_cookie_handling() {
$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 ) );
}
@@ -387,6 +421,8 @@ function test_ssl() {
$this->fail( 'This installation of PHP does not support SSL' );
$res = wp_remote_get( 'https://wordpress.org/' );
$this->skipTestOnTimeout( $res );
$this->assertNotWPError( $res );
}
@@ -400,6 +436,8 @@ function test_url_with_double_slashes_path() {
$url = str_replace( $path, '/' . $path, $url );
$res = wp_remote_request( $url );
$this->skipTestOnTimeout( $res );
$this->assertNotWPError( $res );
}

0 comments on commit 9e8090f

Please sign in to comment.
You can’t perform that action at this time.