Make WordPress Core


Ignore:
Timestamp:
01/30/2021 09:29:39 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], [50105] to the 3.7 branch.
See #51669.

Location:
branches/3.7
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/3.7

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

    r47492 r50108  
    5555    }
    5656
    57     /**
    58      * Unregister existing post types and register defaults.
    59      *
    60      * Run before each test in order to clean up the global scope, in case
    61      * a test forgets to unregister a post type on its own, or fails before
    62      * it has a chance to do so.
    63      */
    64     protected function reset_post_types() {
    65         foreach ( get_post_types() as $pt ) {
    66             _unregister_post_type( $pt );
    67         }
    68         create_initial_post_types();
    69     }
    70 
    71     /**
    72      * Unregister existing taxonomies and register defaults.
    73      *
    74      * Run before each test in order to clean up the global scope, in case
    75      * a test forgets to unregister a taxonomy on its own, or fails before
    76      * it has a chance to do so.
    77      */
    78     protected function reset_taxonomies() {
    79         foreach ( get_taxonomies() as $tax ) {
    80             _unregister_taxonomy( $tax );
    81         }
    82         create_initial_taxonomies();
    83     }
    84 
    8557    function tearDown() {
    8658        global $wpdb;
     
    12496            $this->markTestSkipped( 'For automated test runs, this test is only run on trunk/master' );
    12597        }
     98    }
     99
     100    /**
     101     * Allow tests to be skipped if the HTTP request times out.
     102     *
     103     * @param array|WP_Error $response HTTP response.
     104     */
     105    public function skipTestOnTimeout( $response ) {
     106        if ( ! is_wp_error( $response ) ) {
     107            return;
     108        }
     109        if ( 'connect() timed out!' === $response->get_error_message() ) {
     110            $this->markTestSkipped( 'HTTP timeout' );
     111        }
     112
     113        if ( false !== strpos( $response->get_error_message(), 'timed out after' ) ) {
     114            $this->markTestSkipped( 'HTTP timeout' );
     115        }
     116
     117        if ( 0 === strpos( $response->get_error_message(), 'stream_socket_client(): unable to connect to tcp://s.w.org:80' ) ) {
     118            $this->markTestSkipped( 'HTTP timeout' );
     119        }
     120
     121    }
     122
     123    /**
     124     * Unregister existing post types and register defaults.
     125     *
     126     * Run before each test in order to clean up the global scope, in case
     127     * a test forgets to unregister a post type on its own, or fails before
     128     * it has a chance to do so.
     129     */
     130    protected function reset_post_types() {
     131        foreach ( get_post_types() as $pt ) {
     132            _unregister_post_type( $pt );
     133        }
     134        create_initial_post_types();
     135    }
     136
     137    /**
     138     * Unregister existing taxonomies and register defaults.
     139     *
     140     * Run before each test in order to clean up the global scope, in case
     141     * a test forgets to unregister a taxonomy on its own, or fails before
     142     * it has a chance to do so.
     143     */
     144    protected function reset_taxonomies() {
     145        foreach ( get_taxonomies() as $tax ) {
     146            _unregister_taxonomy( $tax );
     147        }
     148        create_initial_taxonomies();
    126149    }
    127150
Note: See TracChangeset for help on using the changeset viewer.