Skip to content

Commit

Permalink
fix concurrency in test
Browse files Browse the repository at this point in the history
  • Loading branch information
jfbus committed Nov 12, 2018
1 parent c866960 commit 2fb2c7a
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,36 +139,35 @@ type workingTransport struct {

func (*workingTransport) RegisterEndpoints(m endpoint.Middleware) error { return nil }
func (t *workingTransport) Start(ctx context.Context) error {
t.running = make(chan struct{})
defer func() {
close(t.running)
}()
}()
<-ctx.Done()
return nil
}
func (*workingTransport) Shutdown(ctx context.Context) error { return nil }

func TestStartError(t *testing.T) {
ctx, cancel := context.WithTimeout(context.TODO(), 30*time.Second)
ctx, cancel := context.WithTimeout(context.TODO(), 5*time.Second)
defer cancel()
exitError := make(chan error)
wt := &workingTransport{}
wt := &workingTransport{running: make(chan struct{})}
srv := NewServer(&failingTransport{}, wt)
go func() {
exitError <- srv.Run(ctx)
}()

select {
case <-ctx.Done():
t.Error("Server.Run has not stopped after 30sec")
t.Error("Server.Run has not stopped after 5sec")
case err := <-exitError:
if err == nil || err.Error() != "unable to start" {
t.Errorf("Server.Run returned an invalid error : %v", err)
}
}
select {
case <-ctx.Done():
t.Error("Alternate transport has not stopped after 30sec")
t.Error("Alternate transport has not stopped after 5sec")
case <-wt.running:
}
}

0 comments on commit 2fb2c7a

Please sign in to comment.