-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.js
79 lines (66 loc) · 1.68 KB
/
test.js
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
'use strict'
const { test, teardown } = require('tap')
const Redis = require('ioredis')
const auto = require('.')
const redis = new Redis()
teardown(async () => {
await redis.quit()
})
test('automatic create a pipeline', async ({ is }) => {
const pipeline = auto(redis)
await pipeline.set('foo', 'bar')
is(await pipeline.get('foo'), 'bar')
})
test('hide non-compatible commands', async ({ is }) => {
const pipeline = auto(redis)
const notAllowedCommands = ['subscribe', 'psubscribe', 'pipeline', 'multi']
for (const cmd of notAllowedCommands) {
is(pipeline[cmd], undefined)
}
})
test('loop gets', async ({ deepEqual }) => {
const pipeline = auto(redis)
await pipeline.set('foo', 'bar')
deepEqual(await Promise.all([
pipeline.get('foo'),
pipeline.get('foo'),
pipeline.get('foo'),
pipeline.get('foo'),
pipeline.get('foo')
]), [
'bar',
'bar',
'bar',
'bar',
'bar'
])
})
test('verify reject', async ({ deepEqual, rejects, is }) => {
const pipeline = auto(redis)
await pipeline.set('foo', 'bar')
pipeline[auto.kPipeline].get = (key, cb) => {
is(key, 'foo')
process.nextTick(cb, new Error('kaboom'))
}
pipeline[auto.kPipeline].exec = (cb) => {
process.nextTick(cb)
}
await rejects(pipeline.get('foo'))
})
test('counter', async ({ is }) => {
const pipeline = auto(redis)
is(pipeline.queued, 0)
const promise1 = pipeline.set('foo', 'bar')
is(pipeline.queued, 1)
await promise1
is(pipeline.queued, 0)
const promise2 = Promise.all([
pipeline.get('foo'),
pipeline.get('foo'),
pipeline.get('foo'),
pipeline.get('foo'),
pipeline.get('foo')
])
is(pipeline.queued, 5)
await promise2
})