fix flaky teleterm daemon test (#29218)

This commit is contained in:
STeve (Xin) Huang 2023-07-17 20:00:33 -04:00 committed by GitHub
parent b0a787021b
commit ed8d212812
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -22,7 +22,6 @@ import (
"testing"
"github.com/gravitational/trace"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
@ -451,12 +450,22 @@ func newMockTSHDEventsServiceServer(t *testing.T) (service *mockTSHDEventsServic
grpcServer := grpc.NewServer()
api.RegisterTshdEventsServiceServer(grpcServer, tshdEventsService)
t.Cleanup(grpcServer.GracefulStop)
serveErr := make(chan error)
go func() {
err := grpcServer.Serve(ls)
assert.NoError(t, err)
serveErr <- grpcServer.Serve(ls)
}()
t.Cleanup(func() {
grpcServer.GracefulStop()
// For test cases that did not send any grpc calls, test may finish
// before grpcServer.Serve is called and grpcServer.Serve will return
// grpc.ErrServerStopped.
err := <-serveErr
if len(tshdEventsService.callCounts) > 0 || err != grpc.ErrServerStopped {
require.NoError(t, err)
}
})
return tshdEventsService, ls.Addr().String()
}