func BenchmarkConnMuxConcurrent(b *testing.B) { b.StopTimer() c, err := redistest.Dial() if err != nil { b.Fatalf("error connection to database, %v", err) } defer c.Close() m := redisx.NewConnMux(c) var wg sync.WaitGroup wg.Add(numConcurrent) b.StartTimer() for i := 0; i < numConcurrent; i++ { go func() { defer wg.Done() for i := 0; i < b.N; i++ { c := m.Get() if _, err := c.Do("PING"); err != nil { b.Fatal(err) } c.Close() } }() } wg.Wait() }
func TestConnMuxClose(t *testing.T) { c, err := redistest.Dial() if err != nil { t.Fatalf("error connection to database, %v", err) } m := redisx.NewConnMux(c) defer m.Close() c1 := m.Get() c2 := m.Get() if err := c1.Send("ECHO", "hello"); err != nil { t.Fatal(err) } if err := c1.Close(); err != nil { t.Fatal(err) } if err := c2.Send("ECHO", "world"); err != nil { t.Fatal(err) } if err := c2.Flush(); err != nil { t.Fatal(err) } s, err := redis.String(c2.Receive()) if err != nil { t.Fatal(err) } if s != "world" { t.Fatalf("echo returned %q, want %q", s, "world") } c2.Close() }
func BenchmarkConnMux(b *testing.B) { b.StopTimer() c, err := redistest.Dial() if err != nil { b.Fatalf("error connection to database, %v", err) } m := redisx.NewConnMux(c) defer m.Close() b.StartTimer() for i := 0; i < b.N; i++ { c := m.Get() if _, err := c.Do("PING"); err != nil { b.Fatal(err) } c.Close() } }