MCPcopy Index your code
hub / github.com/CovenantSQL/CovenantSQL / TestRPCComponents

Function TestRPCComponents

rpc/pool_test.go:119–224  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

117}
118
119func TestRPCComponents(t *testing.T) {
120 Convey("Setup a single server for pool test", t, func(c C) {
121 nodes, stop, err := setupEnvironment(1, AcceptNAConn)
122 So(err, ShouldBeNil)
123 defer stop()
124
125 target := nodes[0].ID
126 pool := &ClientPool{}
127 defer func() { _ = pool.Close() }()
128
129 So(pool.Len(), ShouldEqual, 0)
130 cli1, err := pool.GetEx(target, true)
131 So(err, ShouldBeNil)
132 _ = cli1.Close()
133 So(pool.Len(), ShouldEqual, 0)
134
135 cli2, err := pool.GetEx(target, false)
136 So(err, ShouldBeNil)
137 _ = cli2.Close()
138 So(pool.Len(), ShouldEqual, 1)
139
140 So(pool.Len(), ShouldEqual, 1)
141 pool.Remove(target)
142 So(pool.Len(), ShouldEqual, 0)
143
144 Convey("Test pool functionality", func() {
145 var resp AddResp
146 // Test broken pipe
147 cli3, err := pool.GetEx(target, false)
148 So(err, ShouldBeNil)
149 err = cli3.Call("Count.Add", &AddReq{Delta: 1}, &resp)
150 So(err, ShouldBeNil)
151 _ = cli3.(*pooledClient).Client.Close() // close underlying client, should produce an error upon any following Call
152 err = cli3.Call("Count.Add", &AddReq{Delta: 1}, &resp)
153 So(err, ShouldNotBeNil)
154 _ = cli3.Close() // should not return a broken client to pool
155 So(pool.Len(), ShouldEqual, 0)
156 })
157
158 Convey("Test caller functionality", func() {
159 pool := &ClientPool{}
160 defer func() { _ = pool.Close() }()
161 caller := NewPersistentCallerWithPool(pool, target)
162 defer caller.Close()
163
164 // Set a bad client with raw tcp
165 rawconn, err := net.Dial("tcp", nodes[0].Addr)
166 So(err, ShouldBeNil)
167 caller.client = NewClient(rawconn)
168 err = caller.Call("Count.Add", &AddReq{Delta: 1}, &AddResp{}) // should try reconnect, and return err
169 So(err, ShouldNotBeNil)
170 err = caller.Call("Count.Add", &AddReq{Delta: 1}, &AddResp{}) // should be no err
171 So(err, ShouldBeNil)
172 })
173 })
174
175 Convey("Setup servers", t, func(c C) {
176 nodes, stop, err := setupEnvironment(10, AcceptNAConn)

Callers

nothing calls this directly

Calls 13

CloseMethod · 0.95
LenMethod · 0.95
GetExMethod · 0.95
RemoveMethod · 0.95
setupEnvironmentFunction · 0.85
NewClientFunction · 0.85
testCallerFunction · 0.85
testPCallerFunction · 0.85
WaitMethod · 0.80
CloseMethod · 0.65
CallMethod · 0.65

Tested by

no test coverage detected