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

Deflake transport timeout case #14861

Merged
merged 2 commits into from
Nov 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion client/pkg/transport/timeout_dialer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func TestReadWriteTimeoutDialer(t *testing.T) {
}

if operr, ok := err.(*net.OpError); !ok || operr.Op != "read" || !operr.Timeout() {
t.Errorf("err = %v, want write i/o timeout error", err)
t.Errorf("err = %v, want read i/o timeout error", err)
}
}

Expand Down
26 changes: 14 additions & 12 deletions client/pkg/transport/timeout_listener_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,23 @@ func TestWriteReadTimeoutListener(t *testing.T) {
writeTimeout: 10 * time.Millisecond,
readTimeout: 10 * time.Millisecond,
}
stop := make(chan struct{}, 1)

blocker := func() {
blocker := func(stopCh <-chan struct{}) {
conn, derr := net.Dial("tcp", ln.Addr().String())
if derr != nil {
t.Errorf("unexpected dail error: %v", derr)
}
defer conn.Close()
// block the receiver until the writer timeout
<-stop
<-stopCh
}
go blocker()

writerStopCh := make(chan struct{}, 1)
go blocker(writerStopCh)

conn, err := wln.Accept()
if err != nil {
stop <- struct{}{}
writerStopCh <- struct{}{}
t.Fatalf("unexpected accept error: %v", err)
}
defer conn.Close()
Expand All @@ -79,20 +80,21 @@ func TestWriteReadTimeoutListener(t *testing.T) {
case <-done:
// It waits 1s more to avoid delay in low-end system.
case <-time.After(wln.writeTimeout*10 + time.Second):
stop <- struct{}{}
writerStopCh <- struct{}{}
t.Fatal("wait timeout")
}

if operr, ok := err.(*net.OpError); !ok || operr.Op != "write" || !operr.Timeout() {
t.Errorf("err = %v, want write i/o timeout error", err)
}
stop <- struct{}{}
writerStopCh <- struct{}{}

go blocker()
readerStopCh := make(chan struct{}, 1)
go blocker(readerStopCh)

conn, err = wln.Accept()
if err != nil {
stop <- struct{}{}
readerStopCh <- struct{}{}
t.Fatalf("unexpected accept error: %v", err)
}
buf := make([]byte, 10)
Expand All @@ -105,12 +107,12 @@ func TestWriteReadTimeoutListener(t *testing.T) {
select {
case <-done:
case <-time.After(wln.readTimeout * 10):
stop <- struct{}{}
readerStopCh <- struct{}{}
t.Fatal("wait timeout")
}

if operr, ok := err.(*net.OpError); !ok || operr.Op != "read" || !operr.Timeout() {
t.Errorf("err = %v, want write i/o timeout error", err)
t.Errorf("err = %v, want read i/o timeout error", err)
}
stop <- struct{}{}
readerStopCh <- struct{}{}
}