Make WordPress Core

Changeset 34848


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

Location:
trunk/tests/phpunit
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/includes/bootstrap.php

    r34172 r34848  
    165165            echo sprintf( 'Not running %1$s tests. To execute these, use --group %1$s.', $group_name ) . PHP_EOL;
    166166        }
     167
     168        if ( ! isset( $skipped_groups['external-http'] ) ){
     169            echo PHP_EOL;
     170            echo 'External HTTP skipped tests can be caused by timeouts.' . PHP_EOL;
     171            echo 'If this changeset inclues changes to HTTP, make sure there are no timeouts.' . PHP_EOL;
     172            echo PHP_EOL;
     173        }
    167174    }
    168175}
  • 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.