@@ -21,7 +21,6 @@ import (
2121 "os"
2222 "path/filepath"
2323 "testing"
24- "time"
2524
2625 "github.com/sirupsen/logrus"
2726 "github.com/stretchr/testify/require"
@@ -170,36 +169,32 @@ func TestSaveLoadConfig(t *testing.T) {
170169 os .RemoveAll (configDir )
171170}
172171
173- func TestAsyncTelemetryHook_Close (t * testing.T ) {
174- t .Skip ("We no longer ensure 100% delivery. To not block, we drop messages when they come in faster than the network sends them." )
175- a := require .New (t )
176- t .Parallel ()
177-
172+ func TestAsyncTelemetryHook_CloseDrop (t * testing.T ) {
178173 const entryCount = 100
179174
175+ filling := make (chan struct {})
176+
180177 testHook := makeMockTelemetryHook (logrus .DebugLevel )
181178 testHook .cb = func (entry * logrus.Entry ) {
182- // Inject a delay to ensure we buffer entries
183- time .Sleep (1 * time .Millisecond )
179+ <- filling // Block while filling
184180 }
185181 hook := createAsyncHook (& testHook , 4 , entryCount )
182+ hook .ready = true
186183 for i := 0 ; i < entryCount ; i ++ {
187184 entry := logrus.Entry {
188185 Level : logrus .ErrorLevel ,
189186 }
190187 hook .Fire (& entry )
191188 }
192189
190+ close (filling )
193191 hook .Close ()
194192
195- a .Equal (entryCount , len (testHook .entries ()))
193+ // To not block, we drop messages when they come in faster than the network sends them.
194+ require .Less (t , len (testHook .entries ()), entryCount )
196195}
197196
198197func TestAsyncTelemetryHook_QueueDepth (t * testing.T ) {
199- t .Skip ("flakey test can fail on slow test systems" )
200- a := require .New (t )
201- t .Parallel ()
202-
203198 const entryCount = 100
204199 const maxDepth = 10
205200
@@ -211,6 +206,7 @@ func TestAsyncTelemetryHook_QueueDepth(t *testing.T) {
211206 }
212207
213208 hook := createAsyncHook (& testHook , entryCount , maxDepth )
209+ hook .ready = true
214210 for i := 0 ; i < entryCount ; i ++ {
215211 entry := logrus.Entry {
216212 Level : logrus .ErrorLevel ,
@@ -221,5 +217,5 @@ func TestAsyncTelemetryHook_QueueDepth(t *testing.T) {
221217 close (filling )
222218 hook .Close ()
223219
224- a .Equal (maxDepth , len (testHook .entries ()))
220+ require .Equal (t , maxDepth , len (testHook .entries ()))
225221}
0 commit comments