Skip to content

Commit

Permalink
Update unit test
Browse files Browse the repository at this point in the history
Signed-off-by: rim99 <[email protected]>
rim99 committed Nov 10, 2024
1 parent a2677ea commit 74fd1e5
Showing 3 changed files with 51 additions and 22 deletions.
26 changes: 13 additions & 13 deletions cmd/query/app/apiv3/grpc_handler.go
Original file line number Diff line number Diff line change
@@ -33,22 +33,22 @@ func (h *Handler) GetTrace(request *api_v3.GetTraceRequest, stream api_v3.QueryS
if err != nil {
return fmt.Errorf("malform trace ID: %w", err)
}
var startTime time.Time
var endTime time.Time
reqStartTime := request.GetStartTime()
if reqStartTime != nil {
startTime = time.Unix(request.GetStartTime().GetSeconds(), int64(request.GetStartTime().GetNanos()))
}
reqEndTime := request.GetEndTime()
if reqEndTime != nil {
endTime = time.Unix(request.GetEndTime().GetSeconds(), int64(request.GetEndTime().GetNanos()))
}

query := spanstore.TraceGetParameters{
TraceID: traceID,
StartTime: &startTime,
EndTime: &endTime,
TraceID: traceID,
}

startTime := request.GetStartTime()
if startTime != nil {
ts := time.Unix(startTime.GetSeconds(), int64(startTime.GetNanos()))
query.StartTime = &ts
}
endTime := request.GetEndTime()
if endTime != nil {
ts := time.Unix(endTime.GetSeconds(), int64(endTime.GetNanos()))
query.EndTime = &ts
}

trace, err := h.QueryService.GetTrace(stream.Context(), query)
if err != nil {
return fmt.Errorf("cannot retrieve trace: %w", err)
44 changes: 36 additions & 8 deletions cmd/query/app/apiv3/grpc_handler_test.go
Original file line number Diff line number Diff line change
@@ -82,16 +82,44 @@ func TestGetTrace(t *testing.T) {
tsc := newTestServerClient(t)
traceIdLiteral := "156"
traceId, _ := model.TraceIDFromString(traceIdLiteral)
startTime := types.Timestamp{Seconds: 1, Nanos: 2}
endTime := types.Timestamp{Seconds: 3, Nanos: 4}

traceGetStartTime := time.Unix(startTime.GetSeconds(), int64(startTime.GetNanos()))
traceGetEndTime := time.Unix(endTime.GetSeconds(), int64(endTime.GetNanos()))
expectedTraceGetParameters := spanstore.TraceGetParameters{
TraceID: traceId,
}
tsc.reader.On("GetTrace", matchContext, expectedTraceGetParameters).Return(
&model.Trace{
Spans: []*model.Span{
{
OperationName: "foobar",
},
},
}, nil).Once()

getTraceStream, err := tsc.client.GetTrace(context.Background(),
&api_v3.GetTraceRequest{
TraceId: traceIdLiteral,
},
)
require.NoError(t, err)
recv, err := getTraceStream.Recv()
require.NoError(t, err)
td := recv.ToTraces()
require.EqualValues(t, 1, td.SpanCount())
assert.Equal(t, "foobar",
td.ResourceSpans().At(0).ScopeSpans().At(0).Spans().At(0).Name())
}

func TestGetTraceWithTimeWindow(t *testing.T) {
tsc := newTestServerClient(t)
traceIdLiteral := "156"
traceId, _ := model.TraceIDFromString(traceIdLiteral)

start_ts := time.Unix(1, 2)
end_ts := time.Unix(3, 4)
expectedTraceGetParameters := spanstore.TraceGetParameters{
TraceID: traceId,
StartTime: &traceGetStartTime,
EndTime: &traceGetEndTime,
StartTime: &start_ts,
EndTime: &end_ts,
}
tsc.reader.On("GetTrace", matchContext, expectedTraceGetParameters).Return(
&model.Trace{
@@ -105,8 +133,8 @@ func TestGetTrace(t *testing.T) {
getTraceStream, err := tsc.client.GetTrace(context.Background(),
&api_v3.GetTraceRequest{
TraceId: traceIdLiteral,
StartTime: &startTime,
EndTime: &endTime,
StartTime: &types.Timestamp{Seconds: 1, Nanos: 2},
EndTime: &types.Timestamp{Seconds: 3, Nanos: 4},
},
)
require.NoError(t, err)
3 changes: 2 additions & 1 deletion cmd/query/app/server_test.go
Original file line number Diff line number Diff line change
@@ -42,6 +42,7 @@ import (
"github.com/jaegertracing/jaeger/ports"
"github.com/jaegertracing/jaeger/proto-gen/api_v2"
depsmocks "github.com/jaegertracing/jaeger/storage/dependencystore/mocks"
"github.com/jaegertracing/jaeger/storage/spanstore"
spanstoremocks "github.com/jaegertracing/jaeger/storage/spanstore/mocks"
)

@@ -933,7 +934,7 @@ func TestServerHTTP_TracesRequest(t *testing.T) {

tenancyMgr := tenancy.NewManager(&serverOptions.Tenancy)
querySvc := makeQuerySvc()
querySvc.spanReader.On("GetTrace", mock.AnythingOfType("*context.valueCtx"), model.NewTraceID(0, 0x123456abc)).
querySvc.spanReader.On("GetTrace", mock.AnythingOfType("*context.valueCtx"), spanstore.TraceGetParameters{TraceID: model.NewTraceID(0, 0x123456abc)}).
Return(makeMockTrace(t), nil).Once()
telset := initTelSet(zaptest.NewLogger(t), &tracer, healthcheck.New())

0 comments on commit 74fd1e5

Please sign in to comment.