-
-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathpubsub_test.ts
76 lines (73 loc) · 1.8 KB
/
pubsub_test.ts
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
import { assertEquals } from "./vendor/https/deno.land/std/testing/asserts.ts";
import { connect } from "./redis.ts";
const { test } = Deno;
const addr = {
hostname: "127.0.0.1",
port: 6379,
};
test({
name: "testSubscribe",
async fn() {
const redis = await connect(addr);
const sub = await redis.subscribe("subsc");
// const hoge = await redis.get("hoge");
const unsub = await sub.unsubscribe("subsc");
await sub.close();
assertEquals(sub.isClosed, true);
redis.close();
},
});
test({
name: "testSubscribe2",
async fn() {
const redis = await connect(addr);
const pub = await connect(addr);
const sub = await redis.subscribe("subsc2");
const p = (async function () {
const it = sub.receive();
return (await it.next()).value;
})();
await pub.publish("subsc2", "wayway");
const message = await p;
assertEquals(message, {
channel: "subsc2",
message: "wayway",
});
await sub.close();
const a = await redis.get("aaa");
assertEquals(a, undefined);
pub.close();
redis.close();
},
});
test({
name: "testSubscribe3",
async fn() {
const redis = await connect(addr);
const pub = await connect(addr);
const sub = await redis.psubscribe("ps*");
let message1;
let message2;
const it = sub.receive();
const p = (async function () {
message1 = (await it.next()).value;
message2 = (await it.next()).value;
})();
await pub.publish("psub", "wayway");
await pub.publish("psubs", "heyhey");
await p;
assertEquals(message1, {
pattern: "ps*",
channel: "psub",
message: "wayway",
});
assertEquals(message2, {
pattern: "ps*",
channel: "psubs",
message: "heyhey",
});
await sub.close();
pub.close();
redis.close();
},
});