Skip to content

Commit 9912f7f

Browse files
committed
grpc: Run test servers on unused ports
By setting the port to 0 we will end up letting the kernel choose the port. We need to call the new s.listen method so that the code running in the main test goroutine won't race with s.port = 0 or s.port = $kernelProvidedPort that happens in s.listen. This ends up fixing a flaky test setup that is *super* hard to reproduce. The flaky test was first seen in Nahum's branch converting CI from drone -> GitHubActions, and only when running `make test` followed by `make coverage`, which seemed to run into the TCP port possibly being in SHUTDOWN still. Seems like the GHA runner does not have the kernel tweaked for this.
1 parent b29b40e commit 9912f7f

1 file changed

Lines changed: 2 additions & 0 deletions

File tree

grpc/grpc_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,8 @@ func serve(t *testing.T, s *Server, test func()) {
195195
wg.Add(1)
196196

197197
go func() {
198+
s.port = 0
199+
s.listen()
198200
wg.Done()
199201
if err := s.Serve(); err != nil {
200202
panic(err)

0 commit comments

Comments
 (0)