Make sure a cancalable watch must be a successful watch.

Signed-off-by: Tao He <linzhu.ht@alibaba-inc.com>
This commit is contained in:
Tao He 2020-10-12 13:19:23 +08:00
parent a00a06d5bd
commit 7fe755ae53
2 changed files with 13 additions and 13 deletions

View File

@ -36,12 +36,6 @@ etcdv3::AsyncWatchAction::AsyncWatchAction(etcdv3::ActionParameters param)
} else {
throw std::runtime_error("failed to create a watch connection");
}
}
void etcdv3::AsyncWatchAction::waitForResponse()
{
void* got_tag;
bool ok = false;
// wait "write" (WatchCreateRequest) success, and start to read the first reply
if (cq_.Next(&got_tag, &ok) && ok && got_tag == (void *)"write") {
@ -49,6 +43,12 @@ void etcdv3::AsyncWatchAction::waitForResponse()
} else {
throw std::runtime_error("failed to write WatchCreateRequest to server");
}
}
void etcdv3::AsyncWatchAction::waitForResponse()
{
void* got_tag;
bool ok = false;
while(cq_.Next(&got_tag, &ok))
{
@ -102,13 +102,6 @@ void etcdv3::AsyncWatchAction::waitForResponse(std::function<void(etcd::Response
void* got_tag;
bool ok = false;
// wait "write" (WatchCreateRequest) success, and start to read the first reply
if (cq_.Next(&got_tag, &ok) && ok && got_tag == (void *)"write") {
stream->Read(&reply, (void*)this);
} else {
throw std::runtime_error("failed to write WatchCreateRequest to server");
}
while(cq_.Next(&got_tag, &ok))
{
if(ok == false)

View File

@ -63,6 +63,13 @@ TEST_CASE("create watcher")
etcd.rmdir("/test", true).error_code();
}
TEST_CASE("watch should exit normally")
{
// cancal immediately after start watch.
etcd::Watcher watcher(etcd_uri, "/test", printResponse, true);
watcher.Cancel();
}
// TEST_CASE("request cancellation")
// {
// etcd::Client etcd(etcd_uri);