MCPcopy Create free account
hub / github.com/coder/coder / TestLogSender_Batch

Function TestLogSender_Batch

codersdk/agentsdk/logs_internal_test.go:277–325  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

275}
276
277func 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
327func TestLogSender_MaxQueuedLogs(t *testing.T) {
328 t.Parallel()

Callers

nothing calls this directly

Calls 12

EnqueueMethod · 0.95
SendLoopMethod · 0.95
ContextFunction · 0.92
LoggerFunction · 0.92
NowFunction · 0.92
TryReceiveFunction · 0.92
RequireSendFunction · 0.92
newFakeLogDestFunction · 0.85
NewLogSenderFunction · 0.85
LessMethod · 0.80
MarshalMethod · 0.45
EqualMethod · 0.45

Tested by

no test coverage detected