Created
April 7, 2013 18:54
-
-
Save Berdir/5331930 to your computer and use it in GitHub Desktop.
views data cache test comments
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/core/modules/views/lib/Drupal/views/Tests/ViewsDataTest.php b/core/modules/views/lib/Drupal/views/Tests/ViewsDataTest.php | |
index bd47a35..b434dc7 100644 | |
--- a/core/modules/views/lib/Drupal/views/Tests/ViewsDataTest.php | |
+++ b/core/modules/views/lib/Drupal/views/Tests/ViewsDataTest.php | |
@@ -133,31 +133,35 @@ public function testViewsFetchData() { | |
* Ensures that cache entries are only set and get when necessary. | |
*/ | |
public function testCache() { | |
- // Request the same table 5 times. | |
+ // Request the same table 5 times. The caches are empty at this point, so | |
+ // what will happen is that it will first check for a cache entry for the | |
+ // given table, get a cache miss, then try the cache entry for all tables, | |
+ // which does not exist yet either. As a result, it rebuilds the information | |
+ // and writes a cache entry for all tables and the requested table. | |
$table_name = 'views_test_data'; | |
for ($i = 0; $i < 5; $i++) { | |
$this->viewsDataCache->get($table_name); | |
} | |
- // Requesting the table did a full rebuild internally, so we have one cache | |
- // get for the table, one for the whole storage and we also write both. | |
- $this->assertEqual($this->memoryCounterBackend->getCounter('get', 'views_data:views_test_data:en'), 1); | |
- $this->assertEqual($this->memoryCounterBackend->getCounter('get', 'views_data:en'), 1); | |
- $this->assertEqual($this->memoryCounterBackend->getCounter('set', 'views_data:views_test_data:en'), 1); | |
- $this->assertEqual($this->memoryCounterBackend->getCounter('set', 'views_data:en'), 1); | |
+ // Assert cache set and get calls. | |
+ $this->assertEqual($this->memoryCounterBackend->getCounter('get', 'views_data:views_test_data:en'), 1, 'Requested the cache for the table-specific cache entry.'); | |
+ $this->assertEqual($this->memoryCounterBackend->getCounter('get', 'views_data:en'), 1, 'Requested the cache for all tables.'); | |
+ $this->assertEqual($this->memoryCounterBackend->getCounter('set', 'views_data:views_test_data:en'), 1, 'Wrote the cache for the requested once.'); | |
+ $this->assertEqual($this->memoryCounterBackend->getCounter('set', 'views_data:en'), 1, 'Wrote the cache for the all tables once.'); | |
// Re-initialize the views data cache to simulate a new request and repeat. | |
+ // We have a warm cache now, so this will only request the tables-specific | |
+ // cache entry and return that. | |
$this->initViewsDataCache(); | |
for ($i = 0; $i < 5; $i++) { | |
$this->viewsDataCache->get($table_name); | |
} | |
- // This only requested the table for which a specific cache entry already | |
- // exists. No other cache requests should have been made. | |
- $this->assertEqual($this->memoryCounterBackend->getCounter('get', 'views_data:views_test_data:en'), 1); | |
- $this->assertEqual($this->memoryCounterBackend->getCounter('get', 'views_data:en'), 0); | |
- $this->assertEqual($this->memoryCounterBackend->getCounter('set', 'views_data:views_test_data:en'), 0); | |
- $this->assertEqual($this->memoryCounterBackend->getCounter('set', 'views_data:en'), 0); | |
+ // Assert cache set and get calls. | |
+ $this->assertEqual($this->memoryCounterBackend->getCounter('get', 'views_data:views_test_data:en'), 1, 'Requested the cache for the table-specific cache entry.'); | |
+ $this->assertEqual($this->memoryCounterBackend->getCounter('get', 'views_data:en'), 0, 'Did not request to load the cache entry for all tables.'); | |
+ $this->assertEqual($this->memoryCounterBackend->getCounter('set', 'views_data:views_test_data:en'), 0, 'Did not write the cache entry for the requested table.'); | |
+ $this->assertEqual($this->memoryCounterBackend->getCounter('set', 'views_data:en'), 0, 'Did not write the cache for all tables.'); | |
// Re-initialize the views data cache and repeat with no specified table. | |
$this->initViewsDataCache(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment