@@ -10,6 +10,7 @@ import (
10
10
"testing"
11
11
"time"
12
12
13
+ "github.com/zalando/skipper/logging/loggingtest"
13
14
"github.com/zalando/skipper/metrics/metricstest"
14
15
)
15
16
@@ -21,12 +22,20 @@ type testConnection struct {
21
22
type testListener struct {
22
23
sync.Mutex
23
24
closed bool
25
+ failNextTimeout bool
24
26
fail bool
25
27
connsBeforeFail int
26
28
addr net.Addr
27
29
conns chan * testConnection
28
30
}
29
31
32
+ type testError struct {}
33
+
34
+ var errTimeout testError
35
+
36
+ func (err testError ) Error () string { return "test error" }
37
+ func (err testError ) Timeout () bool { return false }
38
+
30
39
func (c * testConnection ) Read ([]byte ) (int , error ) { return 0 , nil }
31
40
func (c * testConnection ) Write ([]byte ) (int , error ) { return 0 , nil }
32
41
func (c * testConnection ) LocalAddr () net.Addr { return nil }
@@ -50,6 +59,11 @@ func (c *testConnection) isClosed() bool {
50
59
51
60
func (l * testListener ) Accept () (net.Conn , error ) {
52
61
62
+ if l .failNextTimeout {
63
+ l .failNextTimeout = false
64
+ return nil , errTimeout
65
+ }
66
+
53
67
if l .fail {
54
68
return nil , errors .New ("listener error" )
55
69
}
@@ -339,6 +353,25 @@ func TestInterface(t *testing.T) {
339
353
}
340
354
})
341
355
356
+ t .Run ("wrapped listener returns timeout error, logs and retries" , func (t * testing.T ) {
357
+ log := loggingtest .New ()
358
+ l , err := listenWith (& testListener {failNextTimeout : true }, Options {
359
+ Log : log ,
360
+ })
361
+ if err != nil {
362
+ t .Fatal (err )
363
+ }
364
+ defer l .Close ()
365
+ conn , err := l .Accept ()
366
+ if err != nil {
367
+ t .Fatal (err )
368
+ }
369
+ defer conn .Close ()
370
+ if err := log .WaitFor (errTimeout .Error (), 120 * time .Millisecond ); err != nil {
371
+ t .Error ("failed to log timeout error" )
372
+ }
373
+ })
374
+
342
375
t .Run ("wrapped permanently fails, returns queued connections and the error" , func (t * testing.T ) {
343
376
m := & metricstest.MockMetrics {}
344
377
l , err := listenWith (& testListener {connsBeforeFail : 3 }, Options {
@@ -947,6 +980,26 @@ func TestTeardown(t *testing.T) {
947
980
948
981
func TestMonitoring (t * testing.T ) {
949
982
983
+ t .Run ("logs the timeout errors" , func (t * testing.T ) {
984
+ log := loggingtest .New ()
985
+ l , err := listenWith (& testListener {failNextTimeout : true }, Options {
986
+ Log : log ,
987
+ })
988
+
989
+ if err != nil {
990
+ t .Fatal (err )
991
+ }
992
+ defer l .Close ()
993
+ conn , err := l .Accept ()
994
+ if err != nil {
995
+ t .Fatal (err )
996
+ }
997
+ defer conn .Close ()
998
+ if err := log .WaitFor (errTimeout .Error (), 120 * time .Millisecond ); err != nil {
999
+ t .Error ("failed to log timeout error" )
1000
+ }
1001
+ })
1002
+
950
1003
t .Run ("updates the gauges for the concurrency and the queue size, measures accept latency" , func (t * testing.T ) {
951
1004
m := & metricstest.MockMetrics {}
952
1005
l , err := listenWith (& testListener {}, Options {
0 commit comments