Currently, HTTP requests via simpletest change the user agent in order to hit the test database rather than the real database. In bootstrap.inc, a check is made to see if the stated request time of the request is within a five-second window, which seems reasonable for _single_ local requests.
However, certain modules, like the Selenium module, and Simpletest PhantomJS, on which I am currently working, attempt to leverage Drupal's Simpletest framework in order to parse Javascript, including Ajax calls.
How the Selenium project deals with the problem
The Selenium module, which integrates with Selenium to test code in real browsers, provides a patch to core which replaces the hard-coded 5 second window by a hard-coded 500-second window.
Example usage for Simpletest PhantomJS integration
PhantomJS is a so-called headless browser which can interpret Javascript. Let's say you have a module which defines a page which is modified by an Ajax call, this results to two http requests. If they happen to be in the same 5-second window, everything works. If the second call is outside the 5-second window, the main database is hit rather than the test database.
My idea is to provide a hook_init implementation within Simpletest PhantomJS to exit if the call to Simpletest is outside the 5-second window, but any test which takes more than 5 seconds will then break.
Proposed solution
Use 5 seconds a default behaviour, but allow site developers to add something like the following in their settings.php file:
$conf['simpletest_time_window'] = 500;
Comment | File | Size | Author |
---|---|---|---|
#3 | 2104139-3-core-8.x-simpletest-dont-hardcode-5-sec-window.patch | 2.47 KB | alberto56 |
#1 | 2104139-1-core-7.x-simpletest-dont-hardcode-5-sec-window.patch | 1.29 KB | alberto56 |
Comments
Comment #1
alberto56 CreditAttribution: alberto56 commentedHere's a first shot at a patch.
Comment #3
alberto56 CreditAttribution: alberto56 commentedHere is a version for 8.x
Comment #4
alberto56 CreditAttribution: alberto56 commentedComment #11
Anonymous (not verified) CreditAttribution: Anonymous commentedAfter #2771547: In Browser and FunctionalJavascript tests SIMPLETEST_USER_AGENT cookie needs to be set every 5 seconds we have:
So even though the value is still set hardly, it is changed in favor of what we want to get here. Maybe close this issue?
Comment #12
alberto56 CreditAttribution: alberto56 at Dcycle commentedRight, this seems fixed to me, thanks!