Skip to content

Commit

Permalink
Add integration test for ErrTraceNotFound (#2478)
Browse files Browse the repository at this point in the history
Signed-off-by: Yuri Shkuro <[email protected]>
  • Loading branch information
yurishkuro authored Sep 16, 2020
1 parent 0a889e8 commit 37eaced
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
2 changes: 1 addition & 1 deletion plugin/storage/badger/spanstore/read_write_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ func TestFindNothing(t *testing.T) {
assert.Equal(t, 0, len(trs))

tr, err := sr.GetTrace(context.Background(), model.TraceID{High: 0, Low: 0})
assert.NoError(t, err)
assert.Equal(t, spanstore.ErrTraceNotFound, err)
assert.Nil(t, tr)
})
}
Expand Down
2 changes: 1 addition & 1 deletion plugin/storage/badger/spanstore/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func (r *TraceReader) GetTrace(ctx context.Context, traceID model.TraceID) (*mod
return traces[0], nil
}

return nil, nil
return nil, spanstore.ErrTraceNotFound
}

// scanTimeRange returns all the Traces found between startTs and endTs
Expand Down
7 changes: 7 additions & 0 deletions plugin/storage/integration/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,13 @@ func (s *StorageIntegration) testGetTrace(t *testing.T) {
if !assert.True(t, found) {
CompareTraces(t, expected, actual)
}

t.Run("NotFound error", func(t *testing.T) {
fakeTraceID := model.TraceID{High: 0, Low: 0}
trace, err := s.SpanReader.GetTrace(context.Background(), fakeTraceID)
assert.Equal(t, spanstore.ErrTraceNotFound, err)
assert.Nil(t, trace)
})
}

func (s *StorageIntegration) testFindTraces(t *testing.T) {
Expand Down
21 changes: 21 additions & 0 deletions storage/spanstore/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,31 @@ type Writer interface {

// Reader finds and loads traces and other data from storage.
type Reader interface {
// GetTrace retrieves the trace with a given id.
//
// If no spans are stored for this trace, it returns ErrTraceNotFound.
GetTrace(ctx context.Context, traceID model.TraceID) (*model.Trace, error)

// GetServices returns all service names known to the backend from spans
// within its retention period.
GetServices(ctx context.Context) ([]string, error)

// GetOperations returns all operation names for a given service
// known to the backend from spans within its retention period.
GetOperations(ctx context.Context, query OperationQueryParameters) ([]Operation, error)

// FindTraces returns all traces matching query parameters. There's currently
// an implementation-dependent abiguity whether all query filters (such as
// multiple tags) must apply to the same span within a trace, or can be satisfied
// by different spans.
//
// If no matching traces are found, the function returns (nil, nil).
FindTraces(ctx context.Context, query *TraceQueryParameters) ([]*model.Trace, error)

// FindTraceIDs does the same search as FindTraces, but returns only the list
// of matching trace IDs.
//
// If no matching traces are found, the function returns (nil, nil).
FindTraceIDs(ctx context.Context, query *TraceQueryParameters) ([]model.TraceID, error)
}

Expand Down

0 comments on commit 37eaced

Please sign in to comment.