diff options
author | Dries Buytaert <dries@buytaert.net> | 2009-06-06 15:43:05 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2009-06-06 15:43:05 +0000 |
commit | 36e3d552cfe211cba22d1fc8cf0a7f4b13627179 (patch) | |
tree | 2350df7fe55052c45329e3818ec77421669525f6 /modules | |
parent | e9f8dc82b0a33c9d8c5a78267f79762ff5d884da (diff) | |
download | brdo-36e3d552cfe211cba22d1fc8cf0a7f4b13627179.tar.gz brdo-36e3d552cfe211cba22d1fc8cf0a7f4b13627179.tar.bz2 |
- Patch #156582 by c960657, Damien Tournoud, townxelliot: added support for timeouts to drupal_http_request().
Diffstat (limited to 'modules')
-rw-r--r-- | modules/simpletest/tests/common.test | 13 | ||||
-rw-r--r-- | modules/simpletest/tests/system_test.module | 10 |
2 files changed, 23 insertions, 0 deletions
diff --git a/modules/simpletest/tests/common.test b/modules/simpletest/tests/common.test index 9b91d5775..6b767a527 100644 --- a/modules/simpletest/tests/common.test +++ b/modules/simpletest/tests/common.test @@ -309,6 +309,19 @@ class DrupalHTTPRequestTestCase extends DrupalWebTestCase { $this->assertTrue(!empty($result->protocol), t('Result protocol is returned.')); $this->assertEqual($result->code, '404', t('Result code is 404')); $this->assertEqual($result->status_message, 'Not Found', t('Result status message is "Not Found"')); + + // Test that timeout is respected. The test machine is expected to be able + // to make the connection (i.e. complete the fsockopen()) in 2 seconds and + // return within a total of 5 seconds. If the test machine is extremely + // slow, the test will fail. fsockopen() has been seen to time out in + // slightly less than the specified timeout, so allow a little slack on the + // minimum expected time (i.e. 1.8 instead of 2). + timer_start(__METHOD__); + $result = drupal_http_request(url('system-test/sleep/10', array('absolute' => TRUE)), array('timeout' => 2)); + $time = timer_read(__METHOD__) / 1000; + $this->assertTrue(1.8 < $time && $time < 5, t('Request timed out (%time seconds).', array('%time' => $time))); + $this->assertTrue($result->error, t('An error message was returned.')); + $this->assertEqual($result->code, HTTP_REQUEST_TIMEOUT, t('Proper error code was returned.')); } function testDrupalHTTPRequestBasicAuth() { diff --git a/modules/simpletest/tests/system_test.module b/modules/simpletest/tests/system_test.module index 432737f52..07a86afdb 100644 --- a/modules/simpletest/tests/system_test.module +++ b/modules/simpletest/tests/system_test.module @@ -5,6 +5,12 @@ * Implement hook_menu(). */ function system_test_menu() { + $items['system-test/sleep/%'] = array( + 'page callback' => 'system_test_sleep', + 'page arguments' => array(2), + 'access callback' => TRUE, + 'type' => MENU_CALLBACK, + ); $items['system-test/auth'] = array( 'page callback' => 'system_test_basic_auth_page', 'access callback' => TRUE, @@ -56,6 +62,10 @@ function system_test_menu() { return $items; } +function system_test_sleep($seconds) { + sleep($seconds); +} + function system_test_basic_auth_page() { $output = t('$_SERVER[\'PHP_AUTH_USER\'] is @username.', array('@username' => $_SERVER['PHP_AUTH_USER'])); $output .= t('$_SERVER[\'PHP_AUTH_PW\'] is @password.', array('@password' => $_SERVER['PHP_AUTH_PW'])); |