@@ -56,6 +56,12 @@ func TestLogSender_Mainline(t *testing.T) {
56
56
loopErr <- err
57
57
}()
58
58
59
+ empty := make (chan error , 1 )
60
+ go func () {
61
+ err := uut .WaitUntilEmpty (ctx )
62
+ empty <- err
63
+ }()
64
+
59
65
// since neither source has even been flushed, it should immediately Flush
60
66
// both, although the order is not controlled
61
67
var logReqs []* proto.BatchCreateLogsRequest
@@ -104,8 +110,11 @@ func TestLogSender_Mainline(t *testing.T) {
104
110
require .Equal (t , proto .Log_DEBUG , req .Logs [0 ].GetLevel ())
105
111
require .Equal (t , t1 , req .Logs [0 ].GetCreatedAt ().AsTime ())
106
112
113
+ err := testutil .RequireRecvCtx (ctx , t , empty )
114
+ require .NoError (t , err )
115
+
107
116
cancel ()
108
- err : = testutil .RequireRecvCtx (testCtx , t , loopErr )
117
+ err = testutil .RequireRecvCtx (testCtx , t , loopErr )
109
118
require .NoError (t , err )
110
119
111
120
// we can still enqueue more logs after SendLoop returns
@@ -363,6 +372,33 @@ func TestLogSender_SendError(t *testing.T) {
363
372
uut .L .Unlock ()
364
373
}
365
374
375
+ func TestLogSender_WaitUntilEmpty_ContextExpired (t * testing.T ) {
376
+ t .Parallel ()
377
+ testCtx := testutil .Context (t , testutil .WaitShort )
378
+ ctx , cancel := context .WithCancel (testCtx )
379
+ logger := slogtest .Make (t , nil ).Leveled (slog .LevelDebug )
380
+ uut := NewLogSender (logger )
381
+
382
+ t0 := dbtime .Now ()
383
+
384
+ ls1 := uuid.UUID {0x11 }
385
+ uut .Enqueue (ls1 , Log {
386
+ CreatedAt : t0 ,
387
+ Output : "test log 0, src 1" ,
388
+ Level : codersdk .LogLevelInfo ,
389
+ })
390
+
391
+ empty := make (chan error , 1 )
392
+ go func () {
393
+ err := uut .WaitUntilEmpty (ctx )
394
+ empty <- err
395
+ }()
396
+
397
+ cancel ()
398
+ err := testutil .RequireRecvCtx (testCtx , t , empty )
399
+ require .ErrorIs (t , err , context .Canceled )
400
+ }
401
+
366
402
type fakeLogDest struct {
367
403
reqs chan * proto.BatchCreateLogsRequest
368
404
resps chan * proto.BatchCreateLogsResponse
0 commit comments