test: fix occasional error in TestDialTLS (#716)

This commit is contained in:
zekin 2023-04-11 11:25:21 +08:00 committed by GitHub
parent 8e56601a70
commit fcd5e6ccf5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 3 deletions

View File

@ -75,20 +75,25 @@ func TestDialTLS(t *testing.T) {
t.Fatalf("timeout")
}
buf := make([]byte, len(data))
dial := NewDialer()
_, err := dial.DialConnection(nw, addr, time.Second, &tls.Config{
conn, err := dial.DialConnection(nw, addr, time.Second, &tls.Config{
InsecureSkipVerify: true,
})
assert.Nil(t, err)
conn, err := dial.DialConnection(nw, addr, time.Second, nil)
_, err = conn.Read(buf)
assert.Nil(t, err)
assert.DeepEqual(t, string(data), string(buf))
conn, err = dial.DialConnection(nw, addr, time.Second, nil)
assert.Nil(t, err)
nConn, err := dial.AddTLS(conn, &tls.Config{
InsecureSkipVerify: true,
})
assert.Nil(t, err)
buf := make([]byte, len(data))
_, err = nConn.Read(buf)
assert.Nil(t, err)
assert.DeepEqual(t, string(data), string(buf))