Skip to content
This repository has been archived by the owner on Jun 19, 2022. It is now read-only.

Commit

Permalink
Properly cleanup test server and client in ingress TestHandler (#1830)
Browse files Browse the repository at this point in the history
  • Loading branch information
ian-mi authored Oct 21, 2020
1 parent 940d1c9 commit 632e6ca
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions pkg/broker/ingress/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ func TestHandler(t *testing.T) {
defer cancel()

psSrv := pstest.NewServer()
defer psSrv.Close()
t.Cleanup(func() { psSrv.Close() })

decouple := tc.decouple
if decouple == nil {
Expand Down Expand Up @@ -351,6 +351,7 @@ func TestHandler(t *testing.T) {
}
savedToSink, err := binding.ToEvent(ctx, m)
if err != nil {
m.Finish(err)
t.Fatal(err)
}
// Retrieve the event from the decouple sink.
Expand All @@ -363,6 +364,7 @@ func TestHandler(t *testing.T) {
for _, assertion := range tc.eventAssertions {
assertion(t, savedToSink)
}
m.Finish(nil)
}

select {
Expand Down Expand Up @@ -460,7 +462,13 @@ func setupTestReceiver(ctx context.Context, t testing.TB, psSrv *pstest.Server)
t.Fatal(err)
}

go p.OpenInbound(cecontext.WithLogger(ctx, logtest.TestLogger(t)))
errChan := make(chan error)
go func() {
errChan <- p.OpenInbound(cecontext.WithLogger(ctx, logtest.TestLogger(t)))
}()
t.Cleanup(func() {
<-errChan
})
return p
}

Expand Down

0 comments on commit 632e6ca

Please sign in to comment.