Make WordPress Core


Ignore:
Timestamp:
01/30/2021 08:45:47 PM (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 [38757], [43511], [43512], [46682], [46996] to the 4.3 branch.
See #51669.

Location:
branches/4.3
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/4.3

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

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