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

Function TestIterateBlocksRecoversPanic

modules/livestore/instance_search_test.go:1047–1105  ·  modules/livestore/instance_search_test.go::TestIterateBlocksRecoversPanic
(t *testing.T)

Source from the content-addressed store, hash-verified

1045}
1046
1047func TestIterateBlocksRecoversPanic(t *testing.T) {
1048 for _, tc := range []struct {
1049 name string
1050 populate func(t *testing.T, i *instance)
1051 }{
1052 {
1053 name: "head block",
1054 populate: func(t *testing.T, i *instance) {
1055 _, _, _, _ = writeTracesForSearch(t, i, "", foo, bar, false, false)
1056 },
1057 },
1058 {
1059 name: "wal block",
1060 populate: func(t *testing.T, i *instance) {
1061 _, _, _, _ = writeTracesForSearch(t, i, "", foo, bar, false, false)
1062 blockID, err := i.cutBlocks(t.Context(), true)
1063 require.NoError(t, err)
1064 require.NotEqual(t, uuid.Nil, blockID)
1065 i.blocksMtx.Lock()
1066 i.blocks.Store(i.blocks.Load().withHeadBlock(nil))
1067 i.blocksMtx.Unlock()
1068 },
1069 },
1070 {
1071 name: "complete block",
1072 populate: func(t *testing.T, i *instance) {
1073 _, _, _, _ = writeTracesForSearch(t, i, "", foo, bar, false, false)
1074 blockID, err := i.cutBlocks(t.Context(), true)
1075 require.NoError(t, err)
1076 require.NotEqual(t, uuid.Nil, blockID)
1077 _, err = i.completeBlock(t.Context(), blockID)
1078 require.NoError(t, err)
1079 i.blocksMtx.Lock()
1080 i.blocks.Store(i.blocks.Load().withHeadBlock(nil))
1081 i.blocksMtx.Unlock()
1082 },
1083 },
1084 } {
1085 t.Run(tc.name, func(t *testing.T) {
1086 i, ls := defaultInstanceAndTmpDir(t)
1087 defer func() {
1088 err := services.StopAndAwaitTerminated(t.Context(), ls)
1089 if err != nil && !errors.Is(err, context.Canceled) {
1090 require.NoError(t, err)
1091 }
1092 }()
1093
1094 tc.populate(t, i)
1095
1096 panicFn := func(_ context.Context, _ *backend.BlockMeta, _ block) error {
1097 panic("simulated parquet ByteArray panic")
1098 }
1099
1100 err := i.iterateBlocks(t.Context(), time.Unix(0, 0), time.Unix(0, 0), panicFn)
1101 require.Error(t, err, "iterateBlocks should return an error rather than crash on panic")
1102 require.Contains(t, err.Error(), "panic")
1103 })
1104 }

Callers

nothing calls this directly

Calls 11

writeTracesForSearchFunction · 0.85
defaultInstanceAndTmpDirFunction · 0.85
cutBlocksMethod · 0.80
withHeadBlockMethod · 0.80
completeBlockMethod · 0.80
populateMethod · 0.80
iterateBlocksMethod · 0.80
ContextMethod · 0.65
StoreMethod · 0.65
ErrorMethod · 0.65
RunMethod · 0.45

Tested by

no test coverage detected