Skip to content

Commit

Permalink
fix: test
Browse files Browse the repository at this point in the history
  • Loading branch information
keroxp committed Jun 1, 2019
1 parent d9a42a9 commit 7e12bad
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion io.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export function createRequest(
export async function sendCommand(
writer: BufWriter,
reader: BufReader,
command,
command: string,
...args
): Promise<RedisRawReply> {
const msg = createRequest(command, ...args);
Expand Down
4 changes: 1 addition & 3 deletions pubsub.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BufReader, BufWriter } from "https://deno.land/std@v0.7.0/io/bufio.ts";
import { readArrayReply, sendCommand } from "./io.ts";
import { createRequest, readArrayReply, sendCommand } from "./io.ts";

export type RedisSubscription = {
readonly isClosed: boolean;
Expand Down Expand Up @@ -77,9 +77,7 @@ class RedisSubscriptionImpl implements RedisSubscription {

async close() {
try {
console.log("unsubscribing");
await this.unsubscribe(...Object.keys(this.channels));
console.log("unsubscribing done");
await this.punsubscribe(...Object.keys(this.patterns));
} finally {
this._isClosed = true;
Expand Down
12 changes: 7 additions & 5 deletions pubsub_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,17 @@ test(async function testSubscribe2() {
const pub = await connect(addr);
const sub = await redis.subscribe("subsc2");
let message: RedisPubSubMessage;
(async function() {
const p = (async function() {
const it = sub.receive();
message = (await it.next()).value;
})();
await pub.publish("subsc2", "wayway");
await sub.close();
await p;
assertEquals(message, {
channel: "subsc2",
message: "wayway"
});
await sub.close();
const a = await redis.get("aaa");
assertEquals(a, void 0);
pub.close();
Expand All @@ -48,14 +49,14 @@ test(async function testPsubscribe() {
const sub = await redis.psubscribe("ps*");
let message1;
let message2;
(async function() {
const it = sub.receive();
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 sub.close();
await p;
assertEquals(message1, {
pattern: "ps*",
channel: "psub",
Expand All @@ -66,6 +67,7 @@ test(async function testPsubscribe() {
channel: "psubs",
message: "heyhey"
});
await sub.close();
pub.close();
redis.close();
});

0 comments on commit 7e12bad

Please sign in to comment.