MCPcopy
hub / github.com/etcd-io/etcd / testServer

Function testServer

pkg/proxy/server_test.go:49–161  ·  view source on GitHub ↗
(t *testing.T, scheme string, secure bool, delayTx bool)

Source from the content-addressed store, hash-verified

47func TestServer_TCP_Secure_DelayTx(t *testing.T) { testServer(t, "tcp", true, true) }
48
49func testServer(t *testing.T, scheme string, secure bool, delayTx bool) {
50 lg := zaptest.NewLogger(t)
51 srcAddr, dstAddr := newUnixAddr(), newUnixAddr()
52 if scheme == "tcp" {
53 ln1, ln2 := listen(t, "tcp", "localhost:0", transport.TLSInfo{}), listen(t, "tcp", "localhost:0", transport.TLSInfo{})
54 srcAddr, dstAddr = ln1.Addr().String(), ln2.Addr().String()
55 ln1.Close()
56 ln2.Close()
57 } else {
58 defer func() {
59 os.RemoveAll(srcAddr)
60 os.RemoveAll(dstAddr)
61 }()
62 }
63 tlsInfo := createTLSInfo(lg, secure)
64 ln := listen(t, scheme, dstAddr, tlsInfo)
65 defer ln.Close()
66
67 cfg := ServerConfig{
68 Logger: lg,
69 From: url.URL{Scheme: scheme, Host: srcAddr},
70 To: url.URL{Scheme: scheme, Host: dstAddr},
71 }
72 if secure {
73 cfg.TLSInfo = tlsInfo
74 }
75 p := NewServer(cfg)
76
77 waitForServer(t, p)
78
79 defer p.Close()
80
81 data1 := []byte("Hello World!")
82 donec, writec := make(chan struct{}), make(chan []byte)
83
84 go func() {
85 defer close(donec)
86 for data := range writec {
87 send(t, data, scheme, srcAddr, tlsInfo) //nolint:testifylint //FIXME
88 }
89 }()
90
91 recvc := make(chan []byte, 1)
92 go func() {
93 for i := 0; i < 2; i++ {
94 recvc <- receive(t, ln) //nolint:testifylint //FIXME
95 }
96 }()
97
98 writec <- data1
99 now := time.Now()
100 if d := <-recvc; !bytes.Equal(data1, d) {
101 close(writec)
102 t.Fatalf("expected %q, got %q", string(data1), string(d))
103 }
104 took1 := time.Since(now)
105 t.Logf("took %v with no latency", took1)
106

Calls 15

CloseMethod · 0.95
DelayTxMethod · 0.95
UndelayTxMethod · 0.95
DoneMethod · 0.95
ErrorMethod · 0.95
newUnixAddrFunction · 0.85
listenFunction · 0.85
createTLSInfoFunction · 0.85
waitForServerFunction · 0.85
sendFunction · 0.85
receiveFunction · 0.85
AddrMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…