Make WordPress Core


Ignore:
Timestamp:
01/30/2021 11:29:34 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.7 branch.
See #51669.

Location:
branches/4.7
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/4.7

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

    r41305 r50088  
    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
     
    233233            _unregister_post_status( $post_status );
    234234        }
     235    }
     236
     237    /**
     238     * Allow tests to be skipped if the HTTP request times out.
     239     *
     240     * @param array|WP_Error $response HTTP response.
     241     */
     242    public function skipTestOnTimeout( $response ) {
     243        if ( ! is_wp_error( $response ) ) {
     244            return;
     245        }
     246        if ( 'connect() timed out!' === $response->get_error_message() ) {
     247            $this->markTestSkipped( 'HTTP timeout' );
     248        }
     249
     250        if ( false !== strpos( $response->get_error_message(), 'timed out after' ) ) {
     251            $this->markTestSkipped( 'HTTP timeout' );
     252        }
     253
     254        if ( 0 === strpos( $response->get_error_message(), 'stream_socket_client(): unable to connect to tcp://s.w.org:80' ) ) {
     255            $this->markTestSkipped( 'HTTP timeout' );
     256        }
     257
    235258    }
    236259
Note: See TracChangeset for help on using the changeset viewer.