]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Updated tests/testRock and the store rebuild stubs it needs.
authorAlex Rousskov <rousskov@measurement-factory.com>
Fri, 27 Dec 2013 18:37:26 +0000 (11:37 -0700)
committerAlex Rousskov <rousskov@measurement-factory.com>
Fri, 27 Dec 2013 18:37:26 +0000 (11:37 -0700)
Synced tests/testUfs after updating the store rebuild stubs.

Store uses StoreController::store_dirs_rebuilding to decide whether the entry
release should be delayed. Thus, storeRebuildComplete() must update it. Also
synced the corresponding CPPUNIT_ASSERT_EQUAL() statements to expect a zero
value after the rebuild is completed.

Do not create an entry just to get its key: Creating forces a public key which
necessarily invalidates the previously cached entry with the same key, if any.

Unlock unused entries. This helps with their release later (and adds more
realism to the test case).

Fixed entry #5 test case to account for the fact that creating a second entry
with the same public key invalidates the first entry.

Release instead of just unlinking entries. StoreEntry::release() is the public
interface which updates internal tables as needed. StoreEntry::unlink() is an
internal call for updating the disk cache-related state; it does not update
the the in-transit index.

src/tests/stub_store_rebuild.cc
src/tests/testRock.cc
src/tests/testUfs.cc

index 8d952394744d39adc239eacee28a1b69a02854bc..ab7e68ba63912975ee4ab18ad11fc99249d4ab4e 100644 (file)
 
 #include "squid.h"
 #include "MemBuf.h"
+#include "SwapDir.h"
 #include "store_rebuild.h"
+#if HAVE_STRING_H
+#include <string.h>
+#endif
 
 #define STUB_API "stub_store_rebuild.cc"
 #include "tests/STUB.h"
 
 void storeRebuildProgress(int sd_index, int total, int sofar) STUB
-void storeRebuildComplete(StoreRebuildData *dc) STUB_NOP
-bool storeRebuildLoadEntry(int, int, MemBuf&, StoreRebuildData&)
-{
-    return false;
-}
 bool storeRebuildKeepEntry(const StoreEntry &tmpe, const cache_key *key, StoreRebuildData &counts) STUB_RETVAL(false)
 bool storeRebuildParseEntry(MemBuf &, StoreEntry &, cache_key *, StoreRebuildData &, uint64_t) STUB_RETVAL(false)
+
+void storeRebuildComplete(StoreRebuildData *)
+{
+    --StoreController::store_dirs_rebuilding;
+}
+
+bool
+storeRebuildLoadEntry(int fd, int diskIndex, MemBuf &buf, StoreRebuildData &)
+{
+    if (fd < 0)
+        return false;
+
+    assert(buf.hasSpace()); // caller must allocate
+    // this stub simulates reading an empty entry
+    memset(buf.space(), 0, buf.spaceSize());
+    buf.appended(buf.spaceSize());
+    return true;
+}
index cf7cc4055eb0f868c48bcdac4122cf29e79c1e9f..3b2e640f7ef53a468cd2c8d9d4ef1306367d3803 100644 (file)
@@ -167,7 +167,16 @@ testRock::storeInit()
      */
 
     /* nothing left to rebuild */
-    CPPUNIT_ASSERT_EQUAL(1, StoreController::store_dirs_rebuilding);
+    CPPUNIT_ASSERT_EQUAL(0, StoreController::store_dirs_rebuilding);
+}
+
+static const char *
+storeId(const int i)
+{
+    static char buf[64];
+    snprintf(buf, sizeof(buf), "dummy url %i", i);
+    buf[sizeof(buf) - 1] = '\0';
+    return buf;
 }
 
 StoreEntry *
