From cfb05acc50164a32ccd9589eec4d674acd308186 Mon Sep 17 00:00:00 2001 From: Ivan Babrou Date: Fri, 8 Jan 2021 23:01:00 -0800 Subject: [PATCH] Add tests to exercise the broken serialization path Signed-off-by: Ivan Babrou --- plugin/storage/memory/memory_test.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/plugin/storage/memory/memory_test.go b/plugin/storage/memory/memory_test.go index 19ad502016a..ef5e499a5e6 100644 --- a/plugin/storage/memory/memory_test.go +++ b/plugin/storage/memory/memory_test.go @@ -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) @@ -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{}) @@ -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