Skip to content

Commit

Permalink
Timeout test
Browse files Browse the repository at this point in the history
  • Loading branch information
ozh committed Jan 24, 2014
1 parent 0c6a797 commit 247a225
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions library/Requests/Transport/fsockopen.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,8 @@ public function request($url, $headers = array(), $data = array(), $options = ar
$options['hooks']->dispatch('fsockopen.after_request', array(&$fake_headers));
return '';
}
$timeout_sec = (int) floor( $options['timeout'] );

$timeout_sec = (int) floor( $options['timeout'] );
$timeout_msec = $timeout_sec == $options['timeout'] ? 0 : 1000000 * $options['timeout'] % 1000000;
stream_set_timeout( $fp, $timeout_sec, $timeout_msec );

Expand Down
8 changes: 8 additions & 0 deletions tests/Requests.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,12 @@ public function test30xWithoutLocation() {
$this->assertEquals(302, $response->status_code);
$this->assertEquals(0, $response->redirects);
}

/**
* @expectedException Requests_Exception
*/
public function testTimeoutException() {
$options = array('timeout' => 0.5);
$response = Requests::get('http://httpbin.org/delay/3', array(), $options);
}
}

0 comments on commit 247a225

Please sign in to comment.