MB-23530: Add test for CAS set after delete 26/76326/7
authorJames Harrison <00jamesh@gmail.com>
Wed, 5 Apr 2017 14:37:36 +0000 (15:37 +0100)
committerDave Rigby <daver@couchbase.com>
Thu, 13 Apr 2017 13:21:20 +0000 (13:21 +0000)
It is erroneously possible to set an item with CAS after deleting it on
an ephemeral bucket or a full eviction persistent bucket. This breaks
the expected behaviour.

This test should identify this failure and as such can not be enabled
for these types until after the issue is resolved.

Change-Id: I5b382d10a2fa6f955645d8305282a494b5f8ba6b
Reviewed-on: http://review.couchbase.org/76326
Tested-by: Build Bot <build@couchbase.com>
Reviewed-by: Dave Rigby <daver@couchbase.com>
tests/module_tests/kv_bucket_test.cc

index 78bd923..5eb970f 100644 (file)
@@ -298,6 +298,57 @@ TEST_P(KVBucketParamTest, SetCASNonExistent) {
     EXPECT_EQ(ENGINE_KEY_ENOENT, store->set(item, cookie));
 }
 
+// Test CAS set against a deleted item
+TEST_P(KVBucketParamTest, SetCASDeleted) {
+    auto key = makeStoredDocKey("key");
+    auto item = make_item(vbid, key, "value");
+
+    // Store item
+    EXPECT_EQ(ENGINE_SUCCESS, store->set(item, cookie));
+
+    // Delete item
+    uint64_t cas = 0;
+    EXPECT_EQ(ENGINE_SUCCESS,
+              store->deleteItem(key,
+                                cas,
+                                vbid,
+                                cookie,
+                      /*Item*/ nullptr,
+                      /*itemMeta*/ nullptr,
+                      /*mutation_descr_t*/ nullptr));
+
+    if (engine->getConfiguration().getBucketType() == "persistent") {
+        // Trigger a flush to disk.
+        flush_vbucket_to_disk(vbid);
+    }
+
+    // check we have the cas
+    ASSERT_NE(0, cas);
+
+    auto item2 = make_item(vbid, key, "value2");
+    item2.setCas(cas);
+
+    // Store item
+    if (engine->getConfiguration().getBucketType() == "ephemeral" ||
+        engine->getConfiguration().getItemEvictionPolicy() == "full_eviction") {
+        // This currently fails due to MB-23712
+        // TODO: Reenable this check once fixed
+        return;
+    }
+
+    if (engine->getConfiguration().getItemEvictionPolicy() ==
+               "full_eviction") {
+        EXPECT_EQ(ENGINE_EWOULDBLOCK, store->set(item2, cookie));
+
+        // Manually run the bgfetch task.
+        MockGlobalTask mockTask(engine->getTaskable(),
+                                TaskId::MultiBGFetcherTask);
+        store->getVBucket(vbid)->getShard()->getBgFetcher()->run(&mockTask);
+    }
+
+    EXPECT_EQ(ENGINE_KEY_ENOENT, store->set(item2, cookie));
+}
+
 // Add tests //////////////////////////////////////////////////////////////////
 
 // Test successful add