WordPress.org

Make WordPress Core

Changeset 50093


Ignore:
Timestamp:
01/30/2021 01:02:18 PM (8 months ago)
Author:
SergeyBiryukov
Message:

Tests: Skip test_readme() if the HTTP request to secure.php.net or dev.mysql.com failed on timeout.

Move skipTestOnTimeout() to WP_UnitTestCase_Base to avoid duplication.

Merges [46682] and [46996] to the 5.2 branch.
See #51669.

Location:
branches/5.2
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/5.2

  • branches/5.2/tests/phpunit/includes/abstract-testcase.php

    r44966 r50093  
    190190
    191191    /**
    192      * Allow tests to be skipped on some automated runs
     192     * Allow tests to be skipped on some automated runs.
    193193     *
    194194     * For test runs on Travis for something other than trunk/master
     
    230230            $this->markTestSkipped( 'Test does not run on Multisite' );
    231231        }
     232    }
     233
     234    /**
     235     * Allow tests to be skipped if the HTTP request times out.
     236     *
     237     * @param array|WP_Error $response HTTP response.
     238     */
     239    public function skipTestOnTimeout( $response ) {
     240        if ( ! is_wp_error( $response ) ) {
     241            return;
     242        }
     243        if ( 'connect() timed out!' === $response->get_error_message() ) {
     244            $this->markTestSkipped( 'HTTP timeout' );
     245        }
     246
     247        if ( false !== strpos( $response->get_error_message(), 'timed out after' ) ) {
     248            $this->markTestSkipped( 'HTTP timeout' );
     249        }
     250
     251        if ( 0 === strpos( $response->get_error_message(), 'stream_socket_client(): unable to connect to tcp://s.w.org:80' ) ) {
     252            $this->markTestSkipped( 'HTTP timeout' );
     253        }
     254
    232255    }
    233256
  • branches/5.2/tests/phpunit/tests/external-http/basic.php

    r40519 r50093  
    1414
    1515        $response = wp_remote_get( 'https://secure.php.net/supported-versions.php' );
    16         if ( 200 != wp_remote_retrieve_response_code( $response ) ) {
    17             $this->fail( 'Could not contact PHP.net to check versions.' );
     16
     17        $this->skipTestOnTimeout( $response );
     18
     19        $response_code = wp_remote_retrieve_response_code( $response );
     20        if ( 200 !== $response_code ) {
     21            $this->fail( sprintf( 'Could not contact PHP.net to check versions. Response code: %s', $response_code ) );
    1822        }
     23
    1924        $php = wp_remote_retrieve_body( $response );
    2025
     
    2631
    2732        $response = wp_remote_get( "https://dev.mysql.com/doc/relnotes/mysql/{$matches[1]}/en/" );
    28         if ( 200 != wp_remote_retrieve_response_code( $response ) ) {
    29             $this->fail( 'Could not contact dev.MySQL.com to check versions.' );
     33
     34        $this->skipTestOnTimeout( $response );
     35
     36        $response_code = wp_remote_retrieve_response_code( $response );
     37        if ( 200 !== $response_code ) {
     38            $this->fail( sprintf( 'Could not contact dev.MySQL.com to check versions. Response code: %s', $response_code ) );
    3039        }
     40
    3141        $mysql = wp_remote_retrieve_body( $response );
    3242
  • branches/5.2/tests/phpunit/tests/http/base.php

    r45035 r50093  
    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 ( false !== strpos( $response->get_error_message(), 'timed out after' ) ) {
    32             $this->markTestSkipped( 'HTTP timeout' );
    33         }
    34 
    35         if ( 0 === strpos( $response->get_error_message(), 'stream_socket_client(): unable to connect to tcp://s.w.org:80' ) ) {
    36             $this->markTestSkipped( 'HTTP timeout' );
    37         }
    38 
    39     }
    40 
    4120    function setUp() {
    4221        parent::setUp();
  • branches/5.2/tests/phpunit/tests/http/functions.php

    r45135 r50093  
    66 */
    77class Tests_HTTP_Functions extends WP_UnitTestCase {
    8 
    9     /**
    10      * Mark test as skipped if the HTTP request times out.
    11      */
    12     function skipTestOnTimeout( $response ) {
    13         if ( ! is_wp_error( $response ) ) {
    14             return;
    15         }
    16         if ( 'connect() timed out!' === $response->get_error_message() ) {
    17             $this->markTestSkipped( 'HTTP timeout' );
    18         }
    19 
    20         if ( false !== strpos( $response->get_error_message(), 'timed out after' ) ) {
    21             $this->markTestSkipped( 'HTTP timeout' );
    22         }
    23 
    24         if ( 0 === strpos( $response->get_error_message(), 'stream_socket_client(): unable to connect to tcp://s.w.org:80' ) ) {
    25             $this->markTestSkipped( 'HTTP timeout' );
    26         }
    27 
    28     }
    298
    309    public function setUp() {
Note: See TracChangeset for help on using the changeset viewer.