Make WordPress Core


Ignore:
Timestamp:
01/30/2021 09:03:08 PM (6 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.0 branch.
See #51669.

Location:
branches/4.0
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/4.0

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

    r47331 r50104  
    5353                $this->expectDeprecated();
    5454                add_filter( 'wp_die_handler', array( $this, 'get_wp_die_handler' ) );
     55        }
     56
     57        /**
     58         * Allow tests to be skipped if the HTTP request times out.
     59         *
     60         * @param array|WP_Error $response HTTP response.
     61         */
     62        public function skipTestOnTimeout( $response ) {
     63                if ( ! is_wp_error( $response ) ) {
     64                        return;
     65                }
     66                if ( 'connect() timed out!' === $response->get_error_message() ) {
     67                        $this->markTestSkipped( 'HTTP timeout' );
     68                }
     69
     70                if ( false !== strpos( $response->get_error_message(), 'timed out after' ) ) {
     71                        $this->markTestSkipped( 'HTTP timeout' );
     72                }
     73
     74                if ( 0 === strpos( $response->get_error_message(), 'stream_socket_client(): unable to connect to tcp://s.w.org:80' ) ) {
     75                        $this->markTestSkipped( 'HTTP timeout' );
     76                }
     77
    5578        }
    5679
Note: See TracChangeset for help on using the changeset viewer.