Skip to content

Commit

Permalink
fix(test): ensure some more clients are closed
Browse files Browse the repository at this point in the history
Signed-off-by: Dominic Evans <dominic.evans@uk.ibm.com>
  • Loading branch information
dnwe committed Aug 11, 2023
1 parent 45313c3 commit 2facdec
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 2 additions & 1 deletion client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
)

func safeClose(t testing.TB, c io.Closer) {
t.Helper()
err := c.Close()
if err != nil {
t.Error(err)
Expand Down Expand Up @@ -51,6 +52,7 @@ func TestCachedPartitions(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer safeClose(t, c)
client := c.(*client)

// Verify they aren't cached the same
Expand All @@ -69,7 +71,6 @@ func TestCachedPartitions(t *testing.T) {
}

seedBroker.Close()
safeClose(t, client)
}

func TestClientDoesntCachePartitionsForTopicsWithErrors(t *testing.T) {
Expand Down
4 changes: 3 additions & 1 deletion functional_producer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,7 @@ func TestFuncTxnAbortedProduce(t *testing.T) {

client, err := NewClient(FunctionalTestEnv.KafkaBrokerAddrs, config)
require.NoError(t, err)
defer client.Close()

consumer, err := NewConsumerFromClient(client)
require.NoError(t, err)
Expand Down Expand Up @@ -745,6 +746,7 @@ func TestInterceptors(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer safeClose(t, client)

initialOffset, err := client.GetOffset("test.1", 0, OffsetNewest)
if err != nil {
Expand Down Expand Up @@ -821,6 +823,7 @@ func testProducingMessages(t *testing.T, config *Config) {
if err != nil {
t.Fatal(err)
}
defer safeClose(t, client)

// Keep in mind the current offset
initialOffset, err := client.GetOffset("test.1", 0, OffsetNewest)
Expand Down Expand Up @@ -885,7 +888,6 @@ func testProducingMessages(t *testing.T, config *Config) {
validateConsumerMetrics(t, client)

safeClose(t, consumer)
safeClose(t, client)
}

// TestAsyncProducerRemoteBrokerClosed ensures that the async producer can
Expand Down

0 comments on commit 2facdec

Please sign in to comment.