Make WordPress Core


Ignore:
Timestamp:
01/30/2021 08:46:48 PM (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.2 branch.
See #51669.

Location:
branches/4.2
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/4.2

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

    r40245 r50102  
    110110            $this->markTestSkipped( 'For automated test runs, this test is only run on trunk/master' );
    111111        }
     112    }
     113
     114    /**
     115     * Allow tests to be skipped if the HTTP request times out.
     116     *
     117     * @param array|WP_Error $response HTTP response.
     118     */
     119    public function skipTestOnTimeout( $response ) {
     120        if ( ! is_wp_error( $response ) ) {
     121            return;
     122        }
     123        if ( 'connect() timed out!' === $response->get_error_message() ) {
     124            $this->markTestSkipped( 'HTTP timeout' );
     125        }
     126
     127        if ( false !== strpos( $response->get_error_message(), 'timed out after' ) ) {
     128            $this->markTestSkipped( 'HTTP timeout' );
     129        }
     130
     131        if ( 0 === strpos( $response->get_error_message(), 'stream_socket_client(): unable to connect to tcp://s.w.org:80' ) ) {
     132            $this->markTestSkipped( 'HTTP timeout' );
     133        }
     134
    112135    }
    113136
Note: See TracChangeset for help on using the changeset viewer.