(t *testing.T)
| 198 | } |
| 199 | |
| 200 | func TestInstanceBackpressure(t *testing.T) { |
| 201 | instance, ls := defaultInstance(t) |
| 202 | |
| 203 | id1 := test.ValidTraceID(nil) |
| 204 | pushTrace(t.Context(), t, instance, test.MakeTrace(1, id1), id1) |
| 205 | |
| 206 | instance.Cfg.MaxLiveTracesBytes = instance.liveTraces.Size() // Set max size to current live-traces size |
| 207 | |
| 208 | id2 := test.ValidTraceID(nil) |
| 209 | |
| 210 | // Use a channel to coordinate the blocking push operation |
| 211 | pushComplete := make(chan struct{}) |
| 212 | go func() { |
| 213 | defer close(pushComplete) |
| 214 | // Second write will block waiting for the live traces to have room |
| 215 | pushTrace(t.Context(), t, instance, test.MakeTrace(1, id2), id2) |
| 216 | }() |
| 217 | |
| 218 | // Give goroutine time to start and block |
| 219 | time.Sleep(10 * time.Millisecond) |
| 220 | |
| 221 | // First trace is found |
| 222 | res, err := instance.FindByTraceID(t.Context(), id1, true) |
| 223 | require.NoError(t, err) |
| 224 | require.NotNil(t, res) |
| 225 | require.NotNil(t, res.Trace) |
| 226 | require.Greater(t, res.Trace.Size(), 0) |
| 227 | |
| 228 | // Second is not (should be blocked) |
| 229 | res, err = instance.FindByTraceID(t.Context(), id2, true) |
| 230 | require.NoError(t, err) |
| 231 | require.NotNil(t, res) |
| 232 | require.Nil(t, res.Trace) |
| 233 | |
| 234 | // Free up space for the blocked push |
| 235 | drained, cutErr := instance.cutIdleTraces(t.Context(), true) |
| 236 | require.NoError(t, cutErr) |
| 237 | require.True(t, drained, "should drain live traces in one iteration") |
| 238 | |
| 239 | // Wait for push to complete with timeout |
| 240 | select { |
| 241 | case <-pushComplete: |
| 242 | // Push completed successfully |
| 243 | case <-time.After(1 * time.Second): |
| 244 | t.Fatal("push operation did not complete within timeout") |
| 245 | } |
| 246 | |
| 247 | // After cut, second trace is pushed to instance and can be found |
| 248 | res, err = instance.FindByTraceID(t.Context(), id2, true) |
| 249 | require.NoError(t, err) |
| 250 | require.NotNil(t, res) |
| 251 | require.NotNil(t, res.Trace) |
| 252 | require.Greater(t, res.Trace.Size(), 0) |
| 253 | |
| 254 | require.NoError(t, services.StopAndAwaitTerminated(t.Context(), ls)) |
| 255 | } |
| 256 | |
| 257 | func TestInstanceWALBackpressure(t *testing.T) { |
nothing calls this directly
no test coverage detected