Skip to content

Commit 802aa24

Browse files
committed
tests: fix flaky TestFdDialer_Dial_requirements
It seems that a connection's file descriptor is not always fully ready after the connection is created. The hack helps to avoid the "bad file descriptor" flaky errors for the test.
1 parent 29b97f0 commit 802aa24

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

dial_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,8 +658,21 @@ func TestFdDialer_Dial(t *testing.T) {
658658
t.Run(tc.name, func(t *testing.T) {
659659
sock, err := net.Dial("tcp", addr)
660660
require.NoError(t, err)
661+
defer sock.Close()
662+
663+
// It seems that the file descriptor is not always fully ready
664+
// after the connection is created. These lines help to avoid the
665+
// "bad file descriptor" errors.
666+
//
667+
// We already tried to use the SyscallConn(), but it has the same
668+
// issue.
669+
time.Sleep(time.Millisecond)
670+
sock.(*net.TCPConn).SetLinger(0)
671+
661672
f, err := sock.(*net.TCPConn).File()
662673
require.NoError(t, err)
674+
defer f.Close()
675+
663676
dialer := tarantool.FdDialer{
664677
Fd: f.Fd(),
665678
}
@@ -676,8 +689,21 @@ func TestFdDialer_Dial_requirements(t *testing.T) {
676689

677690
sock, err := net.Dial("tcp", addr)
678691
require.NoError(t, err)
692+
defer sock.Close()
693+
694+
// It seems that the file descriptor is not always fully ready after the
695+
// connection is created. These lines help to avoid the
696+
// "bad file descriptor" errors.
697+
//
698+
// We already tried to use the SyscallConn(), but it has the same
699+
// issue.
700+
time.Sleep(time.Millisecond)
701+
sock.(*net.TCPConn).SetLinger(0)
702+
679703
f, err := sock.(*net.TCPConn).File()
680704
require.NoError(t, err)
705+
defer f.Close()
706+
681707
dialer := tarantool.FdDialer{
682708
Fd: f.Fd(),
683709
RequiredProtocolInfo: tarantool.ProtocolInfo{
@@ -688,6 +714,7 @@ func TestFdDialer_Dial_requirements(t *testing.T) {
688714
testDialAccept(testDialOpts{}, l)
689715
ctx, cancel := test_helpers.GetConnectContext()
690716
defer cancel()
717+
691718
conn, err := dialer.Dial(ctx, tarantool.DialOpts{})
692719
if err == nil {
693720
conn.Close()

0 commit comments

Comments
 (0)