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

Function BenchmarkSessionPool_Get

rpc/mux/pool_test.go:68–104  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

66}
67
68func BenchmarkSessionPool_Get(b *testing.B) {
69 Convey("session pool", b, func(c C) {
70 log.SetLevel(log.FatalLevel)
71 p := &SessionPool{
72 sessions: make(map[proto.NodeID]*Session),
73 }
74 defer withTCPDialer()()
75 defer func() { _ = p.Close() }()
76
77 l, err := net.Listen("tcp", ":0")
78 if err != nil {
79 log.Fatal(err)
80 }
81 server, err := NewServerWithService(ServiceMap{"Test": NewTestService()})
82 server.SetListener(l)
83 go server.WithAcceptConnFunc(rpc.AcceptRawConn).Serve()
84 wg := &sync.WaitGroup{}
85 b.ResetTimer()
86
87 wg.Add(concurrency)
88 for i := 0; i < concurrency; i++ {
89 go func(c2 C, n int) {
90 defer wg.Done()
91 client, err := p.Get(proto.NodeID(l.Addr().String()))
92 defer func() { _ = client.Close() }()
93 if err != nil {
94 log.Errorf("get session failed: %s", err)
95 return
96 }
97 c2.So(err, ShouldBeNil)
98 err = client.Call("Test.IncCounter", &TestReq{Step: 1}, &TestRep{})
99 c2.So(err, ShouldBeNil)
100 }(c, b.N)
101 }
102 wg.Wait()
103 })
104}
105
106func TestNewSessionPool(t *testing.T) {
107 Convey("session pool", t, func(c C) {

Callers

nothing calls this directly

Calls 15

CloseMethod · 0.95
GetMethod · 0.95
SetLevelFunction · 0.92
FatalFunction · 0.92
NodeIDTypeAlias · 0.92
ErrorfFunction · 0.92
withTCPDialerFunction · 0.85
SetListenerMethod · 0.80
AddrMethod · 0.80
WaitMethod · 0.80
NewServerWithServiceFunction · 0.70
NewTestServiceFunction · 0.70

Tested by

no test coverage detected