MCPcopy
hub / github.com/CodisLabs/codis / TestBackend

Function TestBackend

pkg/proxy/backend_test.go:37–82  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

35}
36
37func TestBackend(t *testing.T) {
38 config := NewDefaultConfig()
39 config.BackendMaxPipeline = 0
40 config.BackendSendTimeout.Set(time.Second)
41 config.BackendRecvTimeout.Set(time.Minute)
42
43 conn, bc := newConnPair(config)
44
45 var array = make([]*Request, 16384)
46 for i := range array {
47 array[i] = &Request{Batch: &sync.WaitGroup{}}
48 }
49
50 go func() {
51 defer conn.Close()
52 time.Sleep(time.Millisecond * 300)
53 for i, _ := range array {
54 _, err := conn.Decode()
55 assert.MustNoError(err)
56 resp := redis.NewString([]byte(strconv.Itoa(i)))
57 assert.MustNoError(conn.Encode(resp, true))
58 }
59 }()
60
61 defer bc.Close()
62
63 ticker := time.NewTicker(time.Second)
64 defer ticker.Stop()
65 go func() {
66 for i := 0; i < 10; i++ {
67 <-ticker.C
68 }
69 log.Panicf("timeout")
70 }()
71
72 for _, r := range array {
73 bc.PushBack(r)
74 }
75
76 for i, r := range array {
77 r.Batch.Wait()
78 assert.MustNoError(r.Err)
79 assert.Must(r.Resp != nil)
80 assert.Must(string(r.Resp.Value) == strconv.Itoa(i))
81 }
82}

Callers

nothing calls this directly

Calls 10

DecodeMethod · 0.80
PanicfMethod · 0.80
NewDefaultConfigFunction · 0.70
newConnPairFunction · 0.70
CloseMethod · 0.65
SleepMethod · 0.65
SetMethod · 0.45
EncodeMethod · 0.45
PushBackMethod · 0.45
WaitMethod · 0.45

Tested by

no test coverage detected