From a27821f7238eceaee21d4e0b8bd31aeb923dd72a Mon Sep 17 00:00:00 2001 From: Tor Brede Vekterli Date: Thu, 16 Mar 2023 14:16:00 +0000 Subject: Do not return TaS error code when doc is not found for conditional update Instead, return an OK response with `wasFound() == false`. This mirrors the behavior of existing non-conditional updates. --- storage/src/tests/persistence/testandsettest.cpp | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'storage/src/tests/persistence/testandsettest.cpp') diff --git a/storage/src/tests/persistence/testandsettest.cpp b/storage/src/tests/persistence/testandsettest.cpp index 5be1c7cd92a..02be3e4d2c0 100644 --- a/storage/src/tests/persistence/testandsettest.cpp +++ b/storage/src/tests/persistence/testandsettest.cpp @@ -66,7 +66,7 @@ struct TestAndSetTest : PersistenceTestUtils { document::Document::SP createTestDocument(); document::Document::SP retrieveTestDocument(); - void setTestCondition(api::TestAndSetCommand & command); + static void setTestCondition(api::TestAndSetCommand& command); void putTestDocument(bool matchingHeader, api::Timestamp timestamp); void assertTestDocumentFoundAndMatchesContent(const document::FieldValue & value); @@ -154,6 +154,16 @@ TEST_F(TestAndSetTest, conditional_remove_executed_on_condition_match) { dumpBucket(BUCKET_ID)); } +TEST_F(TestAndSetTest, conditional_remove_to_non_existing_document_fails_with_tas_error) { + api::Timestamp timestamp = 0; + auto remove = std::make_shared(BUCKET, testDocId, timestamp); + setTestCondition(*remove); + + ASSERT_EQ(fetchResult(asyncHandler->handleRemove(*remove, createTracker(remove, BUCKET))).getResult(), + api::ReturnCode::Result::TEST_AND_SET_CONDITION_FAILED); + EXPECT_EQ("", dumpBucket(BUCKET_ID)); +} + std::shared_ptr TestAndSetTest::conditional_update_test(bool createIfMissing, api::Timestamp updateTimestamp) { @@ -197,8 +207,10 @@ TEST_F(TestAndSetTest, conditional_update_not_executed_when_no_document_and_no_a api::Timestamp updateTimestamp = 200; auto updateUp = conditional_update_test(false, updateTimestamp); - ASSERT_EQ(fetchResult(asyncHandler->handleUpdate(*updateUp, createTracker(updateUp, BUCKET))).getResult(), - api::ReturnCode::Result::TEST_AND_SET_CONDITION_FAILED); + auto reply = fetch_single_reply(asyncHandler->handleUpdate(*updateUp, createTracker(updateUp, BUCKET))); + ASSERT_TRUE(reply); + EXPECT_EQ(reply->getResult(), api::ReturnCode()); + EXPECT_FALSE(reply->wasFound()); EXPECT_EQ("", dumpBucket(BUCKET_ID)); } @@ -270,7 +282,7 @@ TestAndSetTest::retrieveTestDocument() auto tracker = _persistenceHandler->simpleMessageHandler().handleGet(*get, createTracker(get, BUCKET)); assert(tracker->getResult() == api::ReturnCode::Result::OK); - auto & reply = static_cast(tracker->getReply()); + auto& reply = dynamic_cast(tracker->getReply()); assert(reply.wasFound()); return reply.getDocument(); -- cgit v1.2.3