@@ -70,11 +70,8 @@ func TestStorageWriter_NormalAppend(t *testing.T) {
7070
7171 ctx , cancel := context .WithCancel (context .Background ())
7272
73- done := make (chan struct {})
74- go func () {
75- defer close (done )
76- w .Run (ctx ) //nolint:errcheck
77- }()
73+ done := make (chan error , 1 )
74+ go func () { done <- w .Run (ctx ) }()
7875
7976 env1 := es .Publish (Envelope {Event : makeEvent ("test.one" )})
8077 env2 := es .Publish (Envelope {Event : makeEvent ("test.two" )})
@@ -84,7 +81,7 @@ func TestStorageWriter_NormalAppend(t *testing.T) {
8481 }, time .Second , 5 * time .Millisecond )
8582
8683 cancel ()
87- <- done
84+ require . ErrorIs ( t , <- done , context . Canceled )
8885
8986 got := backend .envelopes ()
9087 assert .Equal (t , env1 .Seq , got [0 ].Seq )
@@ -104,18 +101,15 @@ func TestStorageWriter_DroppedEvents(t *testing.T) {
104101 }
105102
106103 ctx , cancel := context .WithCancel (context .Background ())
107- done := make (chan struct {})
108- go func () {
109- defer close (done )
110- w .Run (ctx ) //nolint:errcheck
111- }()
104+ done := make (chan error , 1 )
105+ go func () { done <- w .Run (ctx ) }()
112106
113107 require .Eventually (t , func () bool {
114108 return len (backend .envelopes ()) > 0
115109 }, time .Second , 5 * time .Millisecond )
116110
117111 cancel ()
118- <- done
112+ require . ErrorIs ( t , <- done , context . Canceled )
119113
120114 // With ring capacity 4 and 8 publishes, the writer must have skipped at
121115 // least 4 events via a drop gap — so fewer than 8 envelopes landed.
@@ -132,11 +126,8 @@ func TestStorageWriter_AppendError(t *testing.T) {
132126 w := NewStorageWriter (es , backend , slog .Default ())
133127
134128 ctx , cancel := context .WithCancel (context .Background ())
135- done := make (chan struct {})
136- go func () {
137- defer close (done )
138- w .Run (ctx ) //nolint:errcheck
139- }()
129+ done := make (chan error , 1 )
130+ go func () { done <- w .Run (ctx ) }()
140131
141132 // Publish an event that will fail. Wait until the writer has attempted it
142133 // (errCount > 0), then clear the error and publish a second event. The
@@ -153,7 +144,7 @@ func TestStorageWriter_AppendError(t *testing.T) {
153144 }, time .Second , 5 * time .Millisecond )
154145
155146 cancel ()
156- <- done
147+ require . ErrorIs ( t , <- done , context . Canceled )
157148
158149 got := backend .envelopes ()
159150 require .Len (t , got , 1 )
@@ -198,10 +189,11 @@ func TestStorageWriter_DrainFlushesRingAfterRunExits(t *testing.T) {
198189 cancel ()
199190 require .ErrorIs (t , <- done , context .Canceled )
200191
201- // Drain must flush whatever is left in the ring .
192+ // Drain then Close mirrors the real shutdown sequence .
202193 drainCtx , drainCancel := context .WithTimeout (context .Background (), time .Second )
203194 defer drainCancel ()
204195 require .NoError (t , w .Drain (drainCtx ))
196+ require .NoError (t , w .Close (drainCtx ))
205197
206198 got := backend .envelopes ()
207199 // All 8 published events must have been appended across Run + Drain.
0 commit comments