MCPcopy
hub / github.com/grafana/tempo / TestInstanceSearchDoesNotRace

Function TestInstanceSearchDoesNotRace

modules/livestore/instance_search_test.go:769–866  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

767}
768
769func TestInstanceSearchDoesNotRace(t *testing.T) {
770 i, ls := defaultInstanceAndTmpDir(t)
771
772 // add dummy search data
773 tagKey := foo
774 tagValue := bar
775
776 req := &tempopb.SearchRequest{
777 Query: fmt.Sprintf(`{ span.%s = "%s" }`, tagKey, tagValue),
778 }
779
780 end := make(chan struct{})
781 wg := sync.WaitGroup{}
782
783 concurrent := func(f func()) {
784 wg.Add(1)
785 go func() {
786 defer wg.Done()
787 for {
788 select {
789 case <-end:
790 return
791 default:
792 f()
793 }
794 }
795 }()
796 }
797
798 concurrent(func() {
799 id := make([]byte, 16)
800 _, err := crand.Read(id)
801 require.NoError(t, err)
802
803 trace := test.MakeTrace(10, id)
804 traceBytes, err := trace.Marshal()
805 require.NoError(t, err)
806
807 // Create a push request for livestore
808 req := &tempopb.PushBytesRequest{
809 Traces: []tempopb.PreallocBytes{{Slice: traceBytes}},
810 Ids: [][]byte{id},
811 }
812 i.pushBytes(t.Context(), time.Now(), req)
813 })
814
815 concurrent(func() {
816 drained, err := i.cutIdleTraces(t.Context(), true)
817 require.NoError(t, err, "error cutting complete traces")
818 require.True(t, drained, "should drain live traces in one iteration")
819 })
820
821 concurrent(func() {
822 // Cut wal, complete
823 blockID, _ := i.cutBlocks(t.Context(), true)
824 if blockID != uuid.Nil {
825 _, err := i.completeBlock(t.Context(), blockID)
826 require.NoError(t, err)

Callers

nothing calls this directly

Calls 15

MakeTraceFunction · 0.92
defaultInstanceAndTmpDirFunction · 0.85
fFunction · 0.85
cutIdleTracesMethod · 0.80
cutBlocksMethod · 0.80
completeBlockMethod · 0.80
deleteOldBlocksMethod · 0.80
AddMethod · 0.65
DoneMethod · 0.65
ReadMethod · 0.65
MarshalMethod · 0.65
pushBytesMethod · 0.65

Tested by

no test coverage detected