Make WordPress Core


Ignore:
Timestamp:
01/30/2021 08:45:47 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] to the 4.3 branch.
See #51669.

Location:
branches/4.3
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/4.3

  • branches/4.3/tests/phpunit/tests/http/functions.php

    r31258 r50101  
    1818        $url = 'https://asdftestblog1.files.wordpress.com/2007/09/2007-06-30-dsc_4700-1.jpg';
    1919        $response = wp_remote_head( $url );
     20
     21        $this->skipTestOnTimeout( $response );
     22
    2023        $headers = wp_remote_retrieve_headers( $response );
    2124
     
    3033        $url = 'https://asdftestblog1.wordpress.com/files/2007/09/2007-06-30-dsc_4700-1.jpg';
    3134        $response = wp_remote_head( $url );
     35
     36        $this->skipTestOnTimeout( $response );
    3237        $this->assertEquals( '301', wp_remote_retrieve_response_code( $response ) );
    3338    }
     
    3540    function test_head_404() {
    3641        $url = 'https://asdftestblog1.files.wordpress.com/2007/09/awefasdfawef.jpg';
    37         $headers = wp_remote_head( $url );
     42        $response = wp_remote_head( $url );
    3843
    39         $this->assertInternalType( 'array', $headers, "Reply wasn't array." );
    40         $this->assertEquals( '404', wp_remote_retrieve_response_code( $headers ) );
     44        $this->skipTestOnTimeout( $response );
     45        $this->assertInternalType( 'array', $response, "Reply wasn't array." );
     46        $this->assertEquals( '404', wp_remote_retrieve_response_code( $response ) );
    4147    }
    4248
    4349    function test_get_request() {
    4450        $url = 'https://asdftestblog1.files.wordpress.com/2007/09/2007-06-30-dsc_4700-1.jpg';
    45         $file = tempnam('/tmp', 'testfile');
    4651
    47         $headers = wp_get_http($url, $file);
     52        $response = wp_remote_get( $url );
     53
     54        $this->skipTestOnTimeout( $response );
     55
     56        $headers = wp_remote_retrieve_headers( $response );
    4857
    4958        // should return the same headers as a head request
     
    5160        $this->assertEquals( 'image/jpeg', $headers['content-type'] );
    5261        $this->assertEquals( '40148', $headers['content-length'] );
    53         $this->assertEquals( '200', $headers['response'] );
    54 
    55         // make sure the file is ok
    56         $this->assertEquals( 40148, filesize($file) );
    57         $this->assertEquals( 'b0371a0fc575fcf77f62cd298571f53b', md5_file($file) );
     62        $this->assertEquals( '200', wp_remote_retrieve_response_code( $response ) );
    5863    }
    5964
     
    6166        // this will redirect to asdftestblog1.files.wordpress.com
    6267        $url = 'https://asdftestblog1.wordpress.com/files/2007/09/2007-06-30-dsc_4700-1.jpg';
    63         $file = tempnam('/tmp', 'testfile');
    6468
    65         $headers = wp_get_http($url, $file);
     69        $response = wp_remote_get( $url );
     70
     71        $this->skipTestOnTimeout( $response );
     72
     73        $headers = wp_remote_retrieve_headers( $response );
    6674
    6775        // should return the same headers as a head request
     
    6977        $this->assertEquals( 'image/jpeg', $headers['content-type'] );
    7078        $this->assertEquals( '40148', $headers['content-length'] );
    71         $this->assertEquals( '200', $headers['response'] );
    72 
    73         // make sure the file is ok
    74         $this->assertEquals( 40148, filesize($file) );
    75         $this->assertEquals( 'b0371a0fc575fcf77f62cd298571f53b', md5_file($file) );
     79        $this->assertEquals( '200', wp_remote_retrieve_response_code( $response ) );
    7680    }
    7781
     
    7983        // this will redirect to asdftestblog1.files.wordpress.com
    8084        $url = 'https://asdftestblog1.wordpress.com/files/2007/09/2007-06-30-dsc_4700-1.jpg';
    81         $file = tempnam('/tmp', 'testfile');
     85
    8286        // pretend we've already redirected 5 times
    83         $headers = wp_get_http( $url, $file, 6 );
    84         $this->assertFalse( $headers );
     87        $response = wp_remote_get( $url, array( 'redirection' => -1 ) );
     88
     89        $this->skipTestOnTimeout( $response );
     90        $this->assertTrue( is_wp_error( $response ) );
    8591    }
    8692}
Note: See TracChangeset for help on using the changeset viewer.