Make WordPress Core


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

Location:
branches/4.6
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/4.6

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

    r40249 r50089  
    163163
    164164    /**
    165      * Allow tests to be skipped on some automated runs
     165     * Allow tests to be skipped on some automated runs.
    166166     *
    167167     * For test runs on Travis for something other than trunk/master
     
    218218            _unregister_post_status( $post_status );
    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.