Make WordPress Core


Ignore:
Timestamp:
01/30/2021 11:13:04 AM (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 [43511], [43512], [46682], [46996] to the 4.8 branch.
See #51669.

Location:
branches/4.8
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/4.8

  • branches/4.8/tests/phpunit/includes/testcase.php

    r40875 r50087  
    178178
    179179    /**
    180      * Allow tests to be skipped on some automated runs
     180     * Allow tests to be skipped on some automated runs.
    181181     *
    182182     * For test runs on Travis for something other than trunk/master
     
    218218            $this->markTestSkipped( 'Test does not run on Multisite' );
    219219        }
     220    }
     221
     222    /**
     223     * Allow tests to be skipped if the HTTP request times out.
     224     *
     225     * @param array|WP_Error $response HTTP response.
     226     */
     227    public function skipTestOnTimeout( $response ) {
     228        if ( ! is_wp_error( $response ) ) {
     229            return;
     230        }
     231        if ( 'connect() timed out!' === $response->get_error_message() ) {
     232            $this->markTestSkipped( 'HTTP timeout' );
     233        }
     234
     235        if ( false !== strpos( $response->get_error_message(), 'timed out after' ) ) {
     236            $this->markTestSkipped( 'HTTP timeout' );
     237        }
     238
     239        if ( 0 === strpos( $response->get_error_message(), 'stream_socket_client(): unable to connect to tcp://s.w.org:80' ) ) {
     240            $this->markTestSkipped( 'HTTP timeout' );
     241        }
     242
    220243    }
    221244
Note: See TracChangeset for help on using the changeset viewer.