Skip to content

Commit

Permalink
[test] Use correct Context instance with mocks (jaegertracing#4332)
Browse files Browse the repository at this point in the history
## Which problem is this PR solving?
- Should fix jaegertracing#4327

## Short description of the changes
- Test on tip were failing due to mismatch of context types passed to
mocks.

---------

Signed-off-by: Yuri Shkuro <[email protected]>
  • Loading branch information
yurishkuro authored Mar 23, 2023
1 parent 6ab3f01 commit 45d2de2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
2 changes: 1 addition & 1 deletion cmd/ingester/app/processor/span_processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func TestSpanProcessor_Process(t *testing.T) {

message.On("Value").Return(data)
mockUnmarshaller.On("Unmarshal", data).Return(span, nil)
mockWriter.On("WriteSpan", context.Background(), span).
mockWriter.On("WriteSpan", context.TODO(), span).
Return(nil).
Run(func(args mock.Arguments) {
span := args[1].(*model.Span)
Expand Down
13 changes: 5 additions & 8 deletions plugin/storage/es/spanstore/reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,8 @@ func TestSpanReader_multiRead_followUp_query(t *testing.T) {
secondMultiSearch.On("Index", mock.AnythingOfType("string")).Return(secondMultiSearch)
r.client.On("MultiSearch").Return(multiSearchService)

fistMultiSearchMock := firstMultiSearch.On("Do", mock.AnythingOfType("*context.emptyCtx"))
secondMultiSearchMock := secondMultiSearch.On("Do", mock.AnythingOfType("*context.emptyCtx"))
fistMultiSearchMock := firstMultiSearch.On("Do", mock.Anything)
secondMultiSearchMock := secondMultiSearch.On("Do", mock.Anything)

// set TotalHits to two to trigger the follow up query
// the client will return only one span therefore the implementation
Expand Down Expand Up @@ -951,15 +951,15 @@ func mockMultiSearchService(r *spanReaderTest) *mock.Call {
multiSearchService.On("Index", mock.AnythingOfType("string"), mock.AnythingOfType("string"),
mock.AnythingOfType("string"), mock.AnythingOfType("string"), mock.AnythingOfType("string")).Return(multiSearchService)
r.client.On("MultiSearch").Return(multiSearchService)
return multiSearchService.On("Do", mock.AnythingOfType("*context.valueCtx"))
return multiSearchService.On("Do", mock.Anything)
}

func mockArchiveMultiSearchService(r *spanReaderTest, indexName string) *mock.Call {
multiSearchService := &mocks.MultiSearchService{}
multiSearchService.On("Add", mock.Anything, mock.Anything, mock.Anything).Return(multiSearchService)
multiSearchService.On("Index", indexName).Return(multiSearchService)
r.client.On("MultiSearch").Return(multiSearchService)
return multiSearchService.On("Do", mock.AnythingOfType("*context.valueCtx"))
return multiSearchService.On("Do", mock.Anything)
}

// matchTermsAggregation uses reflection to match the size attribute of the TermsAggregation; neither
Expand All @@ -981,10 +981,7 @@ func mockSearchService(r *spanReaderTest) *mock.Call {
searchService.On("Aggregation", stringMatcher(operationsAggregation), mock.MatchedBy(matchTermsAggregation)).Return(searchService)
searchService.On("Aggregation", stringMatcher(traceIDAggregation), mock.AnythingOfType("*elastic.TermsAggregation")).Return(searchService)
r.client.On("Search", mock.AnythingOfType("string"), mock.AnythingOfType("string"), mock.AnythingOfType("string"), mock.AnythingOfType("string"), mock.AnythingOfType("string")).Return(searchService)
return searchService.On("Do", mock.MatchedBy(func(ctx context.Context) bool {
t := reflect.TypeOf(ctx).String()
return t == "*context.valueCtx" || t == "*context.emptyCtx"
}))
return searchService.On("Do", mock.Anything)
}

func TestTraceQueryParameterValidation(t *testing.T) {
Expand Down

0 comments on commit 45d2de2

Please sign in to comment.