@@ -17,7 +17,14 @@ import (
17
17
. "github.com/onsi/gomega"
18
18
)
19
19
20
- var string_to_1024_chars = "saljdflajsdssdfsdfljkfkajafjajlköflkjöjaklgljksdjlakljkflkjweljklkwjejlkfekljwlkjefjklwjklsdajkljklwerlkaskldgjksakjekjwrjkljasdjkgfkljwejklrkjlklasdkjlsadjlfjlkadfljkajklsdfjklslkdfjkllkjasdjkflsdlakfjklasldfkjlasdjfkjlsadlfjklaljsafjlslkjawjklerkjljklasjkdfjklwerjljalsdjkflwerjlkwejlkarjklalkklfsdjlfhkjsdfkhsewhkjjasdjfkhwkejrkjahjefkhkasdjhfkashfkjwehfkksadfjaskfkhjdshjfhewkjhasdfjdajskfjwehkfajkankaskjdfasdjhfkkjhjjkasdfjhkjahksdf"
20
+ var stringTo256Chars string
21
+
22
+ func init () {
23
+ //With the rest of the syslog, this results in a syslogenvelope of the size 400
24
+ for i := 0 ; i < 256 ; i ++ {
25
+ stringTo256Chars += "a"
26
+ }
27
+ }
21
28
22
29
var _ = Describe ("HTTPS_batch" , func () {
23
30
var (
@@ -30,10 +37,10 @@ var _ = Describe("HTTPS_batch", func() {
30
37
b * syslog.URLBinding
31
38
writer egress.WriteCloser
32
39
)
33
- string_to_1024_chars += string_to_1024_chars
34
40
35
41
BeforeEach (func () {
36
42
drain = newBatchMockDrain (200 )
43
+ drain .Reset ()
37
44
b = buildURLBinding (
38
45
drain .URL ,
39
46
"test-app-id" ,
@@ -45,6 +52,8 @@ var _ = Describe("HTTPS_batch", func() {
45
52
skipSSLTLSConfig ,
46
53
& metricsHelpers.SpyMetric {},
47
54
c ,
55
+ syslog .WithBatchSize (5000 ),
56
+ syslog .WithSendInterval (100 * time .Millisecond ),
48
57
)
49
58
})
50
59
@@ -53,7 +62,7 @@ var _ = Describe("HTTPS_batch", func() {
53
62
Expect (writer .Write (env1 )).To (Succeed ())
54
63
env2 := buildLogEnvelope ("APP" , "2" , "message 2" , loggregator_v2 .Log_OUT )
55
64
Expect (writer .Write (env2 )).To (Succeed ())
56
- time .Sleep (1050 * time .Millisecond )
65
+ time .Sleep (150 * time .Millisecond )
57
66
58
67
Expect (drain .getMessagesSize ()).Should (Equal (2 ))
59
68
expected := & rfc5424.Message {
@@ -83,24 +92,36 @@ var _ = Describe("HTTPS_batch", func() {
83
92
})
84
93
85
94
It ("test batch dispatching with all logs in a given timeframe" , func () {
86
- env1 := buildLogEnvelope ("APP" , "1" , "string to get log to 1024 characters:" + string_to_1024_chars , loggregator_v2 .Log_OUT )
95
+ env1 := buildLogEnvelope ("APP" , "1" , "string to get log to 400 characters:" + stringTo256Chars , loggregator_v2 .Log_OUT )
87
96
for i := 0 ; i < 10 ; i ++ {
88
97
Expect (writer .Write (env1 )).To (Succeed ())
89
- time .Sleep (99 * time .Millisecond )
90
98
}
91
- Expect (drain .getMessagesSize ()).Should (Equal (0 ))
92
- time .Sleep (100 * time .Millisecond )
93
- Expect (drain .getMessagesSize ()).Should (Equal (10 ))
99
+ Expect (drain .getMessagesSize ()).To (Equal (0 ))
100
+ Eventually (drain .getMessagesSize , 180 * time .Millisecond ).Should (Equal (10 ))
94
101
})
95
102
96
- It ("probabilistic test for race condition" , func () {
97
- env1 := buildLogEnvelope ("APP" , "1" , "string to get log to 1024 characters:" + string_to_1024_chars , loggregator_v2 .Log_OUT )
98
- for i := 0 ; i < 10 ; i ++ {
103
+ It ("test dispatching for batches before timewindow is finished" , func () {
104
+ // One envelope has the size of 400byte
105
+ env1 := buildLogEnvelope ("APP" , "1" , "string to get log to 400 characters:" + stringTo256Chars , loggregator_v2 .Log_OUT )
106
+
107
+ for i := 0 ; i < 20 ; i ++ {
99
108
Expect (writer .Write (env1 )).To (Succeed ())
100
- time .Sleep (99 * time .Millisecond )
101
109
}
102
- time .Sleep (100 * time .Millisecond )
103
- Expect (drain .getMessagesSize ()).Should (Equal (10 ))
110
+ // DefaultBatchSize = 5000byte, 12 * 400byte = 4800byte, 13 * 400byte = 5200byte
111
+ // -> The batch will trigger after 13 messages, and this is not a direct hit to prevent inconsistencies.
112
+ Eventually (drain .getMessagesSize , 50 * time .Millisecond ).Should (Equal (13 ))
113
+ Eventually (drain .getMessagesSize , 120 * time .Millisecond ).Should (Equal (20 ))
114
+ })
115
+
116
+ It ("test for hanging after some ticks" , func () {
117
+ // This test will not succeed on the timer based implementation,
118
+ // it works fine with a ticker based implementation.
119
+ env1 := buildLogEnvelope ("APP" , "1" , "only a short test message" , loggregator_v2 .Log_OUT )
120
+ for i := 0 ; i < 5 ; i ++ {
121
+ Expect (writer .Write (env1 )).To (Succeed ())
122
+ time .Sleep (220 * time .Millisecond ) // this sleeps at least 2 ticks, to trigger once without events
123
+ }
124
+ Eventually (drain .getMessagesSize , 120 * time .Millisecond ).Should (Equal (5 ))
104
125
})
105
126
})
106
127
@@ -112,8 +133,6 @@ func newBatchMockDrain(status int) *SpyDrain {
112
133
Expect (err ).ToNot (HaveOccurred ())
113
134
defer r .Body .Close ()
114
135
115
- println (body )
116
-
117
136
message := & rfc5424.Message {}
118
137
119
138
messages := bytes .SplitAfter (body , []byte ("\n " ))
0 commit comments