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:
parent
a00a06d5bd
commit
7fe755ae53
|
|
@ -36,12 +36,6 @@ etcdv3::AsyncWatchAction::AsyncWatchAction(etcdv3::ActionParameters param)
|
||||||
} else {
|
} else {
|
||||||
throw std::runtime_error("failed to create a watch connection");
|
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
|
// wait "write" (WatchCreateRequest) success, and start to read the first reply
|
||||||
if (cq_.Next(&got_tag, &ok) && ok && got_tag == (void *)"write") {
|
if (cq_.Next(&got_tag, &ok) && ok && got_tag == (void *)"write") {
|
||||||
|
|
@ -49,6 +43,12 @@ void etcdv3::AsyncWatchAction::waitForResponse()
|
||||||
} else {
|
} else {
|
||||||
throw std::runtime_error("failed to write WatchCreateRequest to server");
|
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))
|
while(cq_.Next(&got_tag, &ok))
|
||||||
{
|
{
|
||||||
|
|
@ -102,13 +102,6 @@ void etcdv3::AsyncWatchAction::waitForResponse(std::function<void(etcd::Response
|
||||||
void* got_tag;
|
void* got_tag;
|
||||||
bool ok = false;
|
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))
|
while(cq_.Next(&got_tag, &ok))
|
||||||
{
|
{
|
||||||
if(ok == false)
|
if(ok == false)
|
||||||
|
|
|
||||||
|
|
@ -63,6 +63,13 @@ TEST_CASE("create watcher")
|
||||||
etcd.rmdir("/test", true).error_code();
|
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")
|
// TEST_CASE("request cancellation")
|
||||||
// {
|
// {
|
||||||
// etcd::Client etcd(etcd_uri);
|
// etcd::Client etcd(etcd_uri);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue