1 Star 0 Fork 0

0x43/go-zookeeper

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
tcp_server_test.go 633 Bytes
一键复制 编辑 原始数据 按行查看 历史
package zk
import (
"fmt"
"math/rand"
"net"
"testing"
"time"
)
func WithListenServer(t *testing.T, test func(server string)) {
startPort := int(rand.Int31n(6000) + 10000)
server := fmt.Sprintf("localhost:%d", startPort)
l, err := net.Listen("tcp", server)
if err != nil {
t.Fatalf("Failed to start listen server: %v", err)
}
defer l.Close()
go func() {
conn, err := l.Accept()
if err != nil {
t.Logf("Failed to accept connection: %s", err.Error())
}
handleRequest(conn)
}()
test(server)
}
// Handles incoming requests.
func handleRequest(conn net.Conn) {
time.Sleep(5 * time.Second)
conn.Close()
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/git4chen/go-zookeeper.git
git@gitee.com:git4chen/go-zookeeper.git
git4chen
go-zookeeper
go-zookeeper
master

搜索帮助