MCPcopy Create free account
hub / github.com/ContentSquare/chproxy / TestGetHostConcurrent

Function TestGetHostConcurrent

scope_test.go:218–238  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

216}
217
218func TestGetHostConcurrent(t *testing.T) {
219 c := &cluster{
220 replicas: []*replica{
221 {
222 hosts: []*topology.Node{
223 topology.NewNode(&url.URL{Host: "127.0.0.1"}, nil, "", "", topology.WithDefaultActiveState(true)),
224 topology.NewNode(&url.URL{Host: "127.0.0.2"}, nil, "", "", topology.WithDefaultActiveState(true)),
225 topology.NewNode(&url.URL{Host: "127.0.0.3"}, nil, "", "", topology.WithDefaultActiveState(true)),
226 },
227 },
228 },
229 }
230 f := func() {
231 h := c.getHost()
232 h.IncrementConnections()
233 h.DecrementConnections()
234 }
235 if err := testConcurrent(f, 1000); err != nil {
236 t.Fatalf("concurrent test err: %s", err)
237 }
238}
239
240func testConcurrent(f func(), concurrency int) error {
241 ch := make(chan struct{}, concurrency)

Callers

nothing calls this directly

Calls 6

getHostMethod · 0.95
NewNodeFunction · 0.92
WithDefaultActiveStateFunction · 0.92
testConcurrentFunction · 0.85
IncrementConnectionsMethod · 0.80
DecrementConnectionsMethod · 0.80

Tested by

no test coverage detected