(t *testing.T)
| 135 | } |
| 136 | |
| 137 | func TestBlockSharding(t *testing.T) { |
| 138 | // push a req with some traceID |
| 139 | // cut headblock & write to backend |
| 140 | // search with different shards and check if its respecting the params |
| 141 | r, w, _, _ := testConfig(t, 0) |
| 142 | |
| 143 | ctx, cancel := context.WithCancel(context.Background()) |
| 144 | defer cancel() |
| 145 | |
| 146 | r.EnablePolling(ctx, &mockJobSharder{}, false) |
| 147 | |
| 148 | // create block with known ID |
| 149 | blockID := backend.NewUUID() |
| 150 | wal := w.WAL() |
| 151 | |
| 152 | dec := model.MustNewSegmentDecoder(model.CurrentEncoding) |
| 153 | meta := &backend.BlockMeta{BlockID: blockID, TenantID: testTenantID} |
| 154 | head, err := wal.NewBlock(meta, model.CurrentEncoding) |
| 155 | assert.NoError(t, err) |
| 156 | |
| 157 | // add a trace to the block |
| 158 | id := test.ValidTraceID(nil) |
| 159 | req := test.MakeTrace(1, id) |
| 160 | writeTraceToWal(t, head, dec, id, req, 0, 0) |
| 161 | |
| 162 | // write block to backend |
| 163 | _, err = w.CompleteBlock(ctx, head) |
| 164 | assert.NoError(t, err) |
| 165 | |
| 166 | // poll |
| 167 | r.(*readerWriter).pollBlocklist(ctx) |
| 168 | |
| 169 | // get blockID |
| 170 | blocks := r.(*readerWriter).blocklist.Metas(testTenantID) |
| 171 | assert.Len(t, blocks, 1) |
| 172 | |
| 173 | // check if it respects the blockstart/blockend params - case1: hit |
| 174 | blockStart := uuid.MustParse(BlockIDMin).String() |
| 175 | blockEnd := uuid.MustParse(BlockIDMax).String() |
| 176 | bFound, failedBlocks, err := r.Find(ctx, testTenantID, id, blockStart, blockEnd, 0, 0, common.DefaultSearchOptions()) |
| 177 | assert.NoError(t, err) |
| 178 | assert.Nil(t, failedBlocks) |
| 179 | assert.Greater(t, len(bFound), 0) |
| 180 | assert.True(t, proto.Equal(bFound[0].Trace, req)) |
| 181 | require.Greater(t, bFound[0].Metrics.InspectedBytes, uint64(10000)) |
| 182 | |
| 183 | // check if it respects the blockstart/blockend params - case2: miss |
| 184 | blockStart = uuid.MustParse(BlockIDMin).String() |
| 185 | blockEnd = uuid.MustParse(BlockIDMin).String() |
| 186 | bFound, failedBlocks, err = r.Find(ctx, testTenantID, id, blockStart, blockEnd, 0, 0, common.DefaultSearchOptions()) |
| 187 | assert.NoError(t, err) |
| 188 | assert.Nil(t, failedBlocks) |
| 189 | assert.Len(t, bFound, 0) |
| 190 | } |
| 191 | |
| 192 | func TestNilOnUnknownTenantID(t *testing.T) { |
| 193 | r, _, _, _ := testConfig(t, 0) |
nothing calls this directly
no test coverage detected