(t *testing.T)
| 275 | } |
| 276 | |
| 277 | func TestLogSender_Batch(t *testing.T) { |
| 278 | t.Parallel() |
| 279 | testCtx := testutil.Context(t, testutil.WaitShort) |
| 280 | ctx, cancel := context.WithCancel(testCtx) |
| 281 | logger := testutil.Logger(t) |
| 282 | fDest := newFakeLogDest() |
| 283 | uut := NewLogSender(logger) |
| 284 | |
| 285 | t0 := dbtime.Now() |
| 286 | ls1 := uuid.UUID{0x11} |
| 287 | var logs []Log |
| 288 | for i := 0; i < 60000; i++ { |
| 289 | logs = append(logs, Log{ |
| 290 | CreatedAt: t0, |
| 291 | Output: "r", |
| 292 | Level: codersdk.LogLevelInfo, |
| 293 | }) |
| 294 | } |
| 295 | uut.Enqueue(ls1, logs...) |
| 296 | |
| 297 | loopErr := make(chan error, 1) |
| 298 | go func() { |
| 299 | err := uut.SendLoop(ctx, fDest) |
| 300 | loopErr <- err |
| 301 | }() |
| 302 | |
| 303 | // with 60k logs, we should split into two updates to avoid going over 1MiB, since each log |
| 304 | // is about 21 bytes. |
| 305 | gotLogs := 0 |
| 306 | req := testutil.TryReceive(ctx, t, fDest.reqs) |
| 307 | require.NotNil(t, req) |
| 308 | gotLogs += len(req.Logs) |
| 309 | wire, err := protobuf.Marshal(req) |
| 310 | require.NoError(t, err) |
| 311 | require.Less(t, len(wire), maxBytesPerBatch, "wire should not exceed 1MiB") |
| 312 | testutil.RequireSend(ctx, t, fDest.resps, &proto.BatchCreateLogsResponse{}) |
| 313 | req = testutil.TryReceive(ctx, t, fDest.reqs) |
| 314 | require.NotNil(t, req) |
| 315 | gotLogs += len(req.Logs) |
| 316 | wire, err = protobuf.Marshal(req) |
| 317 | require.NoError(t, err) |
| 318 | require.Less(t, len(wire), maxBytesPerBatch, "wire should not exceed 1MiB") |
| 319 | require.Equal(t, 60000, gotLogs) |
| 320 | testutil.RequireSend(ctx, t, fDest.resps, &proto.BatchCreateLogsResponse{}) |
| 321 | |
| 322 | cancel() |
| 323 | err = testutil.TryReceive(testCtx, t, loopErr) |
| 324 | require.ErrorIs(t, err, context.Canceled) |
| 325 | } |
| 326 | |
| 327 | func TestLogSender_MaxQueuedLogs(t *testing.T) { |
| 328 | t.Parallel() |
nothing calls this directly
no test coverage detected