embed: Move the ReadyNotify() call to a better place
When using the embed functionality, you can't call the Server.Stop() function until StartEtcd returns, which can block until there is a call to Server.Stop() in error situations. Since we have a catch-22, the ReadyNotify() can be called manually by the user if they wish to wait for the server startup, or in parallel with a timeout if they wish to cancel it after some time. Chzz pointed out that this is also more consistent with the etcdserver.Start() behaviour too. purpleidea pointed out that this is actually more correct too, because we can now register the stop interrupt handler before we block on startup.
This commit is contained in:
@ -65,6 +65,9 @@ func TestEmbedEtcd(t *testing.T) {
|
||||
for i, tt := range tests {
|
||||
tests[i].cfg.Dir = dir
|
||||
e, err := embed.StartEtcd(&tests[i].cfg)
|
||||
if e != nil {
|
||||
<-e.Server.ReadyNotify() // wait for e.Server to join the cluster
|
||||
}
|
||||
if tt.werr != "" {
|
||||
if err == nil || !strings.Contains(err.Error(), tt.werr) {
|
||||
t.Errorf("%d: expected error with %q, got %v", i, tt.werr, err)
|
||||
|
Reference in New Issue
Block a user