Skip to content

Commit

Permalink
Fix goroutine leaks in integration/cassandra_test.go
Browse files Browse the repository at this point in the history
Signed-off-by: Will Sewell <[email protected]>
  • Loading branch information
Will Sewell committed Mar 31, 2024
1 parent 105a4d7 commit 55089ae
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
7 changes: 7 additions & 0 deletions plugin/storage/cassandra/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,13 @@ var _ io.Closer = (*Factory)(nil)

// Close closes the resources held by the factory
func (f *Factory) Close() error {
if f.primarySession != nil {
f.primarySession.Close()
}
if f.archiveSession != nil {
f.archiveSession.Close()
}

f.Options.Get(archiveStorageConfig)
if cfg := f.Options.Get(archiveStorageConfig); cfg != nil {
cfg.TLS.Close()
Expand Down
19 changes: 11 additions & 8 deletions plugin/storage/integration/cassandra_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package integration
import (
"errors"
"fmt"
"io"
"os"
"testing"

Expand Down Expand Up @@ -81,28 +82,28 @@ func (s *CassandraStorageIntegration) initializeCassandraFactory(flags []string)
return f, nil
}

func (s *CassandraStorageIntegration) initializeCassandra() error {
func (s *CassandraStorageIntegration) initializeCassandra() (io.Closer, error) {
f, err := s.initializeCassandraFactory([]string{
"--cassandra.keyspace=jaeger_v1_dc1",
})
if err != nil {
return err
return nil, err
}
s.session = f.PrimarySession()
if s.SpanWriter, err = f.CreateSpanWriter(); err != nil {
return err
return nil, err
}
if s.SpanReader, err = f.CreateSpanReader(); err != nil {
return err
return nil, err
}
if s.SamplingStore, err = f.CreateSamplingStore(0); err != nil {
return err
return nil, err
}

if err = s.initializeDependencyReaderAndWriter(f); err != nil {
return err
return nil, err
}
return nil
return f, nil
}

func (s *CassandraStorageIntegration) initializeDependencyReaderAndWriter(f *cassandra.Factory) error {
Expand All @@ -125,6 +126,8 @@ func TestCassandraStorage(t *testing.T) {
t.Skip("Integration test against Cassandra skipped; set STORAGE env var to cassandra to run this")
}
s := newCassandraStorageIntegration()
require.NoError(t, s.initializeCassandra())
closer, err := s.initializeCassandra()
require.NoError(t, err)
s.IntegrationTestAll(t)
require.NoError(t, closer.Close())
}

0 comments on commit 55089ae

Please sign in to comment.