etcdserver: add StopNotify

This commit is contained in:
Xiang Li 2014-11-13 14:16:48 -08:00
parent 978d0f1ca1
commit b5d480f17a
2 changed files with 28 additions and 0 deletions

View File

@ -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

View File

@ -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