I have a CRON job that tops up a huge cache table. Normally, it only updates a few records. But the first time it runs in a new installation, it has to load the entire table with thousands of requests to an external API. This gives SimpleTest a big overhead for any minor test in the module.

How can I skip or limit CRON when SimpleTest creates a new installation?


I assume that your module has some sort of variable to know how far back it needs to fetch data. You could initialize that in your setUp() method.

A module should not have to care if it is executed within a test or not. Instead, the test code should prepare the environment to whatever makes sense for the test.

If that for some reason doesn't work, you can add a variable_get() based check if it should fetch data or not. That might also be useful for local development, not just automated tests.

|improve this answer|||||
  • As far as I can tell, the only way is to write your own signal like this. – Joe Beuckman Apr 30 '12 at 19:44

I didn't find a way to know directly whether SimpleTest is running. For now, I am checking a role that the module creates for users. If there are no users of that role, I assume its SimpleTest running and limit my CRON.

|improve this answer|||||

This post is old, but for those who still search for an answer, here are the trick :

use the preloadRegistry method, and override the parent one, instead of using the setUp method. Because Drupalwebtestcase::setUp() is calling preloadRegistry before drupal_cron_run()

So, in your test class extending DrupalWebTestCase, add something like this for example

protected function preloadRegistry(){
  variable_set('activate_mymodule_cron', false);

Then in the hook_cron of your module : mymodule.module : mymodule_cron() add this :

$active_cron = variable_get('activate_mymodule_cron', true);
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.