mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
etcdserver: add StopNotify
This commit is contained in:
parent
978d0f1ca1
commit
b5d480f17a
@ -391,6 +391,10 @@ func (s *EtcdServer) Stop() {
|
||||
<-s.done
|
||||
}
|
||||
|
||||
// StopNotify returns a channel that receives a empty struct
|
||||
// when the server is stopped.
|
||||
func (s *EtcdServer) StopNotify() <-chan struct{} { return s.done }
|
||||
|
||||
// Do interprets r and performs an operation on s.store according to r.Method
|
||||
// and other fields. If r.Method is "POST", "PUT", "DELETE", or a "GET" with
|
||||
// Quorum == true, r will be sent through consensus before performing its
|
||||
|
@ -1135,6 +1135,30 @@ func TestPublishRetry(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestStopNotify(t *testing.T) {
|
||||
s := &EtcdServer{
|
||||
stop: make(chan struct{}),
|
||||
done: make(chan struct{}),
|
||||
}
|
||||
go func() {
|
||||
<-s.stop
|
||||
close(s.done)
|
||||
}()
|
||||
|
||||
notifier := s.StopNotify()
|
||||
select {
|
||||
case <-notifier:
|
||||
t.Fatalf("received unexpected stop notification")
|
||||
default:
|
||||
}
|
||||
s.Stop()
|
||||
select {
|
||||
case <-notifier:
|
||||
default:
|
||||
t.Fatalf("cannot receive stop notification")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetOtherPeerURLs(t *testing.T) {
|
||||
tests := []struct {
|
||||
membs []*Member
|
||||
|
Loading…
x
Reference in New Issue
Block a user