Skip to content

Commit

Permalink
Add tests to exercise the broken serialization path
Browse files Browse the repository at this point in the history
Signed-off-by: Ivan Babrou <[email protected]>
  • Loading branch information
bobrik committed Jan 9, 2021
1 parent f38fe25 commit cfb05ac
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions plugin/storage/memory/memory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,14 @@ var childSpan2_1 = &model.Span{
StartTime: time.Unix(300, 0),
}

// This kind of trace cannot be serialized
var nonSerializableSpan = &model.Span{
Process: &model.Process{
ServiceName: "naughtyService",
},
StartTime: time.Date(0, 0, 0, 0, 0, 0, 0, time.UTC),
}

func withPopulatedMemoryStore(f func(store *Store)) {
memStore := NewStore()
memStore.WriteSpan(context.Background(), testingSpan)
Expand Down Expand Up @@ -228,6 +236,16 @@ func TestStoreGetAndMutateTrace(t *testing.T) {
})
}

func TestStoreGetTraceError(t *testing.T) {
withPopulatedMemoryStore(func(store *Store) {
store.traces[testingSpan.TraceID] = &model.Trace{
Spans: []*model.Span{nonSerializableSpan},
}
_, err := store.GetTrace(context.Background(), testingSpan.TraceID)
assert.Error(t, err)
})
}

func TestStoreGetTraceFailure(t *testing.T) {
withPopulatedMemoryStore(func(store *Store) {
trace, err := store.GetTrace(context.Background(), model.TraceID{})
Expand Down Expand Up @@ -300,6 +318,15 @@ func TestStoreGetEmptyTraceSet(t *testing.T) {
})
}

func TestStoreFindTracesError(t *testing.T) {
withPopulatedMemoryStore(func(store *Store) {
err := store.WriteSpan(context.Background(), nonSerializableSpan)
assert.NoError(t, err)
_, err = store.FindTraces(context.Background(), &spanstore.TraceQueryParameters{ServiceName: "naughtyService"})
assert.Error(t, err)
})
}

func TestStoreFindTracesLimitGetsMostRecent(t *testing.T) {
storeSize, querySize := 100, 10

Expand Down

0 comments on commit cfb05ac

Please sign in to comment.