Make WordPress Core


Ignore:
Timestamp:
10/06/2015 03:36:18 AM (9 years ago)
Author:
jorbin
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/http/base.php

    r34646 r34848  
    1818    protected $http_request_args;
    1919
     20    /**
     21     * Mark test as skipped if the HTTP request times out
     22     */
     23    function skipTestOnTimeout( $response ) {
     24        if( ! is_wp_error( $response ) ){
     25            return;
     26        }
     27        if ( 'connect() timed out!' === $response->get_error_message() ){
     28            $this->markTestSkipped( 'HTTP timeout' );
     29        }
     30
     31        if ( 0 === strpos( $response->get_error_message(), 'Operation timed out after' ) ){
     32            $this->markTestSkipped( 'HTTP timeout' );
     33        }
     34
     35        if ( 'stream_socket_client(): unable to connect to tcp://s.w.org:80 (Connection timed out)' === $response->get_error_message() ){
     36            $this->markTestSkipped( 'HTTP timeout' );
     37        }
     38
     39    }
     40
    2041    function setUp() {
    2142
     
    199220        }
    200221
     222        $this->skipTestOnTimeout ($res );
     223
    201224        $this->assertNotWPError( $res );
    202225        $this->assertEquals( '', $res['body'] ); // The body should be empty.
     
    220243        }
    221244
     245        $this->skipTestOnTimeout ($res );
     246
    222247        $this->assertNotWPError( $res );
    223248        $this->assertEquals( $size, $filesize ); // Check that the file is written to disk correctly without any extra characters
     
    235260
    236261        $res = wp_remote_request( $url, array( 'timeout' => 30, 'limit_response_size' => $size ) );
     262
     263        $this->skipTestOnTimeout ($res );
    237264
    238265        $this->assertNotWPError( $res );
Note: See TracChangeset for help on using the changeset viewer.