...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package redis_test
18
19 import (
20 "context"
21 "testing"
22
23 "github.com/gomodule/redigo/redis"
24 )
25
26 func TestWaitPoolGetContext(t *testing.T) {
27 d := poolDialer{t: t}
28 p := &redis.Pool{
29 MaxIdle: 1,
30 MaxActive: 1,
31 Dial: d.dial,
32 Wait: true,
33 }
34 defer p.Close()
35 c, err := p.GetContext(context.Background())
36 if err != nil {
37 t.Fatalf("GetContext returned %v", err)
38 }
39 defer c.Close()
40 }
41
42 func TestWaitPoolGetAfterClose(t *testing.T) {
43 d := poolDialer{t: t}
44 p := &redis.Pool{
45 MaxIdle: 1,
46 MaxActive: 1,
47 Dial: d.dial,
48 Wait: true,
49 }
50 p.Close()
51 _, err := p.GetContext(context.Background())
52 if err == nil {
53 t.Fatal("expected error")
54 }
55 }
56
57 func TestWaitPoolGetCanceledContext(t *testing.T) {
58 d := poolDialer{t: t}
59 p := &redis.Pool{
60 MaxIdle: 1,
61 MaxActive: 1,
62 Dial: d.dial,
63 Wait: true,
64 }
65 defer p.Close()
66 ctx, f := context.WithCancel(context.Background())
67 f()
68 c := p.Get()
69 defer c.Close()
70 _, err := p.GetContext(ctx)
71 if err != context.Canceled {
72 t.Fatalf("got error %v, want %v", err, context.Canceled)
73 }
74 }
75
View as plain text