9
9
"net/http"
10
10
"os"
11
11
"strings"
12
+ "sync/atomic"
12
13
"testing"
13
14
"time"
14
15
@@ -22,7 +23,7 @@ import (
22
23
func TestGenerateFromEvents (t * testing.T ) {
23
24
log .SetOutput (ioutil .Discard )
24
25
containerID := "8dfafdbc3a40"
25
- counter := 0
26
+ var counter atomic. Int32
26
27
27
28
eventsResponse := `
28
29
{"status":"start","id":"8dfafdbc3a40","from":"base:latest","time":1374067924}
@@ -38,7 +39,7 @@ func TestGenerateFromEvents(t *testing.T) {
38
39
for rsc .Scan () {
39
40
w .Write ([]byte (rsc .Text ()))
40
41
w .(http.Flusher ).Flush ()
41
- time .Sleep (15 * time .Millisecond )
42
+ time .Sleep (150 * time .Millisecond )
42
43
}
43
44
time .Sleep (500 * time .Millisecond )
44
45
}))
@@ -67,7 +68,7 @@ func TestGenerateFromEvents(t *testing.T) {
67
68
json .NewEncoder (w ).Encode (result )
68
69
}))
69
70
server .CustomHandler (fmt .Sprintf ("/containers/%s/json" , containerID ), http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
70
- counter ++
71
+ counter := counter . Add ( 1 )
71
72
container := docker.Container {
72
73
Name : "docker-gen-test" ,
73
74
ID : containerID ,
@@ -165,13 +166,13 @@ func TestGenerateFromEvents(t *testing.T) {
165
166
Template : tmplFile .Name (),
166
167
Dest : destFiles [2 ].Name (),
167
168
Watch : true ,
168
- Wait : & config.Wait {Min : 20 * time .Millisecond , Max : 25 * time .Millisecond },
169
+ Wait : & config.Wait {Min : 200 * time .Millisecond , Max : 250 * time .Millisecond },
169
170
},
170
171
{
171
172
Template : tmplFile .Name (),
172
173
Dest : destFiles [3 ].Name (),
173
174
Watch : true ,
174
- Wait : & config.Wait {Min : 25 * time .Millisecond , Max : 100 * time .Millisecond },
175
+ Wait : & config.Wait {Min : 250 * time .Millisecond , Max : 1 * time .Second },
175
176
},
176
177
},
177
178
},
@@ -188,12 +189,12 @@ func TestGenerateFromEvents(t *testing.T) {
188
189
189
190
// The counter is incremented in each output file in the following sequence:
190
191
//
191
- // init 0ms 5ms 10ms 15ms 20ms 25ms 30ms 35ms 40ms 45ms 50ms 55ms
192
+ // init 150ms 200ms 250ms 300ms 350ms 400ms 450ms 500ms 550ms 600ms 650ms 700ms
192
193
// ├──────╫──────┼──────┼──────╫──────┼──────┼──────╫──────┼──────┼──────┼──────┼──────┤
193
194
// File0 ├─ 1 ║ ║ ║
194
195
// File1 ├─ 1 ╟─ 2 ╟─ 3 ╟─ 5
195
- // File2 ├─ 1 ╟───── max (25ms ) ─── ║───────────> 4 ╟─────── min (20ms) ─ ─────> 6
196
- // File3 └─ 1 ╟──────────────────> ╟──────────────────> ╟─────────── min (25ms) ─ ────────> 7
196
+ // File2 ├─ 1 ╟───── max (250ms ) ──║───────────> 4 ╟─────── min (200ms) ─────> 6
197
+ // File3 └─ 1 ╟──────────────────> ╟──────────────────> ╟─────────── min (250ms) ────────> 7
197
198
// ┌───╨───┐ ┌───╨──┐ ┌───╨───┐
198
199
// │ start │ │ stop │ │ start │
199
200
// └───────┘ └──────┘ └───────┘
0 commit comments