Codebase list golang-github-go-kit-kit / af0ae28
Nicer fix for flaky Travis Peter Bourgon 8 years ago
1 changed file(s) with 6 addition(s) and 8 deletion(s). Raw diff Collapse all Expand all
8686 runtime.Gosched() // yield to flush
8787
8888 // Travis is annoying
89 by(t, time.Second,
90 func() bool { return buf.String() != "" },
91 func() { ch <- time.Now(); runtime.Gosched(); time.Sleep(5 * time.Millisecond) },
92 "buffer never got write+flush",
93 )
89 check := func() bool { return buf.String() != "" }
90 execute := func() { ch <- time.Now(); runtime.Gosched(); time.Sleep(5 * time.Millisecond) }
91 by(t, time.Second, check, execute, "buffer never got write+flush")
9492
9593 if want, have := fmt.Sprintf("test_statsd_callback_gauge:%f|g\n", value), buf.String(); want != have {
9694 t.Errorf("want %q, have %q", want, have)
115113 }
116114 }
117115
118 func by(t *testing.T, d time.Duration, b func() bool, c func(), msg string) {
116 func by(t *testing.T, d time.Duration, check func() bool, execute func(), msg string) {
119117 deadline := time.Now().Add(d)
120 for !b() {
118 for !check() {
121119 if time.Now().After(deadline) {
122120 t.Fatal(msg)
123121 }
124 c()
122 execute()
125123 }
126124 }