Skip to content
Snippets Groups Projects
Commit 20b015e1 authored by totten's avatar totten
Browse files

CRM-12321 - SqlGroupTest - Test prefetching more directly.

When multi-tier caching was introduced, testPrefetch regressed because it
relied on side-effects from having totally independent caches -- but the
multi-tier cache added extra, unforeseen sharing between SqlGroup instances.
In reality, prefetching works. This revision tests prefetch more directly
to workaround the changed assumptions.

----------------------------------------
* CRM-12321: Multi-tier caching causes multiple test regressions
  http://issues.civicrm.org/jira/browse/CRM-12321
parent 710ca22d
No related branches found
No related tags found
No related merge requests found
......@@ -96,6 +96,10 @@ class CRM_Utils_Cache_SqlGroup implements CRM_Utils_Cache_Interface {
return $this->frontCache[$key];
}
function getFromFrontCache($key, $default = NULL) {
return CRM_Utils_Array::value($key, $this->frontCache, $default);
}
function delete($key) {
CRM_Core_BAO_Cache::deleteGroup($this->group, $key);
unset($this->frontCache[$key]);
......
......@@ -55,29 +55,33 @@ class CRM_Utils_Cache_SqlGroupTest extends CiviUnitTestCase {
}
/**
* Add item to one cache instance then read (and prefetch) with another
* Add item to one cache instance then read (with or without prefetch) from another
*/
function testPrefetch() {
// 1. put data in cache
$a = new CRM_Utils_Cache_SqlGroup(array(
'group' => 'testPrefetch',
'prefetch' => FALSE,
));
$fooValue = array('whiz' => 'bang', 'bar' => 4);
$a->set('foo', $fooValue);
$this->assertEquals($a->get('foo'), array('whiz' => 'bang', 'bar' => 4));
// 2. see what happens when prefetch is TRUE
$b = new CRM_Utils_Cache_SqlGroup(array(
'group' => 'testPrefetch',
'prefetch' => TRUE,
));
// assuming the values have been prefetched in $b, we can do a stale
// read -- i.e. change the underlying data table and then read the
// prefetched value from $b
$fooValue2 = 'muahahaha';
$a->set('foo', $fooValue2);
$this->assertEquals($b->get('foo'), array('whiz' => 'bang', 'bar' => 4));
// ok, enough with the stale reading
$b->prefetch();
$this->assertEquals($b->get('foo'), 'muahahaha');
$this->assertEquals($fooValue, $b->getFromFrontCache('foo')); // should work b/c value was prefetched
$this->assertEquals($fooValue, $b->get('foo')); // should work b/c value was prefetched
// 3. see what happens when prefetch is FALSE
$c = new CRM_Utils_Cache_SqlGroup(array(
'group' => 'testPrefetch',
'prefetch' => FALSE,
));
$this->assertEquals(NULL, $c->getFromFrontCache('foo')); // should be NULL b/c value was NOT prefetched
$this->assertEquals($fooValue, $c->get('foo')); // should work b/c value is fetched on demand
$this->assertEquals($fooValue, $c->getFromFrontCache('foo')); // should work b/c value was fetched on demand
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment