web: fix test goroutine in TestService()
This commit is contained in:
parent
f25ad35f0a
commit
c9af88184b
@ -57,10 +57,10 @@ func TestService(t *testing.T) {
|
|||||||
|
|
||||||
service.HandleFunc("/", fn)
|
service.HandleFunc("/", fn)
|
||||||
|
|
||||||
|
errCh := make(chan error, 1)
|
||||||
go func() {
|
go func() {
|
||||||
if err := service.Run(); err != nil {
|
errCh <- service.Run()
|
||||||
t.Fatal(err)
|
close(errCh)
|
||||||
}
|
|
||||||
}()
|
}()
|
||||||
|
|
||||||
var s []*registry.Service
|
var s []*registry.Service
|
||||||
@ -104,12 +104,32 @@ func TestService(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
select {
|
||||||
|
case err := <-errCh:
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("service.Run():%v", err)
|
||||||
|
}
|
||||||
|
case <-time.After(time.Duration(time.Second)):
|
||||||
|
t.Logf("service.Run() survived a client request without an error")
|
||||||
|
}
|
||||||
|
|
||||||
ch := make(chan os.Signal, 1)
|
ch := make(chan os.Signal, 1)
|
||||||
signal.Notify(ch, syscall.SIGTERM)
|
signal.Notify(ch, syscall.SIGTERM)
|
||||||
|
|
||||||
syscall.Kill(syscall.Getpid(), syscall.SIGTERM)
|
syscall.Kill(syscall.Getpid(), syscall.SIGTERM)
|
||||||
<-ch
|
<-ch
|
||||||
|
|
||||||
|
select {
|
||||||
|
case err := <-errCh:
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("service.Run():%v", err)
|
||||||
|
} else {
|
||||||
|
t.Log("service.Run() nil return on syscall.SIGTERM")
|
||||||
|
}
|
||||||
|
case <-time.After(time.Duration(time.Second)):
|
||||||
|
t.Logf("service.Run() survived a client request without an error")
|
||||||
|
}
|
||||||
|
|
||||||
eventually(func() bool {
|
eventually(func() bool {
|
||||||
_, err := reg.GetService("go.micro.web.test")
|
_, err := reg.GetService("go.micro.web.test")
|
||||||
return err == registry.ErrNotFound
|
return err == registry.ErrNotFound
|
||||||
@ -128,6 +148,7 @@ func TestService(t *testing.T) {
|
|||||||
t.Errorf("unexpected %s: want true, have false", tt.subject)
|
t.Errorf("unexpected %s: want true, have false", tt.subject)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestOptions(t *testing.T) {
|
func TestOptions(t *testing.T) {
|
||||||
@ -261,9 +282,10 @@ func TestTLS(t *testing.T) {
|
|||||||
select {
|
select {
|
||||||
case err := <-errCh:
|
case err := <-errCh:
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Run():%v", err)
|
t.Fatalf("service.Run():%v", err)
|
||||||
}
|
}
|
||||||
case <-time.After(time.Duration(time.Second)):
|
case <-time.After(time.Duration(time.Second)):
|
||||||
t.Logf("service.Run() survived a client request without an error")
|
t.Logf("service.Run() survived a client request without an error")
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user