1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-06 02:15:48 +03:00

test fixup

This commit is contained in:
Ruben Bridgewater
2017-05-06 08:16:19 +02:00
parent f1a7bcd735
commit b2613b2270
106 changed files with 2900 additions and 2967 deletions

View File

@@ -1,30 +1,30 @@
'use strict'
var Buffer = require('safe-buffer').Buffer
var assert = require('assert')
var config = require('../lib/config')
var helper = require('../helper')
var utils = require('../../lib/utils')
var redis = config.redis
const Buffer = require('safe-buffer').Buffer
const assert = require('assert')
const config = require('../lib/config')
const helper = require('../helper')
const utils = require('../../lib/utils')
const redis = config.redis
describe('The \'monitor\' method', function () {
helper.allTests(function (parser, ip, args) {
var client
describe('The \'monitor\' method', () => {
helper.allTests((parser, ip, args) => {
let client
afterEach(function () {
afterEach(() => {
client.end(true)
})
beforeEach(function (done) {
beforeEach((done) => {
client = redis.createClient.apply(null, args)
client.once('connect', function () {
client.once('connect', () => {
client.flushdb(done)
})
})
it('monitors commands on all redis clients and works in the correct order', function (done) {
var monitorClient = redis.createClient.apply(null, args)
var responses = [
it('monitors commands on all redis clients and works in the correct order', (done) => {
const monitorClient = redis.createClient.apply(null, args)
const responses = [
['mget', 'some', 'keys', 'foo', 'bar'],
['set', 'json', '{"foo":"123","bar":"sdflkdfsjk","another":false}'],
['eval', 'return redis.call(\'set\', \'sha\', \'test\')', '0'],
@@ -34,11 +34,11 @@ describe('The \'monitor\' method', function () {
['mget', 'foo', 'baz'],
['subscribe', 'foo', 'baz']
]
var end = helper.callFuncAfter(done, 5)
const end = helper.callFuncAfter(done, 5)
monitorClient.set('foo', 'bar')
monitorClient.flushdb()
monitorClient.monitor(function (err, res) {
monitorClient.monitor((err, res) => {
assert.strictEqual(err, null)
assert.strictEqual(res, 'OK')
client.mget('some', 'keys', 'foo', 'bar')
@@ -48,20 +48,20 @@ describe('The \'monitor\' method', function () {
another: false
}))
client.eval('return redis.call(\'set\', \'sha\', \'test\')', 0)
monitorClient.get('baz', function (err, res) {
monitorClient.get('baz', (err, res) => {
assert.strictEqual(res, null)
end(err)
})
monitorClient.set('foo', 'bar" "s are " " good!"', function (err, res) {
monitorClient.set('foo', 'bar" "s are " " good!"', (err, res) => {
assert.strictEqual(res, 'OK')
end(err)
})
monitorClient.mget('foo', 'baz', function (err, res) {
monitorClient.mget('foo', 'baz', (err, res) => {
assert.strictEqual(res[0], 'bar" "s are " " good!"')
assert.strictEqual(res[1], null)
end(err)
})
monitorClient.subscribe('foo', 'baz', function (err, res) {
monitorClient.subscribe('foo', 'baz', (err, res) => {
// The return value might change in v.3
// assert.strictEqual(res, 'baz');
// TODO: Fix the return value of subscribe calls
@@ -69,7 +69,7 @@ describe('The \'monitor\' method', function () {
})
})
monitorClient.on('monitor', function (time, args, rawOutput) {
monitorClient.on('monitor', (time, args, rawOutput) => {
assert.strictEqual(monitorClient.monitoring, true)
assert.deepEqual(args, responses.shift())
assert(utils.monitorRegex.test(rawOutput), rawOutput)
@@ -83,19 +83,19 @@ describe('The \'monitor\' method', function () {
if (process.platform === 'win32') {
this.skip()
}
var monitorClient = redis.createClient({
const monitorClient = redis.createClient({
returnBuffers: true,
path: '/tmp/redis.sock'
})
monitorClient.monitor(function (err, res) {
monitorClient.monitor((err, res) => {
assert.strictEqual(err, null)
assert.strictEqual(monitorClient.monitoring, true)
assert.strictEqual(res.inspect(), Buffer.from('OK').inspect())
monitorClient.mget('hello', Buffer.from('world'))
})
monitorClient.on('monitor', function (time, args, rawOutput) {
monitorClient.on('monitor', (time, args, rawOutput) => {
assert.strictEqual(typeof rawOutput, 'string')
assert(utils.monitorRegex.test(rawOutput), rawOutput)
assert.deepEqual(args, ['mget', 'hello', 'world'])
@@ -104,11 +104,11 @@ describe('The \'monitor\' method', function () {
})
})
it('monitors reconnects properly and works with the offline queue', function (done) {
var called = false
it('monitors reconnects properly and works with the offline queue', (done) => {
let called = false
client.monitor(helper.isString('OK'))
client.mget('hello', 'world')
client.on('monitor', function (time, args, rawOutput) {
client.on('monitor', (time, args, rawOutput) => {
assert.strictEqual(client.monitoring, true)
assert(utils.monitorRegex.test(rawOutput), rawOutput)
assert.deepEqual(args, ['mget', 'hello', 'world'])
@@ -122,13 +122,13 @@ describe('The \'monitor\' method', function () {
})
})
it('monitors reconnects properly and works with the offline queue in a batch statement', function (done) {
var called = false
var multi = client.batch()
it('monitors reconnects properly and works with the offline queue in a batch statement', (done) => {
let called = false
const multi = client.batch()
multi.monitor(helper.isString('OK'))
multi.mget('hello', 'world')
multi.exec(helper.isDeepEqual(['OK', [null, null]]))
client.on('monitor', function (time, args, rawOutput) {
client.on('monitor', (time, args, rawOutput) => {
assert.strictEqual(client.monitoring, true)
assert(utils.monitorRegex.test(rawOutput), rawOutput)
assert.deepEqual(args, ['mget', 'hello', 'world'])
@@ -142,19 +142,19 @@ describe('The \'monitor\' method', function () {
})
})
it('monitor activates even if the command could not be processed properly after a reconnect', function (done) {
client.monitor(function (err, res) {
it('monitor activates even if the command could not be processed properly after a reconnect', (done) => {
client.monitor((err, res) => {
assert.strictEqual(err.code, 'UNCERTAIN_STATE')
})
client.on('error', function () {}) // Ignore error here
client.on('error', () => {}) // Ignore error here
client.stream.destroy()
var end = helper.callFuncAfter(done, 2)
client.on('monitor', function (time, args, rawOutput) {
const end = helper.callFuncAfter(done, 2)
client.on('monitor', (time, args, rawOutput) => {
assert.strictEqual(client.monitoring, true)
end()
})
client.on('reconnecting', function () {
client.get('foo', function (err, res) {
client.on('reconnecting', () => {
client.get('foo', (err, res) => {
assert(!err)
assert.strictEqual(client.monitoring, true)
end()
@@ -162,8 +162,8 @@ describe('The \'monitor\' method', function () {
})
})
it('monitors works in combination with the pub sub mode and the offline queue', function (done) {
var responses = [
it('monitors works in combination with the pub sub mode and the offline queue', (done) => {
const responses = [
['subscribe', '/foo', '/bar'],
['unsubscribe', '/bar'],
['get', 'foo'],
@@ -172,39 +172,39 @@ describe('The \'monitor\' method', function () {
['unsubscribe', 'baz'],
['publish', '/foo', 'hello world']
]
var pub = redis.createClient()
pub.on('ready', function () {
client.monitor(function (err, res) {
const pub = redis.createClient()
pub.on('ready', () => {
client.monitor((err, res) => {
assert.strictEqual(err, null)
assert.strictEqual(res, 'OK')
pub.get('foo', helper.isNull())
})
client.subscribe('/foo', '/bar')
client.unsubscribe('/bar')
setTimeout(function () {
setTimeout(() => {
client.stream.destroy()
client.once('ready', function () {
client.once('ready', () => {
pub.publish('/foo', 'hello world')
})
client.set('foo', 'bar', helper.isError())
client.subscribe('baz')
client.unsubscribe('baz')
}, 150)
var called = false
client.on('monitor', function (time, args, rawOutput) {
let called = false
client.on('monitor', (time, args, rawOutput) => {
assert.deepEqual(args, responses.shift())
assert(utils.monitorRegex.test(rawOutput), rawOutput)
if (responses.length === 0) {
// The publish is called right after the reconnect and the monitor is called before the message is emitted.
// Therefore we have to wait till the next tick
process.nextTick(function () {
process.nextTick(() => {
assert(called)
client.quit(done)
pub.end(false)
})
}
})
client.on('message', function (channel, msg) {
client.on('message', (channel, msg) => {
assert.strictEqual(channel, '/foo')
assert.strictEqual(msg, 'hello world')
called = true