diff --git a/frameworks/libs/distributeddb/test/unittest/common/interfaces/distributeddb_interfaces_nb_publish_test.cpp b/frameworks/libs/distributeddb/test/unittest/common/interfaces/distributeddb_interfaces_nb_publish_test.cpp index 7384fb5a7ea78e422c48ff820e3db9711f9c6643..667677850d4f196bbf7caf49d3393b590b43080d 100644 --- a/frameworks/libs/distributeddb/test/unittest/common/interfaces/distributeddb_interfaces_nb_publish_test.cpp +++ b/frameworks/libs/distributeddb/test/unittest/common/interfaces/distributeddb_interfaces_nb_publish_test.cpp @@ -820,4 +820,39 @@ HWTEST_F(DistributedDBInterfacesNBPublishTest, SingleVerPublishKey012, TestSize. EXPECT_EQ(g_mgr.CloseKvStore(g_kvNbDelegatePtr), OK); EXPECT_EQ(g_mgr.DeleteKvStore("distributed_nb_publish_SingleVerPublishKey012"), OK); g_kvNbDelegatePtr = nullptr; +} + +/** + * @tc.name: SingleVerPublishKey013 + * @tc.desc: Publish key but observer released + * @tc.type: FUNC + * @tc.require: + * @tc.author: bty + */ +HWTEST_F(DistributedDBInterfacesNBPublishTest, SingleVerPublishKey013, TestSize.Level1) +{ + const KvStoreNbDelegate::Option option = {true, false}; + g_mgr.GetKvStore("distributed_nb_publish_SingleVerPublishKey013", option, g_kvNbDelegateCallback); + ASSERT_TRUE(g_kvNbDelegatePtr != nullptr); + EXPECT_TRUE(g_kvDelegateStatus == OK); + + EXPECT_EQ(g_kvNbDelegatePtr->PutLocal(KEY_1, VALUE_1), OK); + std::shared_ptr observerLocal = std::make_shared(); + ASSERT_TRUE(observerLocal != nullptr); + EXPECT_EQ(g_kvNbDelegatePtr->RegisterObserver(NULL_KEY, OBSERVER_CHANGES_LOCAL_ONLY, observerLocal), OK); + observerLocal = nullptr; + /** + * @tc.steps:step1. PublishLocal key1. + * @tc.expected: step1. return OK. + */ + EXPECT_EQ(g_kvNbDelegatePtr->PublishLocal(KEY_1, true, false, nullptr), OK); + /** + * @tc.steps:step2. Get value of key1 from local table + * @tc.expected: step2. value of key1 is value1 + */ + Value readValue; + EXPECT_EQ(g_kvNbDelegatePtr->GetLocal(KEY_1, readValue), NOT_FOUND); + EXPECT_EQ(g_mgr.CloseKvStore(g_kvNbDelegatePtr), OK); + EXPECT_EQ(g_mgr.DeleteKvStore("distributed_nb_publish_SingleVerPublishKey013"), OK); + g_kvNbDelegatePtr = nullptr; } \ No newline at end of file diff --git a/frameworks/libs/distributeddb/test/unittest/common/syncer/cloud/distributeddb_cloud_kvstore_test.cpp b/frameworks/libs/distributeddb/test/unittest/common/syncer/cloud/distributeddb_cloud_kvstore_test.cpp index 71fa4368807cf8327e6a25d00ec8979d51834ba8..305acebea35fe2d4296239a800483ca8458dccba 100644 --- a/frameworks/libs/distributeddb/test/unittest/common/syncer/cloud/distributeddb_cloud_kvstore_test.cpp +++ b/frameworks/libs/distributeddb/test/unittest/common/syncer/cloud/distributeddb_cloud_kvstore_test.cpp @@ -1965,6 +1965,37 @@ HWTEST_F(DistributedDBCloudKvStoreTest, ObserverDataChangeTest004, TestSize.Leve observer = nullptr; } +/** + * @tc.name: ObserverDataChangeTest005 + * @tc.desc: test cloud sync after ovserver released + * @tc.type: FUNC + * @tc.require: + * @tc.author: bty + */ +HWTEST_F(DistributedDBCloudKvStoreTest, ObserverDataChangeTest005, TestSize.Level1) +{ + /** + * @tc.steps: step1. delegate1 insert two data and sync with cloud + * @tc.expected: step1. insert and sync ok + */ + Key k1 = {'k', '1'}; + Value v1 = {'v', '1'}; + ASSERT_EQ(kvDelegatePtrS1_->Put(k1, v1), OK); + Value actualValue; + BlockSync(kvDelegatePtrS1_, OK, g_CloudSyncoption); + + /** + * @tc.steps: step2. sync after ovserver released + * @tc.expected: step2. sync success + */ + std::shared_ptr observer = std::make_shared(); + EXPECT_EQ(kvDelegatePtrS2_->RegisterObserver({}, OBSERVER_CHANGES_CLOUD, observer), OK); + observer = nullptr; + BlockSync(kvDelegatePtrS2_, OK, g_CloudSyncoption); + EXPECT_EQ(kvDelegatePtrS2_->Get(k1, actualValue), OK); + EXPECT_EQ(actualValue, v1); +} + /** * @tc.name: StartTransactionForAsyncDownloadTest001 * @tc.desc: test StartTransactionForAsyncDownload function