Merge pull request #1031 from alrs/fix-web-test-goroutines
web: fix test goroutines
This commit is contained in:
commit
7d884eff9d
@ -57,10 +57,10 @@ func TestService(t *testing.T) {
|
||||
|
||||
service.HandleFunc("/", fn)
|
||||
|
||||
errCh := make(chan error, 1)
|
||||
go func() {
|
||||
if err := service.Run(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
errCh <- service.Run()
|
||||
close(errCh)
|
||||
}()
|
||||
|
||||
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)
|
||||
signal.Notify(ch, syscall.SIGTERM)
|
||||
|
||||
syscall.Kill(syscall.Getpid(), syscall.SIGTERM)
|
||||
<-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 {
|
||||
_, err := reg.GetService("go.micro.web.test")
|
||||
return err == registry.ErrNotFound
|
||||
@ -128,6 +148,7 @@ func TestService(t *testing.T) {
|
||||
t.Errorf("unexpected %s: want true, have false", tt.subject)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestOptions(t *testing.T) {
|
||||
@ -221,10 +242,10 @@ func TestTLS(t *testing.T) {
|
||||
|
||||
service.HandleFunc("/", fn)
|
||||
|
||||
errCh := make(chan error, 1)
|
||||
go func() {
|
||||
if err := service.Run(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
errCh <- service.Run()
|
||||
close(errCh)
|
||||
}()
|
||||
|
||||
var s []*registry.Service
|
||||
@ -257,4 +278,14 @@ func TestTLS(t *testing.T) {
|
||||
if string(b) != str {
|
||||
t.Errorf("Expected %s got %s", str, string(b))
|
||||
}
|
||||
|
||||
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")
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user