Skip to content

Commit

Permalink
Run all integration tests against Cassandra (#4773)
Browse files Browse the repository at this point in the history
## Which problem is this PR solving?
- Turns out we don't run most tests against Cassandra

## Description of the changes
- Enable all tests

## How was this change tested?
- CI

---------

Signed-off-by: Yuri Shkuro <github@ysh.us>
  • Loading branch information
yurishkuro committed Sep 24, 2023
1 parent af70f26 commit 7604158
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 40 deletions.
4 changes: 2 additions & 2 deletions plugin/storage/integration/badgerstore_test.go
Expand Up @@ -59,8 +59,8 @@ func (s *BadgerIntegrationStorage) initialize() error {
logger, _ := testutils.NewLogger()
s.logger = logger

// TODO: remove this flag after badger support returning spanKind when get operations
s.NotSupportSpanKindWithOperation = true
// TODO: remove this badger supports returning spanKind from GetOperations
s.GetOperationsMissingSpanKind = true
return nil
}

Expand Down
39 changes: 5 additions & 34 deletions plugin/storage/integration/cassandra_test.go
Expand Up @@ -16,18 +16,14 @@
package integration

import (
"context"
"errors"
"fmt"
"os"
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.uber.org/zap"

"github.com/jaegertracing/jaeger/model"
"github.com/jaegertracing/jaeger/pkg/config"
"github.com/jaegertracing/jaeger/pkg/metrics"
"github.com/jaegertracing/jaeger/pkg/testutils"
Expand All @@ -46,6 +42,8 @@ type CassandraStorageIntegration struct {
func newCassandraStorageIntegration() *CassandraStorageIntegration {
return &CassandraStorageIntegration{
StorageIntegration: StorageIntegration{
GetDependenciesReturnsSource: true,

Refresh: func() error { return nil },
CleanUp: func() error { return nil },
},
Expand Down Expand Up @@ -100,38 +98,11 @@ func (s *CassandraStorageIntegration) initializeDependencyReaderAndWriter(f *cas
return nil
}

// TODO: Only the cassandra storage currently returns the `Source` field. Once
// all others support the field, we can remove this test and use the existing testGetDependencies.
func (s *StorageIntegration) testCassandraGetDependencies(t *testing.T) {
defer s.cleanUp(t)

expected := []model.DependencyLink{
{
Parent: "hello",
Child: "world",
CallCount: uint64(1),
Source: model.JaegerDependencyLinkSource,
},
{
Parent: "world",
Child: "hello",
CallCount: uint64(3),
Source: model.JaegerDependencyLinkSource,
},
}
require.NoError(t, s.DependencyWriter.WriteDependencies(time.Now(), expected))
s.refresh(t)
actual, err := s.DependencyReader.GetDependencies(context.Background(), time.Now(), 5*time.Minute)
assert.NoError(t, err)
assert.EqualValues(t, expected, actual)
}

func TestCassandraStorage(t *testing.T) {
if os.Getenv("STORAGE") != "cassandra" {
t.Skip("Integration test against Cassandra skipped; set STORAGE env var to cassandra to run this")
}
s1 := newCassandraStorageIntegration()
require.NoError(t, s1.initializeCassandra())
// TODO: Support all other tests.
t.Run("GetDependencies", s1.testCassandraGetDependencies)
s := newCassandraStorageIntegration()
require.NoError(t, s.initializeCassandra())
s.IntegrationTestAll(t)
}
2 changes: 1 addition & 1 deletion plugin/storage/integration/elasticsearch_test.go
Expand Up @@ -112,7 +112,7 @@ func (s *ESStorageIntegration) initializeES(allTagsAsFields, archive bool) error
s.Refresh = s.esRefresh
s.esCleanUp(allTagsAsFields, archive)
// TODO: remove this flag after ES support returning spanKind when get operations
s.NotSupportSpanKindWithOperation = true
s.GetOperationsMissingSpanKind = true
return nil
}

Expand Down
27 changes: 24 additions & 3 deletions plugin/storage/integration/integration.go
Expand Up @@ -22,6 +22,7 @@ import (
"encoding/json"
"fmt"
"regexp"
"sort"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -50,8 +51,13 @@ type StorageIntegration struct {
DependencyWriter dependencystore.Writer
DependencyReader dependencystore.Reader
Fixtures []*QueryFixtures
// TODO: remove this flag after all storage plugins returns spanKind with operationNames
NotSupportSpanKindWithOperation bool

// TODO: remove this after all storage backends return spanKind from GetOperations
GetOperationsMissingSpanKind bool

// TODO: remove this after all storage backends return Source column from GetDependencies
GetDependenciesReturnsSource bool

// List of tests which has to be skipped, it can be regex too.
SkipList []string
// CleanUp() should ensure that the storage backend is clean before another test.
Expand Down Expand Up @@ -122,6 +128,7 @@ func (s *StorageIntegration) testGetServices(t *testing.T) {
found := s.waitForCondition(t, func(t *testing.T) bool {
actual, err := s.SpanReader.GetServices(context.Background())
require.NoError(t, err)
sort.Strings(actual)
return assert.ObjectsAreEqualValues(expected, actual)
})

Expand Down Expand Up @@ -156,7 +163,7 @@ func (s *StorageIntegration) testGetOperations(t *testing.T) {
defer s.cleanUp(t)

var expected []spanstore.Operation
if s.NotSupportSpanKindWithOperation {
if s.GetOperationsMissingSpanKind {
expected = []spanstore.Operation{
{Name: "example-operation-1"},
{Name: "example-operation-3"},
Expand All @@ -178,6 +185,9 @@ func (s *StorageIntegration) testGetOperations(t *testing.T) {
actual, err = s.SpanReader.GetOperations(context.Background(),
spanstore.OperationQueryParameters{ServiceName: "example-service-1"})
require.NoError(t, err)
sort.Slice(actual, func(i, j int) bool {
return actual[i].Name < actual[j].Name
})
return assert.ObjectsAreEqualValues(expected, actual)
})

Expand Down Expand Up @@ -374,22 +384,33 @@ func (s *StorageIntegration) testGetDependencies(t *testing.T) {
s.skipIfNeeded(t)
defer s.cleanUp(t)

source := model.JaegerDependencyLinkSource
if !s.GetDependenciesReturnsSource {
source = ""
}

expected := []model.DependencyLink{
{
Parent: "hello",
Child: "world",
CallCount: uint64(1),
Source: source,
},
{
Parent: "world",
Child: "hello",
CallCount: uint64(3),
Source: source,
},
}

require.NoError(t, s.DependencyWriter.WriteDependencies(time.Now(), expected))
s.refresh(t)
actual, err := s.DependencyReader.GetDependencies(context.Background(), time.Now(), 5*time.Minute)
assert.NoError(t, err)
sort.Slice(actual, func(i, j int) bool {
return actual[i].Parent < actual[j].Parent
})
assert.EqualValues(t, expected, actual)
}

Expand Down

0 comments on commit 7604158

Please sign in to comment.