Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix flaky tbuffered server test #2635

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions cmd/agent/app/servers/tbuffered_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,13 @@ type fakeTransport struct {

func (t *fakeTransport) Read(p []byte) (n int, err error) {
pkositsyn marked this conversation as resolved.
Show resolved Hide resolved
packet := t.packet.Inc()
if packet > 2 {
if packet > 3 {
// return error once when packet==3, otherwise block
t.wg.Wait()
}
if packet == 2 {
// return some error packet, followed by valid one
return 0, io.ErrNoProgress
}
if packet > 3 {
// don't return error at this moment to avoid flaky test
pkositsyn marked this conversation as resolved.
Show resolved Hide resolved
t.wg.Wait()
yurishkuro marked this conversation as resolved.
Show resolved Hide resolved
return 0, io.EOF
}
for i := range p {
Expand All @@ -128,9 +130,9 @@ func TestTBufferedServer_Metrics(t *testing.T) {
go server.Serve()
defer server.Stop()

// The fakeTransport will allow the server to read exactly two packets and one error.
// The fakeTransport will allow the server to read exactly two packets and one error in between.
// Since we use the server with queue size == 1, the first packet will be
// sent to channel, and the second one dropped.
// sent to channel, the error will be processed and the second valid packet dropped.
pkositsyn marked this conversation as resolved.
Show resolved Hide resolved

packetDropped := false
for i := 0; i < 5000; i++ {
Expand Down