Make WordPress Core


Ignore:
Timestamp:
01/30/2021 09:28:27 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.9 branch.
See #51669.

Location:
branches/3.9
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/3.9

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

    r47490 r50106  
    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, $wp_query, $post;
     
    12799            $this->markTestSkipped( 'For automated test runs, this test is only run on trunk/master' );
    128100        }
     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
     124    }
     125
     126    /**
     127     * Unregister existing post types and register defaults.
     128     *
     129     * Run before each test in order to clean up the global scope, in case
     130     * a test forgets to unregister a post type on its own, or fails before
     131     * it has a chance to do so.
     132     */
     133    protected function reset_post_types() {
     134        foreach ( get_post_types() as $pt ) {
     135            _unregister_post_type( $pt );
     136        }
     137        create_initial_post_types();
     138    }
     139
     140    /**
     141     * Unregister existing taxonomies and register defaults.
     142     *
     143     * Run before each test in order to clean up the global scope, in case
     144     * a test forgets to unregister a taxonomy on its own, or fails before
     145     * it has a chance to do so.
     146     */
     147    protected function reset_taxonomies() {
     148        foreach ( get_taxonomies() as $tax ) {
     149            _unregister_taxonomy( $tax );
     150        }
     151        create_initial_taxonomies();
    129152    }
    130153
Note: See TracChangeset for help on using the changeset viewer.