feat: implement server and client
This commit is contained in:
40
client_test.go
Normal file
40
client_test.go
Normal file
@ -0,0 +1,40 @@
|
||||
package krpc
|
||||
|
||||
import (
|
||||
"net"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestClient_dialTimeout(t *testing.T) {
|
||||
t.Parallel()
|
||||
l, _ := net.Listen("tcp", ":0")
|
||||
|
||||
f := func(conn net.Conn, opts ...Option) (client *Client, err error) {
|
||||
_ = conn.Close()
|
||||
time.Sleep(time.Millisecond * 500)
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
tests := map[string]time.Duration{
|
||||
"timeout": time.Millisecond * 100,
|
||||
"unlimited": 0,
|
||||
}
|
||||
for name, timeout := range tests {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
_, err := dialTimeout(f, "tcp", l.Addr().String(),
|
||||
WithConnectTimeout(timeout))
|
||||
if strings.Contains(name, "timeout") {
|
||||
_assert(err != nil &&
|
||||
strings.Contains(err.Error(), "timeout"),
|
||||
"expect a timeout error",
|
||||
)
|
||||
} else {
|
||||
_assert(err == nil, "0 means no limit")
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user