MCPcopy Create free account
hub / github.com/ajitpratap0/GoSQLX / TestPoolStats_ConcurrentSafe

Function TestPoolStats_ConcurrentSafe

pkg/metrics/pool_stats_test.go:102–125  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

100}
101
102func TestPoolStats_ConcurrentSafe(t *testing.T) {
103 metrics.ResetPoolStats()
104
105 done := make(chan struct{})
106 for i := 0; i < 100; i++ {
107 go func() {
108 metrics.RecordNamedPoolGet("tokenizer")
109 metrics.RecordNamedPoolPut("tokenizer")
110 done <- struct{}{}
111 }()
112 }
113 for i := 0; i < 100; i++ {
114 <-done
115 }
116
117 stats := metrics.GetPoolStats()
118 ts := stats["tokenizer"]
119 if ts.Gets != 100 {
120 t.Errorf("expected Gets=100, got %d", ts.Gets)
121 }
122 if ts.Puts != 100 {
123 t.Errorf("expected Puts=100, got %d", ts.Puts)
124 }
125}

Callers

nothing calls this directly

Calls 5

ResetPoolStatsFunction · 0.92
RecordNamedPoolGetFunction · 0.92
RecordNamedPoolPutFunction · 0.92
GetPoolStatsFunction · 0.92
ErrorfMethod · 0.65

Tested by

no test coverage detected