Make WordPress Core


Ignore:
Timestamp:
01/30/2021 08:46:48 PM (3 years ago)
Author:
SergeyBiryukov
Message:

Tests: Use skipTestOnTimeout() in more HTTP tests.

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

Merges [38757], [43511], [43512], [46682], [46996] to the 4.2 branch.
See #51669.

Location:
branches/4.2
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/4.2

  • branches/4.2/tests/phpunit/tests/http/base.php

    r31290 r50102  
    4545        // 5 : 5 & 301
    4646        $res = wp_remote_request($this->redirection_script . '?code=301&rt=' . 5, array('redirection' => 5) );
     47
     48        $this->skipTestOnTimeout( $res );
    4749        $this->assertFalse( is_wp_error($res) );
    4850        $this->assertEquals(200, (int)$res['response']['code'] );
     
    5254        // 5 : 5 & 302
    5355        $res = wp_remote_request($this->redirection_script . '?code=302&rt=' . 5, array('redirection' => 5) );
     56
     57        $this->skipTestOnTimeout( $res );
    5458        $this->assertFalse( is_wp_error($res) );
    5559        $this->assertEquals(200, (int)$res['response']['code'] );
     
    6266        // 5 > 0 & 301
    6367        $res = wp_remote_request($this->redirection_script . '?code=301&rt=' . 5, array('redirection' => 0) );
     68
     69        $this->skipTestOnTimeout( $res );
    6470        $this->assertFalse( is_wp_error($res) );
    6571        $this->assertEquals(301, (int)$res['response']['code'] );
     
    7278        // 5 > 0 & 302
    7379        $res = wp_remote_request($this->redirection_script . '?code=302&rt=' . 5, array('redirection' => 0) );
     80
     81        $this->skipTestOnTimeout( $res );
    7482        $this->assertFalse( is_wp_error($res) );
    7583        $this->assertEquals(302, (int)$res['response']['code'] );
     
    7987        // 5 - 5
    8088        $res = wp_remote_request($this->redirection_script . '?rt=' . 5, array('redirection' => 5) );
     89
     90        $this->skipTestOnTimeout( $res );
    8191        $this->assertFalse( is_wp_error($res) );
    8292        $this->assertEquals(200, (int)$res['response']['code'] );
     
    8696        // No redirections on HEAD request:
    8797        $res = wp_remote_request($this->redirection_script . '?code=302&rt=' . 1, array('method' => 'HEAD') );
     98
     99        $this->skipTestOnTimeout( $res );
    88100        $this->assertFalse( is_wp_error($res) );
    89101        $this->assertEquals( 302, (int)$res['response']['code'] );
     
    96108        // Redirections on HEAD request when Requested
    97109        $res = wp_remote_request($this->redirection_script . '?rt=' . 5, array('redirection' => 5, 'method' => 'HEAD') );
     110
     111        $this->skipTestOnTimeout( $res );
    98112        $this->assertFalse( is_wp_error($res) );
    99113        $this->assertEquals( 200, (int)$res['response']['code'] );
     
    103117        // 10 > 5
    104118        $res = wp_remote_request($this->redirection_script . '?rt=' . 10, array('redirection' => 5) );
     119
     120        $this->skipTestOnTimeout( $res );
    105121        $this->assertTrue( is_wp_error($res), print_r($res, true) );
    106122    }
     
    109125        // 6 > 5 (close edgecase)
    110126        $res = wp_remote_request($this->redirection_script . '?rt=' . 6, array('redirection' => 5) );
     127
     128        $this->skipTestOnTimeout( $res );
    111129        $this->assertTrue( is_wp_error($res) );
    112130    }
     
    115133        // 4 < 5 (close edgecase)
    116134        $res = wp_remote_request($this->redirection_script . '?rt=' . 4, array('redirection' => 5) );
     135
     136        $this->skipTestOnTimeout( $res );
    117137        $this->assertFalse( is_wp_error($res) );
    118138    }
     
    124144        // 0 redirections asked for, Should return the document?
    125145        $res = wp_remote_request($this->redirection_script . '?code=302&rt=' . 5, array('redirection' => 0) );
     146
     147        $this->skipTestOnTimeout( $res );
    126148        $this->assertFalse( is_wp_error($res) );
    127149        $this->assertEquals( 302, (int)$res['response']['code'] );
     
    136158        // Prints PASS on initial load, FAIL if the client follows the specified redirection
    137159        $res = wp_remote_request( $this->redirection_script . '?201-location=true' );
     160
     161        $this->skipTestOnTimeout( $res );
    138162        $this->assertFalse( is_wp_error( $res ) );
    139163        $this->assertEquals( 'PASS', $res['body']);
     
    150174        // Test 301 - POST to POST
    151175        $res = wp_remote_request( $url, array( 'method' => 'PUT', 'timeout' => 30 ) );
     176
     177        $this->skipTestOnTimeout( $res );
    152178        $this->assertEquals( 'PASS', wp_remote_retrieve_body( $res ) );
    153179        $this->assertTrue( !empty( $res['headers']['location'] ) );
     
    162188        $res = wp_remote_request( $this->redirection_script . '?header-check', array('headers' => $headers) );
    163189
     190        $this->skipTestOnTimeout( $res );
    164191        $this->assertFalse( is_wp_error($res) );
    165192
     
    189216            $filesize = filesize( $res['filename'] );
    190217            unlink( $res['filename'] );
    191         }       
    192 
     218        }
     219
     220        $this->skipTestOnTimeout( $res );
    193221        $this->assertFalse( is_wp_error( $res ) );
    194222        $this->assertEquals( '', $res['body'] ); // The body should be empty.
     
    211239        }
    212240
     241        $this->skipTestOnTimeout( $res );
    213242        $this->assertFalse( is_wp_error( $res ) );
    214243        $this->assertEquals( $size, $filesize ); // Check that the file is written to disk correctly without any extra characters
     
    228257        $res = wp_remote_request( $url, array( 'timeout' => 30, 'limit_response_size' => $size ) );
    229258
     259        $this->skipTestOnTimeout( $res );
    230260        $this->assertFalse( is_wp_error( $res ) );
    231261        $this->assertEquals( $size, strlen( $res['body'] ) );
     
    235265     * Test POST redirection methods
    236266     *
     267     * @dataProvider data_post_redirect_to_method_300
     268     *
    237269     * @ticket 17588
    238270     */
    239     function test_post_redirect_to_method_300() {
     271    function test_post_redirect_to_method_300( $response_code, $method ) {
    240272        $url = 'http://api.wordpress.org/core/tests/1.0/redirection.php?post-redirect-to-method=1';
    241273
    242         // Test 300 - POST to POST
    243         $res = wp_remote_post( add_query_arg( 'response_code', 300, $url ), array( 'timeout' => 30 ) );
    244         $this->assertEquals( 'POST', wp_remote_retrieve_body( $res ) );
    245 
    246         // Test 301 - POST to POST
    247         $res = wp_remote_post( add_query_arg( 'response_code', 301, $url ), array( 'timeout' => 30 ) );
    248         $this->assertEquals( 'POST', wp_remote_retrieve_body( $res ) );
    249 
    250         // Test 302 - POST to GET
    251         $res = wp_remote_post( add_query_arg( 'response_code', 302, $url ), array( 'timeout' => 30 ) );
    252         $this->assertEquals( 'GET', wp_remote_retrieve_body( $res ) );
    253 
    254         // Test 303 - POST to GET
    255         $res = wp_remote_post( add_query_arg( 'response_code', 303, $url ), array( 'timeout' => 30 ) );
    256         $this->assertEquals( 'GET', wp_remote_retrieve_body( $res ) );
    257 
    258         // Test 304 - POST to POST
    259         $res = wp_remote_post( add_query_arg( 'response_code', 304, $url ), array( 'timeout' => 30 ) );
    260         $this->assertEquals( 'POST', wp_remote_retrieve_body( $res ) );
     274        $res = wp_remote_post( add_query_arg( 'response_code', $response_code, $url ), array( 'timeout' => 30 ) );
     275
     276        $this->skipTestOnTimeout( $res );
     277        $this->assertEquals( $method, wp_remote_retrieve_body( $res ) );
     278    }
     279
     280    public function data_post_redirect_to_method_300() {
     281        return array(
     282            // Test 300 - POST to POST
     283            array(
     284                300,
     285                'POST',
     286            ),
     287            // Test 301 - POST to POST
     288            array(
     289                301,
     290                'POST',
     291            ),
     292            // Test 302 - POST to GET
     293            array(
     294                302,
     295                'GET',
     296            ),
     297            // Test 303 - POST to GET
     298            array(
     299                303,
     300                'GET',
     301            ),
     302            // Test 304 - POST to POST
     303            array(
     304                304,
     305                'POST',
     306            ),
     307        );
    261308    }
    262309
     
    278325
    279326        $res = wp_remote_get( $url, $args );
     327
     328        $this->skipTestOnTimeout( $res );
    280329        $this->assertEquals( 'PASS', wp_remote_retrieve_body( $res ) );
    281330
     
    291340        $res = wp_remote_head( $url, array( 'timeout' => 30 ) );
    292341
     342        $this->skipTestOnTimeout( $res );
    293343        $this->assertInternalType( 'array', wp_remote_retrieve_header( $res, 'location' ) );
    294344        $this->assertCount( 2, wp_remote_retrieve_header( $res, 'location' ) );
    295345
    296346        $res = wp_remote_get( $url, array( 'timeout' => 30 ) );
     347
     348        $this->skipTestOnTimeout( $res );
    297349        $this->assertEquals( 'PASS', wp_remote_retrieve_body( $res ) );
    298350
     
    308360
    309361        $res = wp_remote_get( $url );
     362
     363        $this->skipTestOnTimeout( $res );
    310364        $this->assertEquals( 'PASS', wp_remote_retrieve_body( $res ) );
    311365    }
     
    322376
    323377        $res = wp_remote_get( 'https://wordpress.org/' );
     378
     379        $this->skipTestOnTimeout( $res );
    324380        $this->assertTrue( ! is_wp_error( $res ), print_r( $res, true ) );
    325381    }
Note: See TracChangeset for help on using the changeset viewer.