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)
|
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) {
|
||||||
@ -221,10 +242,10 @@ func TestTLS(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
|
||||||
@ -257,4 +278,14 @@ func TestTLS(t *testing.T) {
|
|||||||
if string(b) != str {
|
if string(b) != str {
|
||||||
t.Errorf("Expected %s got %s", str, string(b))
|
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…
Reference in New Issue
Block a user