99 "net/http"
1010 "os"
1111 "strings"
12+ "sync/atomic"
1213 "testing"
1314 "time"
1415
@@ -22,7 +23,7 @@ import (
2223func TestGenerateFromEvents (t * testing.T ) {
2324 log .SetOutput (ioutil .Discard )
2425 containerID := "8dfafdbc3a40"
25- counter := 0
26+ var counter atomic. Int32
2627
2728 eventsResponse := `
2829{"status":"start","id":"8dfafdbc3a40","from":"base:latest","time":1374067924}
@@ -38,7 +39,7 @@ func TestGenerateFromEvents(t *testing.T) {
3839 for rsc .Scan () {
3940 w .Write ([]byte (rsc .Text ()))
4041 w .(http.Flusher ).Flush ()
41- time .Sleep (15 * time .Millisecond )
42+ time .Sleep (150 * time .Millisecond )
4243 }
4344 time .Sleep (500 * time .Millisecond )
4445 }))
@@ -67,7 +68,7 @@ func TestGenerateFromEvents(t *testing.T) {
6768 json .NewEncoder (w ).Encode (result )
6869 }))
6970 server .CustomHandler (fmt .Sprintf ("/containers/%s/json" , containerID ), http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
70- counter ++
71+ counter := counter . Add ( 1 )
7172 container := docker.Container {
7273 Name : "docker-gen-test" ,
7374 ID : containerID ,
@@ -165,13 +166,13 @@ func TestGenerateFromEvents(t *testing.T) {
165166 Template : tmplFile .Name (),
166167 Dest : destFiles [2 ].Name (),
167168 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 },
169170 },
170171 {
171172 Template : tmplFile .Name (),
172173 Dest : destFiles [3 ].Name (),
173174 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 },
175176 },
176177 },
177178 },
@@ -188,12 +189,12 @@ func TestGenerateFromEvents(t *testing.T) {
188189
189190 // The counter is incremented in each output file in the following sequence:
190191 //
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
192193 // ├──────╫──────┼──────┼──────╫──────┼──────┼──────╫──────┼──────┼──────┼──────┼──────┤
193194 // File0 ├─ 1 ║ ║ ║
194195 // 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
197198 // ┌───╨───┐ ┌───╨──┐ ┌───╨───┐
198199 // │ start │ │ stop │ │ start │
199200 // └───────┘ └──────┘ └───────┘
0 commit comments