@@ -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 .ErrorIs (t ,err ,context .Canceled )
110
119
111
120
// we can still enqueue more logs after SendLoop returns
@@ -132,6 +141,12 @@ func TestLogSender_LogLimitExceeded(t *testing.T) {
132
141
Level :codersdk .LogLevelInfo ,
133
142
})
134
143
144
+ empty := make (chan error ,1 )
145
+ go func () {
146
+ err := uut .WaitUntilEmpty (ctx )
147
+ empty <- err
148
+ }()
149
+
135
150
loopErr := make (chan error ,1 )
136
151
go func () {
137
152
err := uut .SendLoop (ctx ,fDest )
@@ -146,6 +161,10 @@ func TestLogSender_LogLimitExceeded(t *testing.T) {
146
161
err := testutil .RequireRecvCtx (ctx ,t ,loopErr )
147
162
require .ErrorIs (t ,err ,LogLimitExceededError )
148
163
164
+ // Should also unblock WaitUntilEmpty
165
+ err = testutil .RequireRecvCtx (ctx ,t ,empty )
166
+ require .NoError (t ,err )
167
+
149
168
// we can still enqueue more logs after SendLoop returns, but they don't
150
169
// actually get enqueued
151
170
uut .Enqueue (ls1 ,Log {
@@ -363,6 +382,33 @@ func TestLogSender_SendError(t *testing.T) {
363
382
uut .L .Unlock ()
364
383
}
365
384
385
+ func TestLogSender_WaitUntilEmpty_ContextExpired (t * testing.T ) {
386
+ t .Parallel ()
387
+ testCtx := testutil .Context (t ,testutil .WaitShort )
388
+ ctx ,cancel := context .WithCancel (testCtx )
389
+ logger := slogtest .Make (t ,nil ).Leveled (slog .LevelDebug )
390
+ uut := NewLogSender (logger )
391
+
392
+ t0 := dbtime .Now ()
393
+
394
+ ls1 := uuid.UUID {0x11 }
395
+ uut .Enqueue (ls1 ,Log {
396
+ CreatedAt :t0 ,
397
+ Output :"test log 0, src 1" ,
398
+ Level :codersdk .LogLevelInfo ,
399
+ })
400
+
401
+ empty := make (chan error ,1 )
402
+ go func () {
403
+ err := uut .WaitUntilEmpty (ctx )
404
+ empty <- err
405
+ }()
406
+
407
+ cancel ()
408
+ err := testutil .RequireRecvCtx (testCtx ,t ,empty )
409
+ require .ErrorIs (t ,err ,context .Canceled )
410
+ }
411
+
366
412
type fakeLogDest struct {
367
413
reqs chan * proto.BatchCreateLogsRequest
368
414
resps chan * proto.BatchCreateLogsResponse