Fix flaky Travis test?
Peter Bourgon
8 years ago
86 | 86 | runtime.Gosched() // yield to flush |
87 | 87 | |
88 | 88 | // 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 | ) | |
96 | 94 | |
97 | 95 | if want, have := fmt.Sprintf("test_statsd_callback_gauge:%f|g\n", value), buf.String(); want != have { |
98 | 96 | t.Errorf("want %q, have %q", want, have) |
116 | 114 | t.Errorf("want %q, have %q", want, have) |
117 | 115 | } |
118 | 116 | } |
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 | } |