-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpromise_test.go
54 lines (44 loc) · 1017 Bytes
/
promise_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package mpx
import (
"github.com/gomodule/redigo/redis"
"testing"
"time"
)
func TestPromise(t *testing.T) {
connBuilder := func() (redis.Conn, error) {
return redis.Dial("tcp", ":6379")
}
conn, err := connBuilder()
if err != nil {
panic(err)
}
multiplexer := New(connBuilder)
sub := multiplexer.NewPromiseSubscription("promise-")
timer := time.AfterFunc(3*time.Second, func() {
sub.Close()
})
// Can activate
if ok := sub.WaitForActivation(); !ok {
t.Errorf("failed to activate in time")
}
// Can create promises
{
promiseBanana, err := sub.NewPromise("banana", 3*time.Second)
if err != nil {
panic(err)
}
_, err = conn.Do("PUBLISH", "promise-banana", "Hello World banana!")
if err != nil {
panic(err)
}
select {
case m := <-promiseBanana.C:
mm := "Hello World banana!"
if string(m) != mm {
t.Errorf("Messages are not equal. Got [%v], expected [%v]", string(m), mm)
}
case <-timer.C:
t.Errorf("timed out while waiting for messages")
}
}
}