Skip to content

Commit

Permalink
Fix Unit Tests
Browse files Browse the repository at this point in the history
Signed-off-by: Mahad Zaryab <[email protected]>
  • Loading branch information
mahadzaryab1 committed Jan 8, 2025
1 parent fcd9fe9 commit 67145ac
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 86 deletions.
75 changes: 12 additions & 63 deletions plugin/storage/es/spanstore/reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func withSpanReader(t *testing.T, fn func(r *spanReaderTest)) {
fn(r)
}

func withArchiveSpanReader(t *testing.T, readAlias bool, fn func(r *spanReaderTest)) {
func withArchiveSpanReader(t *testing.T, fn func(r *spanReaderTest)) {
client := &mocks.Client{}
tracer, exp, closer := tracerProvider(t)
defer closer()
Expand All @@ -134,8 +134,7 @@ func withArchiveSpanReader(t *testing.T, readAlias bool, fn func(r *spanReaderTe
Tracer: tracer.Tracer("test"),
MaxSpanAge: 0,
TagDotReplacement: "@",
Archive: true,
UseReadWriteAliases: readAlias,
UseReadWriteAliases: true,
}),
}
fn(r)
Expand Down Expand Up @@ -199,7 +198,6 @@ func TestSpanReaderIndices(t *testing.T) {
}{
{
params: SpanReaderParams{
Archive: false,
SpanIndex: spanIndexOpts,
ServiceIndex: serviceIndexOpts,
},
Expand All @@ -213,7 +211,6 @@ func TestSpanReaderIndices(t *testing.T) {
},
{
params: SpanReaderParams{
Archive: false,
SpanIndex: spanIndexOpts,
ServiceIndex: serviceIndexOpts,
IndexPrefix: "foo:",
Expand All @@ -226,29 +223,10 @@ func TestSpanReaderIndices(t *testing.T) {
},
indices: []string{"foo:-" + spanIndexBaseName + "read", "foo:-" + serviceIndexBaseName + "read"},
},
{
params: SpanReaderParams{
Archive: true,
},
indices: []string{spanIndexBaseName + archiveIndexSuffix, serviceIndexBaseName + archiveIndexSuffix},
},
{
params: SpanReaderParams{
SpanIndex: spanIndexOpts, ServiceIndex: serviceIndexOpts, IndexPrefix: "foo:", Archive: true,
},
indices: []string{"foo:" + config.IndexPrefixSeparator + spanIndexBaseName + archiveIndexSuffix, "foo:" + config.IndexPrefixSeparator + serviceIndexBaseName + archiveIndexSuffix},
},
{
params: SpanReaderParams{
SpanIndex: spanIndexOpts, ServiceIndex: serviceIndexOpts, IndexPrefix: "foo:", Archive: true, UseReadWriteAliases: true,
},
indices: []string{"foo:" + config.IndexPrefixSeparator + spanIndexBaseName + archiveReadIndexSuffix, "foo:" + config.IndexPrefixSeparator + serviceIndexBaseName + archiveReadIndexSuffix},
},
{
params: SpanReaderParams{
SpanIndex: spanIndexOpts,
ServiceIndex: serviceIndexOpts,
Archive: false,
RemoteReadClusters: []string{"cluster_one", "cluster_two"},
},
indices: []string{
Expand All @@ -262,20 +240,7 @@ func TestSpanReaderIndices(t *testing.T) {
},
{
params: SpanReaderParams{
Archive: true, RemoteReadClusters: []string{"cluster_one", "cluster_two"},
},
indices: []string{
spanIndexBaseName + archiveIndexSuffix,
"cluster_one:" + spanIndexBaseName + archiveIndexSuffix,
"cluster_two:" + spanIndexBaseName + archiveIndexSuffix,
serviceIndexBaseName + archiveIndexSuffix,
"cluster_one:" + serviceIndexBaseName + archiveIndexSuffix,
"cluster_two:" + serviceIndexBaseName + archiveIndexSuffix,
},
},
{
params: SpanReaderParams{
Archive: false, UseReadWriteAliases: true, RemoteReadClusters: []string{"cluster_one", "cluster_two"},
UseReadWriteAliases: true, RemoteReadClusters: []string{"cluster_one", "cluster_two"},
},
indices: []string{
spanIndexBaseName + "read",
Expand All @@ -288,15 +253,15 @@ func TestSpanReaderIndices(t *testing.T) {
},
{
params: SpanReaderParams{
Archive: true, UseReadWriteAliases: true, RemoteReadClusters: []string{"cluster_one", "cluster_two"},
UseReadWriteAliases: true, RemoteReadClusters: []string{"cluster_one", "cluster_two"},
},
indices: []string{
spanIndexBaseName + archiveReadIndexSuffix,
"cluster_one:" + spanIndexBaseName + archiveReadIndexSuffix,
"cluster_two:" + spanIndexBaseName + archiveReadIndexSuffix,
serviceIndexBaseName + archiveReadIndexSuffix,
"cluster_one:" + serviceIndexBaseName + archiveReadIndexSuffix,
"cluster_two:" + serviceIndexBaseName + archiveReadIndexSuffix,
spanIndexBaseName + "read",
"cluster_one:" + spanIndexBaseName + "read",
"cluster_two:" + spanIndexBaseName + "read",
serviceIndexBaseName + "read",
"cluster_one:" + serviceIndexBaseName + "read",
"cluster_two:" + serviceIndexBaseName + "read",
},
},
}
Expand Down Expand Up @@ -1267,26 +1232,10 @@ func TestSpanReader_GetEmptyIndex(t *testing.T) {
}

func TestSpanReader_ArchiveTraces(t *testing.T) {
withArchiveSpanReader(t, false, func(r *spanReaderTest) {
mockSearchService(r).
Return(&elastic.SearchResult{}, nil)
mockArchiveMultiSearchService(r, "jaeger-span-archive").
Return(&elastic.MultiSearchResult{
Responses: []*elastic.SearchResult{},
}, nil)
query := spanstore.GetTraceParameters{}
trace, err := r.reader.GetTrace(context.Background(), query)
require.NotEmpty(t, r.traceBuffer.GetSpans(), "Spans recorded")
require.Nil(t, trace)
require.EqualError(t, err, "trace not found")
})
}

func TestSpanReader_ArchiveTraces_ReadAlias(t *testing.T) {
withArchiveSpanReader(t, true, func(r *spanReaderTest) {
withArchiveSpanReader(t, func(r *spanReaderTest) {
mockSearchService(r).
Return(&elastic.SearchResult{}, nil)
mockArchiveMultiSearchService(r, "jaeger-span-archive-read").
mockArchiveMultiSearchService(r, "jaeger-span-read").
Return(&elastic.MultiSearchResult{
Responses: []*elastic.SearchResult{},
}, nil)
Expand Down
25 changes: 2 additions & 23 deletions plugin/storage/es/spanstore/writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func TestSpanWriterIndices(t *testing.T) {
{
params: SpanWriterParams{
Client: clientFn, Logger: logger, MetricsFactory: metricsFactory,
SpanIndex: spanIndexOpts, ServiceIndex: serviceIndexOpts, Archive: false,
SpanIndex: spanIndexOpts, ServiceIndex: serviceIndexOpts,
},
indices: []string{spanIndexBaseName + spanDataLayoutFormat, serviceIndexBaseName + serviceDataLayoutFormat},
},
Expand All @@ -88,7 +88,7 @@ func TestSpanWriterIndices(t *testing.T) {
{
params: SpanWriterParams{
Client: clientFn, Logger: logger, MetricsFactory: metricsFactory,
SpanIndex: spanIndexOpts, ServiceIndex: serviceIndexOpts, IndexPrefix: "foo:", Archive: false,
SpanIndex: spanIndexOpts, ServiceIndex: serviceIndexOpts, IndexPrefix: "foo:",
},
indices: []string{"foo:" + config.IndexPrefixSeparator + spanIndexBaseName + spanDataLayoutFormat, "foo:" + config.IndexPrefixSeparator + serviceIndexBaseName + serviceDataLayoutFormat},
},
Expand All @@ -99,27 +99,6 @@ func TestSpanWriterIndices(t *testing.T) {
},
indices: []string{"foo:-" + spanIndexBaseName + "write", "foo:-" + serviceIndexBaseName + "write"},
},
{
params: SpanWriterParams{
Client: clientFn, Logger: logger, MetricsFactory: metricsFactory,
SpanIndex: spanIndexOpts, ServiceIndex: serviceIndexOpts, Archive: true,
},
indices: []string{spanIndexBaseName + archiveIndexSuffix, ""},
},
{
params: SpanWriterParams{
Client: clientFn, Logger: logger, MetricsFactory: metricsFactory,
SpanIndex: spanIndexOpts, ServiceIndex: serviceIndexOpts, IndexPrefix: "foo:", Archive: true,
},
indices: []string{"foo:" + config.IndexPrefixSeparator + spanIndexBaseName + archiveIndexSuffix, ""},
},
{
params: SpanWriterParams{
Client: clientFn, Logger: logger, MetricsFactory: metricsFactory,
SpanIndex: spanIndexOpts, ServiceIndex: serviceIndexOpts, IndexPrefix: "foo:", Archive: true, UseReadWriteAliases: true,
},
indices: []string{"foo:" + config.IndexPrefixSeparator + spanIndexBaseName + archiveWriteIndexSuffix, ""},
},
}
for _, testCase := range testCases {
w := NewSpanWriter(testCase.params)
Expand Down

0 comments on commit 67145ac

Please sign in to comment.