Make WordPress Core


Ignore:
Timestamp:
01/29/2025 06:17:34 PM (3 months ago)
Author:
johnbillion
Message:

Build/Test Tools: Add a retry mechanism for tests that perform external HTTP requests.

While the skipTestOnTimeout() method will catch a timeout and prevent it from causing a test to fail, other errors such as a failed DNS lookup or HTTPS handshake can still cause a test to unnecessarily fail. This introduces a simple retry mechanism that will hopefully further reduce the flakiness of tests that perform HTTP API requests.

Fixes #62830

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/http/functions.php

    r58108 r59729  
    1313        // This URL gives a direct 200 response.
    1414        $url      = 'https://s.w.org/screenshots/3.9/dashboard.png';
    15         $response = wp_remote_head( $url );
    16 
    17         $this->skipTestOnTimeout( $response );
     15        $response = $this->wp_remote_head( $url );
     16
    1817        $this->assertNotWPError( $response );
    1918
     
    3231        // This URL will 301 redirect.
    3332        $url      = 'https://wp.org/screenshots/3.9/dashboard.png';
    34         $response = wp_remote_head( $url );
    35 
    36         $this->skipTestOnTimeout( $response );
     33        $response = $this->wp_remote_head( $url );
     34
    3735        $this->assertNotWPError( $response );
    3836        $this->assertSame( 301, wp_remote_retrieve_response_code( $response ) );
     
    4442    public function test_head_404() {
    4543        $url      = 'https://wordpress.org/screenshots/3.9/awefasdfawef.jpg';
    46         $response = wp_remote_head( $url );
    47 
    48         $this->skipTestOnTimeout( $response );
     44        $response = $this->wp_remote_head( $url );
     45
    4946        $this->assertNotWPError( $response );
    5047        $this->assertSame( 404, wp_remote_retrieve_response_code( $response ) );
     
    5956        $url = 'https://s.w.org/screenshots/3.9/dashboard.png';
    6057
    61         $response = wp_remote_get( $url );
    62 
    63         $this->skipTestOnTimeout( $response );
     58        $response = $this->wp_remote_get( $url );
     59
    6460        $this->assertNotWPError( $response );
    6561
     
    8177        $url = 'https://wp.org/screenshots/3.9/dashboard.png';
    8278
    83         $response = wp_remote_get( $url );
    84 
    85         $this->skipTestOnTimeout( $response );
     79        $response = $this->wp_remote_get( $url );
     80
    8681        $this->assertNotWPError( $response );
    8782
     
    10297
    10398        // Pretend we've already redirected 5 times.
    104         $response = wp_remote_get( $url, array( 'redirection' => -1 ) );
    105 
    106         $this->skipTestOnTimeout( $response );
     99        $response = $this->wp_remote_get( $url, array( 'redirection' => -1 ) );
     100
    107101        $this->assertWPError( $response );
    108102    }
     
    119113        $url = 'https://login.wordpress.org/wp-login.php';
    120114
    121         $response = wp_remote_head( $url );
    122 
    123         $this->skipTestOnTimeout( $response );
     115        $response = $this->wp_remote_head( $url );
     116
    124117        $this->assertNotWPError( $response );
    125118
     
    153146        $url = 'https://login.wordpress.org/wp-login.php';
    154147
    155         $response = wp_remote_get(
     148        $response = $this->wp_remote_get(
    156149            $url,
    157150            array(
     
    167160        );
    168161
    169         $this->skipTestOnTimeout( $response );
    170162        $this->assertNotWPError( $response );
    171163
     
    190182        $url = 'https://login.wordpress.org/wp-login.php';
    191183
    192         $response = wp_remote_get(
     184        $response = $this->wp_remote_get(
    193185            $url,
    194186            array(
     
    199191        );
    200192
    201         $this->skipTestOnTimeout( $response );
    202193        $this->assertNotWPError( $response );
    203194
Note: See TracChangeset for help on using the changeset viewer.