@@ -17,10 +17,11 @@ import (
17
17
. "github.com/onsi/gomega"
18
18
)
19
19
20
- var string_to_1024_chars = "saljdflajsdssdfsdfljkfkajafjajlköflkjöjaklgljksdjlakljkflkjweljklkwjejlkfekljwlkjefjklwjklsdajkljklwerlkaskldgjksakjekjwrjkljasdjkgfkljwejklrkjlklasdkjlsadjlfjlkadfljkajklsdfjklslkdfjkllkjasdjkflsdlakfjklasldfkjlasdjfkjlsadlfjklaljsafjlslkjawjklerkjljklasjkdfjklwerjljalsdjkflwerjlkwejlkarjklalkklfsdjlfhkjsdfkhsewhkjjasdjfkhwkejrkjahjefkhkasdjhfkashfkjwehfkksadfjaskfkhjdshjfhewkjhasdfjdajskfjwehkfajkankaskjdfasdjhfkkjhjjkasdfjhkjahksdf"
20
+ var string_to_256_chars string
21
21
22
22
func init () {
23
23
syslog .DefaultSendInterval = 100 * time .Millisecond // Modify behavior for tests
24
+ syslog .DefaultBatchSize = 5000
24
25
}
25
26
26
27
var _ = Describe ("HTTPS_batch" , func () {
@@ -34,7 +35,10 @@ var _ = Describe("HTTPS_batch", func() {
34
35
b * syslog.URLBinding
35
36
writer egress.WriteCloser
36
37
)
37
- string_to_1024_chars += string_to_1024_chars
38
+ //With the rest of the syslog, this results in a syslogenvelope of the size 400
39
+ for i := 0 ; i < 256 ; i ++ {
40
+ string_to_256_chars += "a"
41
+ }
38
42
39
43
BeforeEach (func () {
40
44
drain = newBatchMockDrain (200 )
@@ -57,7 +61,7 @@ var _ = Describe("HTTPS_batch", func() {
57
61
Expect (writer .Write (env1 )).To (Succeed ())
58
62
env2 := buildLogEnvelope ("APP" , "2" , "message 2" , loggregator_v2 .Log_OUT )
59
63
Expect (writer .Write (env2 )).To (Succeed ())
60
- time .Sleep (1050 * time .Millisecond )
64
+ time .Sleep (150 * time .Millisecond )
61
65
62
66
Expect (drain .getMessagesSize ()).Should (Equal (2 ))
63
67
expected := & rfc5424.Message {
@@ -87,24 +91,25 @@ var _ = Describe("HTTPS_batch", func() {
87
91
})
88
92
89
93
It ("test batch dispatching with all logs in a given timeframe" , func () {
90
- env1 := buildLogEnvelope ("APP" , "1" , "string to get log to 1024 characters:" + string_to_1024_chars , loggregator_v2 .Log_OUT )
94
+ env1 := buildLogEnvelope ("APP" , "1" , "string to get log to 400 characters:" + string_to_256_chars , loggregator_v2 .Log_OUT )
91
95
for i := 0 ; i < 10 ; i ++ {
92
96
Expect (writer .Write (env1 )).To (Succeed ())
93
- time .Sleep (5 * time .Millisecond )
94
97
}
95
- Expect (drain .getMessagesSize ()).Should (Equal (0 ))
96
- time .Sleep (100 * time .Millisecond )
97
- Expect (drain .getMessagesSize ()).Should (Equal (10 ))
98
+ Consistently (drain .getMessagesSize , 50 * time .Millisecond ).Should (Equal (0 ))
99
+ Eventually (drain .getMessagesSize , 100 * time .Millisecond ).Should (Equal (10 ))
98
100
})
99
101
100
102
It ("test dispatching for batches before timewindow is finished" , func () {
101
- env1 := buildLogEnvelope ("APP" , "1" , "string to get log to 1024 characters:" + string_to_1024_chars , loggregator_v2 .Log_OUT )
102
- for i := 0 ; i < 300 ; i ++ {
103
+ // One envelope has the size of 400byte
104
+ env1 := buildLogEnvelope ("APP" , "1" , "string to get log to 400 characters:" + string_to_256_chars , loggregator_v2 .Log_OUT )
105
+
106
+ for i := 0 ; i < 20 ; i ++ {
103
107
Expect (writer .Write (env1 )).To (Succeed ())
104
108
}
105
- Expect (drain .getMessagesSize ()).Should (Equal (256 ))
106
- time .Sleep (101 * time .Millisecond )
107
- Expect (drain .getMessagesSize ()).Should (Equal (300 ))
109
+ // DefaultBatchSize = 5000byte, 12 * 400byte = 4800byte, 13 * 400byte = 5200byte
110
+ // -> The batch will trigger after 13 messages, and this is not a direct hit to prevent inconsistencies.
111
+ Consistently (drain .getMessagesSize , 50 * time .Millisecond ).Should (Equal (13 ))
112
+ Eventually (drain .getMessagesSize , 100 * time .Millisecond ).Should (Equal (20 ))
108
113
})
109
114
110
115
It ("test for hanging after some ticks" , func () {
@@ -113,10 +118,9 @@ var _ = Describe("HTTPS_batch", func() {
113
118
env1 := buildLogEnvelope ("APP" , "1" , "only a short test message" , loggregator_v2 .Log_OUT )
114
119
for i := 0 ; i < 5 ; i ++ {
115
120
Expect (writer .Write (env1 )).To (Succeed ())
116
- time .Sleep (300 * time .Millisecond )
121
+ time .Sleep (200 * time .Millisecond )
117
122
}
118
- time .Sleep (101 * time .Millisecond )
119
- Expect (drain .getMessagesSize ()).Should (Equal (5 ))
123
+ Eventually (drain .getMessagesSize , 105 * time .Millisecond ).Should (Equal (5 ))
120
124
})
121
125
})
122
126
0 commit comments