You are here

protected function DrupalWebTestCase::storeSetupCache in Drupal 7

Store the installation setup to a cache.

Parameters

string $cache_key_prefix: (optional) Additional prefix for the cache key.

Return value

bool TRUE if the installation was stored in the cache, FALSE otherwise.

1 call to DrupalWebTestCase::storeSetupCache()
DrupalWebTestCase::setUp in modules/simpletest/drupal_web_test_case.php
Sets up a Drupal site for running functional and integration tests.

File

modules/simpletest/drupal_web_test_case.php, line 1514

Class

DrupalWebTestCase
Test case for typical Drupal tests.

Code

protected function storeSetupCache($cache_key_prefix = '') {
  $cache_key = $this
    ->getSetupCacheKey($cache_key_prefix);
  $lock_key = 'simpletest_store_cache_' . $cache_key . '_' . $this->testId;

  // All concurrent tests share the same test id. Therefore it is possible to
  // use the lock to ensure that only one process will store the cache. This
  // is important as else DB tables created by one process could be deleted
  // by another as the cache copying is idempotent.
  if (!lock_acquire($lock_key)) {
    return FALSE;
  }

  // Try to copy the installation to the setup cache - now that we have a
  // lock to do so.
  if (!$this
    ->copySetupCache(substr($this->databasePrefix, 10), $cache_key)) {

    // It is non-fatal if the cache cannot be copied as the next test run
    // will try it again.
    $this
      ->assert('debug', t('Storing cache with key @key failed', array(
      '@key' => $cache_key,
    )), 'storeSetupCache');
    lock_release($lock_key);
    return FALSE;
  }

  // Inform others that this cache is usable now.
  $cache_file = $this->originalFileDirectory . '/simpletest/' . $cache_key . '/simpletest-cache-setup';
  file_put_contents($cache_file, time(NULL));
  lock_release($lock_key);
  return TRUE;
}