Skip to content

Commit

Permalink
Fix race condition in the v1 ingestor server tests
Browse files Browse the repository at this point in the history
There was a recurring race condition because of a goroutine that was
running the `Pusher` method on manager, and the BeforeEach which would
assign a new v1 `IngestorServer` to manager.

This change stops the goroutine after it's not needed, and waits for it
to close before completing the `It` test.
  • Loading branch information
ctlong committed Oct 18, 2022
1 parent 5d93035 commit c7c6d3c
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/router/internal/server/v1/ingestor_server_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package v1_test

import (
"context"
"errors"
"io"
"net"
"time"

"golang.org/x/net/context"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"

Expand Down Expand Up @@ -141,17 +141,23 @@ var _ = Describe("IngestorServer", func() {

Context("When the Recv returns an error", func() {
It("does not forward the message to the sender", func() {
ctx, cancel := context.WithCancel(context.Background())
fakeStream := newSpyIngestorGRPCServer()
fakeStream.context = ctx
fakeStream.recvError = errors.New("fake error")

errCh := make(chan error)
go func() {
err := manager.Pusher(fakeStream)
Expect(err).NotTo(HaveOccurred())
errCh <- manager.Pusher(fakeStream)
}()

Consistently(func() bool {
_, ok := v1Buf.TryNext()
return ok
}).Should(BeFalse())

cancel()
Expect(<-errCh).To(MatchError("context canceled"))
})
})

Expand Down

0 comments on commit c7c6d3c

Please sign in to comment.