Skip to content

Commit

Permalink
[tests] Fix failing e2e test for Cassandra storage (#4776)
Browse files Browse the repository at this point in the history
## Which problem is this PR solving?

Resolves #4782
## Description of the changes
- Recently a [PR](#4773) was
raised to run all integration tests against Cassandra while checking
it's [CI for
cassandra](https://github.com/jaegertracing/jaeger/actions/runs/6287799686/job/17072619668)
I found that the some test where failing but CI passed.
- Fixed the script so that if the test fail we get exit code as
non-zero.
- Fixed `TestCassandraStorage/GetLargeSpans` test which was failing due
to older traces not getting cleanup from db.

## How was this change tested?
- run the cassandra script to test it.

## Checklist
- [x] I have read
https://github.com/jaegertracing/jaeger/blob/master/CONTRIBUTING_GUIDELINES.md
- [x] I have signed all commits
- [x] I have added unit tests for the new functionality
- [x] I have run lint and test steps successfully
  - for `jaeger`: `make lint test`
  - for `jaeger-ui`: `yarn lint` and `yarn test`

---------

Signed-off-by: slayer321 <[email protected]>
  • Loading branch information
slayer321 authored Sep 29, 2023
1 parent ab40e2d commit 847b260
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
5 changes: 5 additions & 0 deletions plugin/storage/cassandra/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,3 +217,8 @@ func (f *Factory) Close() error {
}
return f.Options.GetPrimary().TLS.Close()
}

// PrimarySession is used from integration tests to clean database between tests
func (f *Factory) PrimarySession() cassandra.Session {
return f.primarySession
}
18 changes: 16 additions & 2 deletions plugin/storage/integration/cassandra_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/stretchr/testify/require"
"go.uber.org/zap"

dbsession "github.com/jaegertracing/jaeger/pkg/cassandra"
"github.com/jaegertracing/jaeger/pkg/config"
"github.com/jaegertracing/jaeger/pkg/metrics"
"github.com/jaegertracing/jaeger/pkg/testutils"
Expand All @@ -44,12 +45,22 @@ func newCassandraStorageIntegration() *CassandraStorageIntegration {
StorageIntegration: StorageIntegration{
GetDependenciesReturnsSource: true,

Refresh: func() error { return nil },
CleanUp: func() error { return nil },
Refresh: func() error { return nil },
CleanUp: func() error { return nil },
SkipList: []string{"Tags_+_Operation_name_+_Duration_range", "Tags_+_Duration_range", "Tags_+_Operation_name_+_max_Duration", "Tags_+_max_Duration", "Operation_name_+_Duration_range", "Duration_range", "max_Duration"},
},
}
}

func (s *CassandraStorageIntegration) cleanUp(q dbsession.Session) (func() error, error) {
return func() error {
if err := q.Query("TRUNCATE traces").Exec(); err != nil {
return err
}
return nil
}, nil
}

func (s *CassandraStorageIntegration) initializeCassandraFactory(flags []string) (*cassandra.Factory, error) {
s.logger, _ = testutils.NewLogger()
f := cassandra.NewFactory()
Expand Down Expand Up @@ -77,6 +88,9 @@ func (s *CassandraStorageIntegration) initializeCassandra() error {
if s.SpanReader, err = f.CreateSpanReader(); err != nil {
return err
}
if s.CleanUp, err = s.cleanUp(f.PrimarySession()); err != nil {
return err
}
if err = s.initializeDependencyReaderAndWriter(f); err != nil {
return err
}
Expand Down
3 changes: 2 additions & 1 deletion plugin/storage/integration/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ func (s *StorageIntegration) refresh(t *testing.T) {

func (s *StorageIntegration) skipIfNeeded(t *testing.T) {
for _, pat := range s.SkipList {
ok, err := regexp.MatchString(pat, t.Name())
escapedPat := regexp.QuoteMeta(pat)
ok, err := regexp.MatchString(escapedPat, t.Name())
assert.NoError(t, err)
if ok {
t.Skip()
Expand Down
2 changes: 1 addition & 1 deletion scripts/cassandra-integration-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ run_integration_test() {
apply_schema "$2"
STORAGE=cassandra make storage-integration-test
exit_status=$?
trap 'teardown_cassandra ${cid}' EXIT
trap "teardown_cassandra ${cid}" EXIT
}

main() {
Expand Down

0 comments on commit 847b260

Please sign in to comment.