-
Notifications
You must be signed in to change notification settings - Fork 29
/
redis_pubsub_tests.dart
81 lines (63 loc) · 1.89 KB
/
redis_pubsub_tests.dart
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
library redis_pubsub_tests;
import 'dart:async';
import 'package:test/test.dart';
import 'package:redis_client/redis_client.dart';
import 'helper.dart';
main() {
group('PubSub tests', () {
RedisClient client;
RedisClient client1;
setUp(() {
return RedisClient.connect("127.0.0.1:6379")
.then((c) {
client = c;
client.flushall();
}).then((a){
return RedisClient.connect("127.0.0.1:6379").then((c1){
client1 = c1;
});
});
});
tearDown(() {
try {
client.close();
client1.close();
}
finally {
}
});
test("publish", () {
async(
client.publish("redizzz", "izzzkool").then((val){
expect(val, equals(0));
}));
});
test("subscribe & publish", () {
async(
client.subscribe(["chan0"],(Receiver message){
message.receiveMultiBulkStrings().then((List<String> message){
expect(message[0], equals("message"));
expect(message[1], equals("chan0"));
expect(message[2], equals("You okay?"));
});
}).then((m){
client1.publish("chan0","You okay?");
}));
});
test("Can work after unsubscribe", () {
bool gotMessage = false;
async(
client.subscribe(["chan0"],(Receiver message){
return message.receiveMultiBulkStrings().then((List<String> message){
gotMessage = true;
}).then((bb)=> client.unsubscribe(["chan0"]))
.then((v) => client.set("key", "val"))
.then((c1) => client.get("key"))
.then((ttt){
expect(ttt, equals("val"));
});
}).then((a) => client1.publish("chan0","You okay?"))
);
});
});
}