Make WordPress Core

Changeset 43695


Ignore:
Timestamp:
10/11/2018 03:17:44 AM (6 years ago)
Author:
SergeyBiryukov
Message:

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".

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

Location:
branches/5.0
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/5.0

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

    r41289 r43695  
    2929        }
    3030
    31         if ( 0 === strpos( $response->get_error_message(), 'Operation timed out after' ) ){
     31        if ( false !== strpos( $response->get_error_message(), 'timed out after' ) ) {
    3232            $this->markTestSkipped( 'HTTP timeout' );
    3333        }
     
    7474        // 5 : 5 & 301
    7575        $res = wp_remote_request($this->redirection_script . '?code=301&rt=' . 5, array('redirection' => 5) );
     76
     77        $this->skipTestOnTimeout( $res );
    7678        $this->assertNotWPError( $res );
    7779        $this->assertEquals(200, (int)$res['response']['code'] );
     
    8183        // 5 : 5 & 302
    8284        $res = wp_remote_request($this->redirection_script . '?code=302&rt=' . 5, array('redirection' => 5) );
     85
     86        $this->skipTestOnTimeout( $res );
    8387        $this->assertNotWPError( $res );
    8488        $this->assertEquals(200, (int)$res['response']['code'] );
     
    9195        // 5 > 0 & 301
    9296        $res = wp_remote_request($this->redirection_script . '?code=301&rt=' . 5, array('redirection' => 0) );
     97
     98        $this->skipTestOnTimeout( $res );
    9399        $this->assertNotWPError( $res );
    94100        $this->assertEquals(301, (int)$res['response']['code'] );
     
    101107        // 5 > 0 & 302
    102108        $res = wp_remote_request($this->redirection_script . '?code=302&rt=' . 5, array('redirection' => 0) );
     109
     110        $this->skipTestOnTimeout( $res );
    103111        $this->assertNotWPError( $res );
    104112        $this->assertEquals(302, (int)$res['response']['code'] );
     
    108116        // 5 - 5
    109117        $res = wp_remote_request($this->redirection_script . '?rt=' . 5, array('redirection' => 5) );
     118
     119        $this->skipTestOnTimeout( $res );
    110120        $this->assertNotWPError( $res );
    111121        $this->assertEquals(200, (int)$res['response']['code'] );
     
    115125        // No redirections on HEAD request:
    116126        $res = wp_remote_request($this->redirection_script . '?code=302&rt=' . 1, array('method' => 'HEAD') );
     127
     128        $this->skipTestOnTimeout( $res );
    117129        $this->assertNotWPError( $res );
    118130        $this->assertEquals( 302, (int)$res['response']['code'] );
     
    125137        // Redirections on HEAD request when Requested
    126138        $res = wp_remote_request($this->redirection_script . '?rt=' . 5, array('redirection' => 5, 'method' => 'HEAD') );
     139
     140        $this->skipTestOnTimeout( $res );
    127141        $this->assertNotWPError( $res );
    128142        $this->assertEquals( 200, (int)$res['response']['code'] );
     
    132146        // 10 > 5
    133147        $res = wp_remote_request($this->redirection_script . '?rt=' . 10, array('redirection' => 5) );
     148
     149        $this->skipTestOnTimeout( $res );
    134150        $this->assertWPError( $res );
    135151    }
     
    138154        // 6 > 5 (close edgecase)
    139155        $res = wp_remote_request($this->redirection_script . '?rt=' . 6, array('redirection' => 5) );
     156
     157        $this->skipTestOnTimeout( $res );
    140158        $this->assertWPError( $res );
    141159    }
     
    144162        // 4 < 5 (close edgecase)
    145163        $res = wp_remote_request($this->redirection_script . '?rt=' . 4, array('redirection' => 5) );
     164
     165        $this->skipTestOnTimeout( $res );
    146166        $this->assertNotWPError( $res );
    147167    }
     
    153173        // 0 redirections asked for, Should return the document?
    154174        $res = wp_remote_request($this->redirection_script . '?code=302&rt=' . 5, array('redirection' => 0) );
     175
     176        $this->skipTestOnTimeout( $res );
    155177        $this->assertNotWPError( $res );
    156178        $this->assertEquals( 302, (int)$res['response']['code'] );
     
    165187        // Prints PASS on initial load, FAIL if the client follows the specified redirection
    166188        $res = wp_remote_request( $this->redirection_script . '?201-location=true' );
     189
     190        $this->skipTestOnTimeout( $res );
    167191        $this->assertNotWPError( $res );
    168192        $this->assertEquals( 'PASS', $res['body']);
     
    179203        // Test 301 - POST to POST
    180204        $res = wp_remote_request( $url, array( 'method' => 'PUT', 'timeout' => 30 ) );
     205
     206        $this->skipTestOnTimeout( $res );
    181207        $this->assertEquals( 'PASS', wp_remote_retrieve_body( $res ) );
    182208        $this->assertTrue( !empty( $res['headers']['location'] ) );
     
    191217        $res = wp_remote_request( $this->redirection_script . '?header-check', array('headers' => $headers) );
    192218
     219        $this->skipTestOnTimeout( $res );
    193220        $this->assertNotWPError( $res );
    194221
     
    221248
    222249        $this->skipTestOnTimeout( $res );
    223 
    224250        $this->assertNotWPError( $res );
    225251        $this->assertEquals( '', $res['body'] ); // The body should be empty.
     
    244270
    245271        $this->skipTestOnTimeout( $res );
    246 
    247272        $this->assertNotWPError( $res );
    248273        $this->assertEquals( $size, $filesize ); // Check that the file is written to disk correctly without any extra characters
     
    262287
    263288        $this->skipTestOnTimeout( $res );
    264 
    265289        $this->assertNotWPError( $res );
    266290        $this->assertEquals( $size, strlen( $res['body'] ) );
     
    278302
    279303        $res = wp_remote_post( add_query_arg( 'response_code', $response_code, $url ), array( 'timeout' => 30 ) );
     304
     305        $this->skipTestOnTimeout( $res );
    280306        $this->assertEquals( $method, wp_remote_retrieve_body( $res ) );
    281307    }
     
    323349
    324350        $res = wp_remote_get( $url, $args );
     351
     352        $this->skipTestOnTimeout( $res );
    325353        $this->assertEquals( 'PASS', wp_remote_retrieve_body( $res ) );
    326354
     
    344372        remove_filter( 'http_request_args', array( $this, 'filter_http_request_args' ) );
    345373
     374        $this->skipTestOnTimeout( $res );
    346375        $this->assertNotEmpty( $this->http_request_args['sslcertificates'] );
    347376        $this->assertNotWPError( $res );
     
    357386        $res = wp_remote_head( $url, array( 'timeout' => 30 ) );
    358387
     388        $this->skipTestOnTimeout( $res );
    359389        $this->assertInternalType( 'array', wp_remote_retrieve_header( $res, 'location' ) );
    360390        $this->assertCount( 2, wp_remote_retrieve_header( $res, 'location' ) );
    361391
    362392        $res = wp_remote_get( $url, array( 'timeout' => 30 ) );
     393
     394        $this->skipTestOnTimeout( $res );
    363395        $this->assertEquals( 'PASS', wp_remote_retrieve_body( $res ) );
    364396
     
    374406
    375407        $res = wp_remote_get( $url );
     408
     409        $this->skipTestOnTimeout( $res );
    376410        $this->assertEquals( 'PASS', wp_remote_retrieve_body( $res ) );
    377411    }
     
    388422
    389423        $res = wp_remote_get( 'https://wordpress.org/' );
     424
     425        $this->skipTestOnTimeout( $res );
    390426        $this->assertNotWPError( $res );
    391427    }
     
    401437
    402438        $res = wp_remote_request( $url );
     439
     440        $this->skipTestOnTimeout( $res );
    403441        $this->assertNotWPError( $res );
    404442    }
Note: See TracChangeset for help on using the changeset viewer.