@@ -175,11 +184,8 @@ testRock::createEntry(const int i)
 {
     RequestFlags flags;
     flags.cachable = true;
-    char url[64];
-    snprintf(url, sizeof(url), "dummy url %i", i);
-    url[sizeof(url) - 1] = '\0';
     StoreEntry *const pe =
-        storeCreateEntry(url, "dummy log url", flags, Http::METHOD_GET);
+        storeCreateEntry(storeId(i), "dummy log url", flags, Http::METHOD_GET);
     HttpReply *const rep = const_cast<HttpReply *>(pe->getReply());
     rep->setHeaders(Http::scOkay, "dummy test object", "x-squid-internal/test", 0, -1, squid_curtime + 100000);
 
@@ -213,8 +219,7 @@ testRock::addEntry(const int i)
 StoreEntry *
 testRock::getEntry(const int i)
 {
-    StoreEntry *const pe = createEntry(i);
-    return store->get(reinterpret_cast<const cache_key *>(pe->key));
+    return storeGetPublic(storeId(i), Http::METHOD_GET);
 }
 
 void
@@ -251,7 +256,7 @@ testRock::testRockSwapOut()
 
         CPPUNIT_ASSERT_EQUAL(SWAPOUT_DONE, pe->swap_status);
 
-        pe->unlock("testRock::testRockSwapOut");
+        pe->unlock("testRock::testRockSwapOut priming");
     }
 
     CPPUNIT_ASSERT_EQUAL((uint64_t)5, store->currentCount());
@@ -268,6 +273,8 @@ testRock::testRockSwapOut()
         loop.run();
 
         CPPUNIT_ASSERT_EQUAL(SWAPOUT_DONE, pe->swap_status);
+
+        pe->unlock("testRock::testRockSwapOut e#4");
     }
 
     // try to swap out entry to a used locked slot
@@ -287,16 +294,29 @@ testRock::testRockSwapOut()
 
         StockEventLoop loop;
         loop.run();
+
+        pe->unlock("testRock::testRockSwapOut e#5.1");
+        pe2->unlock("testRock::testRockSwapOut e#5.2");
+
+        // pe2 has the same public key as pe so it marks old pe for release
+        // here, we add another entry #5 into the now-available slot
+        StoreEntry *const pe3 = addEntry(5);
+        CPPUNIT_ASSERT_EQUAL(SWAPOUT_WRITING, pe3->swap_status);
+        CPPUNIT_ASSERT_EQUAL(0, pe3->swap_dirn);
+        CPPUNIT_ASSERT(pe3->swap_filen >= 0);
+        loop.run();
+        CPPUNIT_ASSERT_EQUAL(SWAPOUT_DONE, pe3->swap_status);
+        pe3->unlock("testRock::testRockSwapOut e#5.3");
     }
 
     CPPUNIT_ASSERT_EQUAL((uint64_t)6, store->currentCount());
 
-    // try to get and unlink entries
+    // try to get and release all entries
     for (int i = 0; i < 6; ++i) {
         StoreEntry *const pe = getEntry(i);
         CPPUNIT_ASSERT(pe != NULL);
 
-        pe->unlink();
+        pe->release(); // destroys pe
 
         StoreEntry *const pe2 = getEntry(i);
         CPPUNIT_ASSERT_EQUAL(static_cast<StoreEntry *>(NULL), pe2);
index 342687ae302bab361f284be35fe1739ebfcda6b6..45fb28be003dcfdad51b2561e9e7e36239dd6293 100644 (file)
@@ -129,7 +129,7 @@ testUfs::testUfsSearch()
     /* rebuild is a scheduled event */
     StockEventLoop loop;
 
-    while (StoreController::store_dirs_rebuilding > 1)
+    while (StoreController::store_dirs_rebuilding)
         loop.runOnce();
 
     /* cannot use loop.run(); as the loop will never idle: the store-dir
@@ -137,7 +137,7 @@ testUfs::testUfsSearch()
      */
 
     /* nothing left to rebuild */
-    CPPUNIT_ASSERT_EQUAL(1, StoreController::store_dirs_rebuilding);
+    CPPUNIT_ASSERT_EQUAL(0, StoreController::store_dirs_rebuilding);
 
     /* add an entry */
     {