Make WordPress Core


Ignore:
Timestamp:
07/19/2018 07:09:56 PM (6 years ago)
Author:
SergeyBiryukov
Message:

Tests: Use WP_HTTP_UnitTestCase::skipTestOnTimeout() in more HTTP tests.

Adjust it to handle more types of timeouts, e.g. "Resolving timed out", "Connection timed out".

See #44613.

File:
1 edited

Legend:

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

    r42343 r43511  
    2929        }
    3030
    31         if ( 0 === strpos( $response->get_error_message(), 'Operation timed out after' ) ) {
     31        if ( false !== strpos( $response->get_error_message(), 'timed out after' ) ) {
    3232            $this->markTestSkipped( 'HTTP timeout' );
    3333        }
     
    7575        // 5 : 5 & 301
    7676        $res = wp_remote_request( $this->redirection_script . '?code=301&rt=' . 5, array( 'redirection' => 5 ) );
     77
     78        $this->skipTestOnTimeout( $res );
    7779        $this->assertNotWPError( $res );
    7880        $this->assertEquals( 200, (int) $res['response']['code'] );
     
    8284        // 5 : 5 & 302
    8385        $res = wp_remote_request( $this->redirection_script . '?code=302&rt=' . 5, array( 'redirection' => 5 ) );
     86
     87        $this->skipTestOnTimeout( $res );
    8488        $this->assertNotWPError( $res );
    8589        $this->assertEquals( 200, (int) $res['response']['code'] );
     
    9296        // 5 > 0 & 301
    9397        $res = wp_remote_request( $this->redirection_script . '?code=301&rt=' . 5, array( 'redirection' => 0 ) );
     98
     99        $this->skipTestOnTimeout( $res );
    94100        $this->assertNotWPError( $res );
    95101        $this->assertEquals( 301, (int) $res['response']['code'] );
     
    102108        // 5 > 0 & 302
    103109        $res = wp_remote_request( $this->redirection_script . '?code=302&rt=' . 5, array( 'redirection' => 0 ) );
     110
     111        $this->skipTestOnTimeout( $res );
    104112        $this->assertNotWPError( $res );
    105113        $this->assertEquals( 302, (int) $res['response']['code'] );
     
    109117        // 5 - 5
    110118        $res = wp_remote_request( $this->redirection_script . '?rt=' . 5, array( 'redirection' => 5 ) );
     119
     120        $this->skipTestOnTimeout( $res );
    111121        $this->assertNotWPError( $res );
    112122        $this->assertEquals( 200, (int) $res['response']['code'] );
     
    116126        // No redirections on HEAD request:
    117127        $res = wp_remote_request( $this->redirection_script . '?code=302&rt=' . 1, array( 'method' => 'HEAD' ) );
     128
     129        $this->skipTestOnTimeout( $res );
    118130        $this->assertNotWPError( $res );
    119131        $this->assertEquals( 302, (int) $res['response']['code'] );
     
    131143            )
    132144        );
     145
     146        $this->skipTestOnTimeout( $res );
    133147        $this->assertNotWPError( $res );
    134148        $this->assertEquals( 200, (int) $res['response']['code'] );
     
    138152        // 10 > 5
    139153        $res = wp_remote_request( $this->redirection_script . '?rt=' . 10, array( 'redirection' => 5 ) );
     154
     155        $this->skipTestOnTimeout( $res );
    140156        $this->assertWPError( $res );
    141157    }
     
    144160        // 6 > 5 (close edgecase)
    145161        $res = wp_remote_request( $this->redirection_script . '?rt=' . 6, array( 'redirection' => 5 ) );
     162
     163        $this->skipTestOnTimeout( $res );
    146164        $this->assertWPError( $res );
    147165    }
     
    150168        // 4 < 5 (close edgecase)
    151169        $res = wp_remote_request( $this->redirection_script . '?rt=' . 4, array( 'redirection' => 5 ) );
     170
     171        $this->skipTestOnTimeout( $res );
    152172        $this->assertNotWPError( $res );
    153173    }
     
    159179        // 0 redirections asked for, Should return the document?
    160180        $res = wp_remote_request( $this->redirection_script . '?code=302&rt=' . 5, array( 'redirection' => 0 ) );
     181
     182        $this->skipTestOnTimeout( $res );
    161183        $this->assertNotWPError( $res );
    162184        $this->assertEquals( 302, (int) $res['response']['code'] );
     
    171193        // Prints PASS on initial load, FAIL if the client follows the specified redirection
    172194        $res = wp_remote_request( $this->redirection_script . '?201-location=true' );
     195
     196        $this->skipTestOnTimeout( $res );
    173197        $this->assertNotWPError( $res );
    174198        $this->assertEquals( 'PASS', $res['body'] );
     
    190214            )
    191215        );
     216
     217        $this->skipTestOnTimeout( $res );
    192218        $this->assertEquals( 'PASS', wp_remote_retrieve_body( $res ) );
    193219        $this->assertTrue( ! empty( $res['headers']['location'] ) );
     
    206232        $res     = wp_remote_request( $this->redirection_script . '?header-check', array( 'headers' => $headers ) );
    207233
     234        $this->skipTestOnTimeout( $res );
    208235        $this->assertNotWPError( $res );
    209236
     
    242269
    243270        $this->skipTestOnTimeout( $res );
    244 
    245271        $this->assertNotWPError( $res );
    246272        $this->assertEquals( '', $res['body'] ); // The body should be empty.
     
    271297
    272298        $this->skipTestOnTimeout( $res );
    273 
    274299        $this->assertNotWPError( $res );
    275300        $this->assertEquals( $size, $filesize ); // Check that the file is written to disk correctly without any extra characters
     
    294319
    295320        $this->skipTestOnTimeout( $res );
    296 
    297321        $this->assertNotWPError( $res );
    298322        $this->assertEquals( $size, strlen( $res['body'] ) );
     
    310334
    311335        $res = wp_remote_post( add_query_arg( 'response_code', $response_code, $url ), array( 'timeout' => 30 ) );
     336
     337        $this->skipTestOnTimeout( $res );
    312338        $this->assertEquals( $method, wp_remote_retrieve_body( $res ) );
    313339    }
     
    355381
    356382        $res = wp_remote_get( $url, $args );
     383
     384        $this->skipTestOnTimeout( $res );
    357385        $this->assertEquals( 'PASS', wp_remote_retrieve_body( $res ) );
    358386
     
    376404        remove_filter( 'http_request_args', array( $this, 'filter_http_request_args' ) );
    377405
     406        $this->skipTestOnTimeout( $res );
    378407        $this->assertNotEmpty( $this->http_request_args['sslcertificates'] );
    379408        $this->assertNotWPError( $res );
     
    389418        $res = wp_remote_head( $url, array( 'timeout' => 30 ) );
    390419
     420        $this->skipTestOnTimeout( $res );
    391421        $this->assertInternalType( 'array', wp_remote_retrieve_header( $res, 'location' ) );
    392422        $this->assertCount( 2, wp_remote_retrieve_header( $res, 'location' ) );
    393423
    394424        $res = wp_remote_get( $url, array( 'timeout' => 30 ) );
     425
     426        $this->skipTestOnTimeout( $res );
    395427        $this->assertEquals( 'PASS', wp_remote_retrieve_body( $res ) );
    396428
     
    406438
    407439        $res = wp_remote_get( $url );
     440
     441        $this->skipTestOnTimeout( $res );
    408442        $this->assertEquals( 'PASS', wp_remote_retrieve_body( $res ) );
    409443    }
     
    421455
    422456        $res = wp_remote_get( 'https://wordpress.org/' );
     457
     458        $this->skipTestOnTimeout( $res );
    423459        $this->assertNotWPError( $res );
    424460    }
     
    434470
    435471        $res = wp_remote_request( $url );
     472
     473        $this->skipTestOnTimeout( $res );
    436474        $this->assertNotWPError( $res );
    437475    }
Note: See TracChangeset for help on using the changeset viewer.