mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
Merge pull request #10420 from spzala/watch10340
clientV3watch: do not return ctx canceled when Close watch
This commit is contained in:
commit
e80d1745be
@ -1133,3 +1133,24 @@ func TestWatchCancelDisconnected(t *testing.T) {
|
||||
t.Fatal("took too long to cancel disconnected watcher")
|
||||
}
|
||||
}
|
||||
|
||||
// TestWatchClose ensures that close does not return error
|
||||
func TestWatchClose(t *testing.T) {
|
||||
runWatchTest(t, testWatchClose)
|
||||
}
|
||||
|
||||
func testWatchClose(t *testing.T, wctx *watchctx) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
wch := wctx.w.Watch(ctx, "a")
|
||||
cancel()
|
||||
if wch == nil {
|
||||
t.Fatalf("expected watcher channel, got nil")
|
||||
}
|
||||
if wctx.w.Close() != nil {
|
||||
t.Fatalf("watch did not close successfully")
|
||||
}
|
||||
wresp, ok := <-wch
|
||||
if ok {
|
||||
t.Fatalf("read wch got %v; expected closed channel", wresp)
|
||||
}
|
||||
}
|
||||
|
@ -371,6 +371,10 @@ func (w *watcher) Close() (err error) {
|
||||
err = werr
|
||||
}
|
||||
}
|
||||
// Consider context.Canceled as a successful close
|
||||
if err == context.Canceled {
|
||||
err = nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user