Make WordPress Core


Ignore:
Timestamp:
01/30/2021 09:01:52 PM (5 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.1 branch.
See #51669.

Location:
branches/4.1
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/4.1

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

    r42064 r50103  
    9999            $this->markTestSkipped( 'For automated test runs, this test is only run on trunk/master' );
    100100        }
     101    }
     102
     103    /**
     104     * Allow tests to be skipped if the HTTP request times out.
     105     *
     106     * @param array|WP_Error $response HTTP response.
     107     */
     108    public function skipTestOnTimeout( $response ) {
     109        if ( ! is_wp_error( $response ) ) {
     110            return;
     111        }
     112        if ( 'connect() timed out!' === $response->get_error_message() ) {
     113            $this->markTestSkipped( 'HTTP timeout' );
     114        }
     115
     116        if ( false !== strpos( $response->get_error_message(), 'timed out after' ) ) {
     117            $this->markTestSkipped( 'HTTP timeout' );
     118        }
     119
     120        if ( 0 === strpos( $response->get_error_message(), 'stream_socket_client(): unable to connect to tcp://s.w.org:80' ) ) {
     121            $this->markTestSkipped( 'HTTP timeout' );
     122        }
     123
    101124    }
    102125
Note: See TracChangeset for help on using the changeset viewer.