Skip to content

Commit 62ffc24

Browse files
behoskezhuw
authored andcommitted
fix: wrong error code for Error::NoWatcher
See #22.
1 parent 60fef3f commit 62ffc24

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

src/proto/error_code.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ pub enum ErrorCode {
4949
AuthFailed = -115,
5050
SessionMoved = -118,
5151
NotReadOnly = -119,
52-
NoWatcher = -122,
52+
NoWatcher = -121,
5353
ReconfigDisabled = -123,
5454
SessionClosedRequireSaslAuth = -124,
5555
QuotaExceeded = -125,

tests/zookeeper.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1375,6 +1375,34 @@ async fn test_watcher_coexist_on_same_path() {
13751375
assert_that!(recursive_watcher.changed().await).is_equal_to(&expected);
13761376
}
13771377

1378+
// Use "current_thread" explicitly.
1379+
#[test_log::test(tokio::test(flavor = "current_thread"))]
1380+
async fn test_remove_no_watcher() {
1381+
let docker = DockerCli::default();
1382+
let zookeeper = docker.run(zookeeper_image());
1383+
let zk_port = zookeeper.get_host_port(2181);
1384+
let cluster = format!("127.0.0.1:{}", zk_port);
1385+
1386+
let client = zk::Client::connect(&cluster).await.unwrap();
1387+
1388+
let (_, exist_watcher) = client.check_and_watch_stat("/a").await.unwrap();
1389+
let create = client.create("/a", &vec![], PERSISTENT_OPEN);
1390+
1391+
// Let session task issue `create` request first, oneshot watch will be removed by server.
1392+
tokio::task::yield_now().await;
1393+
1394+
// Issue `RemoveWatches` which likely happen before watch event notification as it involves
1395+
// several IO paths.
1396+
assert_that!(exist_watcher.remove().await.unwrap_err()).is_equal_to(zk::Error::NoWatcher);
1397+
create.await.unwrap();
1398+
1399+
let (_, _, data_watcher) = client.get_and_watch_data("/a").await.unwrap();
1400+
let delete = client.delete("/a", None);
1401+
tokio::task::yield_now().await;
1402+
assert_that!(data_watcher.remove().await.unwrap_err()).is_equal_to(zk::Error::NoWatcher);
1403+
delete.await.unwrap();
1404+
}
1405+
13781406
#[test_log::test(tokio::test)]
13791407
async fn test_session_event() {
13801408
let docker = DockerCli::default();

0 commit comments

Comments
 (0)