Codebase list golang-github-go-kit-kit / af784ed
Fix flaky Travis test? Peter Bourgon 8 years ago
1 changed file(s) with 15 addition(s) and 7 deletion(s). Raw diff Collapse all Expand all
8686 runtime.Gosched() // yield to flush
8787
8888 // Travis is annoying
89 deadline := time.Now().Add(100 * time.Millisecond)
90 for buf.String() == "" {
91 if time.Now().After(deadline) {
92 t.Fatal("buffer never got write + flush")
93 }
94 time.Sleep(time.Millisecond)
95 }
89 by(t, time.Second,
90 func() bool { return buf.String() != "" },
91 func() { runtime.Gosched(); time.Sleep(time.Millisecond) },
92 "buffer never got write+flush",
93 )
9694
9795 if want, have := fmt.Sprintf("test_statsd_callback_gauge:%f|g\n", value), buf.String(); want != have {
9896 t.Errorf("want %q, have %q", want, have)
116114 t.Errorf("want %q, have %q", want, have)
117115 }
118116 }
117
118 func by(t *testing.T, d time.Duration, b func() bool, c func(), msg string) {
119 deadline := time.Now().Add(d)
120 for !b() {
121 if time.Now().After(deadline) {
122 t.Fatal(msg)
123 }
124 c()
125 }
126 }