You've already forked node-redis
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:
@@ -1,28 +1,28 @@
|
||||
'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
|
||||
var zlib = require('zlib')
|
||||
var client
|
||||
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
|
||||
const zlib = require('zlib')
|
||||
let client
|
||||
|
||||
describe('The \'multi\' method', function () {
|
||||
afterEach(function () {
|
||||
describe('The \'multi\' method', () => {
|
||||
afterEach(() => {
|
||||
client.end(true)
|
||||
})
|
||||
|
||||
describe('regression test', function () {
|
||||
describe('regression test', () => {
|
||||
it('saved buffers with charsets different than utf-8 (issue #913)', function (done) {
|
||||
this.timeout(12000) // Windows tests on 0.10 are slow
|
||||
client = redis.createClient()
|
||||
|
||||
var end = helper.callFuncAfter(done, 100)
|
||||
const end = helper.callFuncAfter(done, 100)
|
||||
|
||||
// Some random object created from http://beta.json-generator.com/
|
||||
var testObj = {
|
||||
const testObj = {
|
||||
'Id': '5642c4c33d4667c4a1fefd99',
|
||||
'index': 0,
|
||||
'guid': '5baf1f1c-7621-41e7-ae7a-f8c6f3199b0f',
|
||||
@@ -53,27 +53,27 @@ describe('The \'multi\' method', function () {
|
||||
return
|
||||
}
|
||||
// To demonstrate a big payload for hash set field values, let's create a big array
|
||||
var testArr = []
|
||||
var i = 0
|
||||
const testArr = []
|
||||
let i = 0
|
||||
for (; i < 80; i++) {
|
||||
var newObj = JSON.parse(JSON.stringify(testObj))
|
||||
const newObj = JSON.parse(JSON.stringify(testObj))
|
||||
testArr.push(newObj)
|
||||
}
|
||||
|
||||
var json = JSON.stringify(testArr)
|
||||
zlib.deflate(Buffer.from(json), function (err, buffer) {
|
||||
const json = JSON.stringify(testArr)
|
||||
zlib.deflate(Buffer.from(json), (err, buffer) => {
|
||||
if (err) {
|
||||
done(err)
|
||||
return
|
||||
}
|
||||
|
||||
var multi = client.multi()
|
||||
const multi = client.multi()
|
||||
multi.del('SOME_KEY')
|
||||
|
||||
for (i = 0; i < 100; i++) {
|
||||
multi.hset('SOME_KEY', 'SOME_FIELD' + i, buffer)
|
||||
multi.hset('SOME_KEY', `SOME_FIELD${i}`, buffer)
|
||||
}
|
||||
multi.exec(function (err, res) {
|
||||
multi.exec((err, res) => {
|
||||
if (err) {
|
||||
done(err)
|
||||
return
|
||||
@@ -86,19 +86,19 @@ describe('The \'multi\' method', function () {
|
||||
})
|
||||
})
|
||||
|
||||
describe('pipeline limit', function () {
|
||||
describe('pipeline limit', () => {
|
||||
it('do not exceed maximum string size', function (done) {
|
||||
this.timeout(process.platform !== 'win32' ? 10000 : 35000) // Windows tests are horribly slow
|
||||
// Triggers a RangeError: Invalid string length if not handled properly
|
||||
client = redis.createClient()
|
||||
var multi = client.multi()
|
||||
var i = Math.pow(2, 28)
|
||||
const multi = client.multi()
|
||||
let i = Math.pow(2, 28)
|
||||
while (i > 0) {
|
||||
i -= 10230
|
||||
multi.set('foo' + i, 'bar' + new Array(1024).join('1234567890'))
|
||||
multi.set(`foo${i}`, `bar${new Array(1024).join('1234567890')}`)
|
||||
}
|
||||
client.on('ready', function () {
|
||||
multi.exec(function (err, res) {
|
||||
client.on('ready', () => {
|
||||
multi.exec((err, res) => {
|
||||
assert.strictEqual(err, null)
|
||||
assert.strictEqual(res.length, 26241)
|
||||
})
|
||||
@@ -107,67 +107,66 @@ describe('The \'multi\' method', function () {
|
||||
})
|
||||
})
|
||||
|
||||
helper.allTests(function (ip, args) {
|
||||
describe('using ' + ip, function () {
|
||||
describe('when not connected', function () {
|
||||
beforeEach(function (done) {
|
||||
var end = helper.callFuncAfter(done, 2)
|
||||
helper.allTests((ip, args) => {
|
||||
describe(`using ${ip}`, () => {
|
||||
describe('when not connected', () => {
|
||||
beforeEach((done) => {
|
||||
const end = helper.callFuncAfter(done, 2)
|
||||
client = redis.createClient.apply(null, args)
|
||||
client.once('ready', function () {
|
||||
client.once('ready', () => {
|
||||
client.quit(end)
|
||||
})
|
||||
client.once('end', end)
|
||||
})
|
||||
|
||||
it('reports an error', function (done) {
|
||||
var multi = client.multi()
|
||||
var notBuffering = multi.exec(function (err, res) {
|
||||
it('reports an error', (done) => {
|
||||
const multi = client.multi()
|
||||
multi.exec((err, res) => {
|
||||
assert(err.message.match(/The connection is already closed/))
|
||||
done()
|
||||
})
|
||||
assert.strictEqual(notBuffering, false)
|
||||
})
|
||||
|
||||
it('reports an error if promisified', function () {
|
||||
return client.multi().execAsync().catch(function (err) {
|
||||
it('reports an error if promisified', () => {
|
||||
return client.multi().execAsync().catch((err) => {
|
||||
assert(err.message.match(/The connection is already closed/))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('when connected', function () {
|
||||
beforeEach(function () {
|
||||
describe('when connected', () => {
|
||||
beforeEach(() => {
|
||||
client = redis.createClient.apply(null, args)
|
||||
})
|
||||
|
||||
describe('monitor and transactions do not work together', function () {
|
||||
it('results in a execabort', function (done) {
|
||||
describe('monitor and transactions do not work together', () => {
|
||||
it('results in a execabort', (done) => {
|
||||
// Check that transactions in combination with monitor result in an error
|
||||
client.monitor(function (e) {
|
||||
client.on('error', function (err) {
|
||||
client.monitor((e) => {
|
||||
client.on('error', (err) => {
|
||||
assert.strictEqual(err.code, 'EXECABORT')
|
||||
client.end(false)
|
||||
done()
|
||||
})
|
||||
var multi = client.multi()
|
||||
const multi = client.multi()
|
||||
multi.set('hello', 'world')
|
||||
multi.exec()
|
||||
})
|
||||
})
|
||||
|
||||
it('results in a execabort #2', function (done) {
|
||||
it('results in a execabort #2', (done) => {
|
||||
// Check that using monitor with a transactions results in an error
|
||||
client.multi().set('foo', 'bar').monitor().exec(function (err, res) {
|
||||
client.multi().set('foo', 'bar').monitor().exec((err, res) => {
|
||||
assert.strictEqual(err.code, 'EXECABORT')
|
||||
client.end(false)
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
it('sanity check', function (done) {
|
||||
it('sanity check', (done) => {
|
||||
// Remove the listener and add it back again after the error
|
||||
var mochaListener = helper.removeMochaListener()
|
||||
process.on('uncaughtException', function () {
|
||||
const mochaListener = helper.removeMochaListener()
|
||||
process.on('uncaughtException', () => {
|
||||
helper.removeMochaListener()
|
||||
process.on('uncaughtException', mochaListener)
|
||||
done()
|
||||
@@ -177,7 +176,7 @@ describe('The \'multi\' method', function () {
|
||||
client.sendCommand('multi')
|
||||
client.sendCommand('set', ['foo', 'bar'])
|
||||
client.sendCommand('get', ['foo'])
|
||||
client.sendCommand('exec', function (err, res) {
|
||||
client.sendCommand('exec', (err, res) => {
|
||||
assert.strictEqual(err, null)
|
||||
// res[0] is going to be the monitor result of set
|
||||
// res[1] is going to be the result of the set command
|
||||
@@ -189,30 +188,30 @@ describe('The \'multi\' method', function () {
|
||||
})
|
||||
})
|
||||
|
||||
it('executes a pipelined multi properly in combination with the offline queue', function (done) {
|
||||
var multi1 = client.multi()
|
||||
it('executes a pipelined multi properly in combination with the offline queue', (done) => {
|
||||
const multi1 = client.multi()
|
||||
multi1.set('m1', '123')
|
||||
multi1.get('m1')
|
||||
multi1.exec(done)
|
||||
assert.strictEqual(client.offlineQueue.length, 4)
|
||||
})
|
||||
|
||||
it('executes a pipelined multi properly after a reconnect in combination with the offline queue', function (done) {
|
||||
client.once('ready', function () {
|
||||
it('executes a pipelined multi properly after a reconnect in combination with the offline queue', (done) => {
|
||||
client.once('ready', () => {
|
||||
client.stream.destroy()
|
||||
var called = false
|
||||
var multi1 = client.multi()
|
||||
let called = false
|
||||
const multi1 = client.multi()
|
||||
multi1.set('m1', '123')
|
||||
multi1.get('m1')
|
||||
multi1.exec(function (err, res) {
|
||||
multi1.exec((err, res) => {
|
||||
assert(!err)
|
||||
called = true
|
||||
})
|
||||
client.once('ready', function () {
|
||||
var multi1 = client.multi()
|
||||
client.once('ready', () => {
|
||||
const multi1 = client.multi()
|
||||
multi1.set('m2', '456')
|
||||
multi1.get('m2')
|
||||
multi1.exec(function (err, res) {
|
||||
multi1.exec((err, res) => {
|
||||
assert(called)
|
||||
assert(!err)
|
||||
assert.strictEqual(res[1], '456')
|
||||
@@ -223,35 +222,35 @@ describe('The \'multi\' method', function () {
|
||||
})
|
||||
})
|
||||
|
||||
describe('when connection is broken', function () {
|
||||
it.skip('return an error even if connection is in broken mode if callback is present', function (done) {
|
||||
describe('when connection is broken', () => {
|
||||
it.skip('return an error even if connection is in broken mode if callback is present', (done) => {
|
||||
client = redis.createClient({
|
||||
host: 'somewhere',
|
||||
port: 6379,
|
||||
retryStrategy: function () {}
|
||||
retryStrategy () {}
|
||||
})
|
||||
|
||||
client.on('error', function (err) {
|
||||
client.on('error', (err) => {
|
||||
if (/Redis connection in broken state/.test(err.message)) {
|
||||
done()
|
||||
}
|
||||
})
|
||||
|
||||
client.multi([['set', 'foo', 'bar'], ['get', 'foo']]).exec(function (err, res) {
|
||||
client.multi([['set', 'foo', 'bar'], ['get', 'foo']]).exec((err, res) => {
|
||||
// assert(/Redis connection in broken state/.test(err.message));
|
||||
assert.strictEqual(err.errors.length, 2)
|
||||
assert.strictEqual(err.errors[0].args.length, 2)
|
||||
})
|
||||
})
|
||||
|
||||
it.skip('does not emit an error twice if connection is in broken mode with no callback', function (done) {
|
||||
it.skip('does not emit an error twice if connection is in broken mode with no callback', (done) => {
|
||||
client = redis.createClient({
|
||||
host: 'somewhere',
|
||||
port: 6379,
|
||||
retryStrategy: function () {}
|
||||
retryStrategy () {}
|
||||
})
|
||||
|
||||
client.on('error', function (err) {
|
||||
client.on('error', (err) => {
|
||||
// Results in multiple done calls if test fails
|
||||
if (/Redis connection in broken state/.test(err.message)) {
|
||||
done()
|
||||
@@ -262,40 +261,39 @@ describe('The \'multi\' method', function () {
|
||||
})
|
||||
})
|
||||
|
||||
describe('when ready', function () {
|
||||
beforeEach(function (done) {
|
||||
describe('when ready', () => {
|
||||
beforeEach((done) => {
|
||||
client = redis.createClient.apply(null, args)
|
||||
client.once('ready', function () {
|
||||
client.flushdb(function (err) {
|
||||
client.once('ready', () => {
|
||||
client.flushdb((err) => {
|
||||
return done(err)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
it('returns an empty result array', function (done) {
|
||||
var multi = client.multi()
|
||||
var notBuffering = multi.exec(function (err, res) {
|
||||
it('returns an empty result array', (done) => {
|
||||
const multi = client.multi()
|
||||
multi.exec((err, res) => {
|
||||
assert.strictEqual(err, null)
|
||||
assert.strictEqual(res.length, 0)
|
||||
done()
|
||||
})
|
||||
assert.strictEqual(notBuffering, true)
|
||||
})
|
||||
|
||||
it('runs normal calls in-between multis', function (done) {
|
||||
var multi1 = client.multi()
|
||||
it('runs normal calls in-between multis', (done) => {
|
||||
const multi1 = client.multi()
|
||||
multi1.set('m1', '123')
|
||||
client.set('m2', '456', done)
|
||||
})
|
||||
|
||||
it('runs simultaneous multis with the same client', function (done) {
|
||||
var end = helper.callFuncAfter(done, 2)
|
||||
it('runs simultaneous multis with the same client', (done) => {
|
||||
const end = helper.callFuncAfter(done, 2)
|
||||
|
||||
var multi1 = client.multi()
|
||||
const multi1 = client.multi()
|
||||
multi1.set('m1', '123')
|
||||
multi1.get('m1')
|
||||
|
||||
var multi2 = client.multi()
|
||||
const multi2 = client.multi()
|
||||
multi2.set('m2', '456')
|
||||
multi2.get('m2')
|
||||
|
||||
@@ -303,10 +301,10 @@ describe('The \'multi\' method', function () {
|
||||
multi2.exec(helper.isDeepEqual(['OK', '456'], end))
|
||||
})
|
||||
|
||||
it('runs simultaneous multis with the same client version 2', function (done) {
|
||||
var end = helper.callFuncAfter(done, 2)
|
||||
var multi2 = client.multi()
|
||||
var multi1 = client.multi()
|
||||
it('runs simultaneous multis with the same client version 2', (done) => {
|
||||
const end = helper.callFuncAfter(done, 2)
|
||||
const multi2 = client.multi()
|
||||
const multi1 = client.multi()
|
||||
|
||||
multi2.set('m2', '456')
|
||||
multi1.set('m1', '123')
|
||||
@@ -318,43 +316,42 @@ describe('The \'multi\' method', function () {
|
||||
multi2.exec(helper.isDeepEqual(['OK', '123', 'PONG'], end))
|
||||
})
|
||||
|
||||
it('roles back a transaction when one command in a sequence of commands fails', function (done) {
|
||||
var multi1, multi2
|
||||
it('roles back a transaction when one command in a sequence of commands fails', (done) => {
|
||||
// Provoke an error at queue time
|
||||
multi1 = client.multi()
|
||||
const multi1 = client.multi()
|
||||
multi1.mset('multifoo', '10', 'multibar', '20', helper.isString('OK'))
|
||||
|
||||
multi1.set('foo2', helper.isError())
|
||||
multi1.incr('multifoo')
|
||||
multi1.incr('multibar')
|
||||
multi1.exec(function () {
|
||||
multi1.exec(() => {
|
||||
// Redis 2.6.5+ will abort transactions with errors
|
||||
// see: http://redis.io/topics/transactions
|
||||
var multibarExpected = 1
|
||||
var multifooExpected = 1
|
||||
const multibarExpected = 1
|
||||
const multifooExpected = 1
|
||||
// Confirm that the previous command, while containing an error, still worked.
|
||||
multi2 = client.multi()
|
||||
const multi2 = client.multi()
|
||||
multi2.incr('multibar', helper.isNumber(multibarExpected))
|
||||
multi2.incr('multifoo', helper.isNumber(multifooExpected))
|
||||
multi2.exec(helper.isDeepEqual([multibarExpected, multibarExpected], done))
|
||||
})
|
||||
})
|
||||
|
||||
it('roles back a transaction when one command in an array of commands fails', function (done) {
|
||||
it('roles back a transaction when one command in an array of commands fails', (done) => {
|
||||
// test nested multi-bulk replies
|
||||
client.multi([
|
||||
['mget', 'multifoo', 'multibar', helper.isDeepEqual([null, null])],
|
||||
['set', 'foo2', helper.isError()],
|
||||
['incr', 'multifoo'],
|
||||
['incr', 'multibar']
|
||||
]).exec(function (err, replies) {
|
||||
]).exec((err, replies) => {
|
||||
assert.notEqual(err, null)
|
||||
assert.strictEqual(replies, undefined)
|
||||
return done()
|
||||
})
|
||||
})
|
||||
|
||||
it('handles multiple operations being applied to a set', function (done) {
|
||||
it('handles multiple operations being applied to a set', (done) => {
|
||||
client.sadd('some set', 'mem 1')
|
||||
client.sadd(['some set', 'mem 2'])
|
||||
client.sadd('some set', 'mem 3')
|
||||
@@ -371,7 +368,7 @@ describe('The \'multi\' method', function () {
|
||||
['smembers', 'some set']
|
||||
])
|
||||
.scard('some set')
|
||||
.exec(function (err, res) {
|
||||
.exec((err, res) => {
|
||||
assert.strictEqual(err, null)
|
||||
assert.strictEqual(res[0].length, 4)
|
||||
assert.strictEqual(res[1], 1)
|
||||
@@ -381,13 +378,13 @@ describe('The \'multi\' method', function () {
|
||||
})
|
||||
})
|
||||
|
||||
it('allows multiple operations to be performed using constructor with all kinds of syntax', function (done) {
|
||||
var now = Date.now()
|
||||
var arr = ['multihmset', 'multibar', 'multibaz']
|
||||
var arr2 = ['some manner of key', 'otherTypes']
|
||||
var arr3 = [5768, 'multibarx', 'multifoox']
|
||||
var arr4 = ['mset', [578, 'multibar'], helper.isString('OK')]
|
||||
var called = false
|
||||
it('allows multiple operations to be performed using constructor with all kinds of syntax', (done) => {
|
||||
const now = Date.now()
|
||||
const arr = ['multihmset', 'multibar', 'multibaz']
|
||||
const arr2 = ['some manner of key', 'otherTypes']
|
||||
const arr3 = [5768, 'multibarx', 'multifoox']
|
||||
const arr4 = ['mset', [578, 'multibar'], helper.isString('OK')]
|
||||
let called = false
|
||||
client.multi([
|
||||
arr4,
|
||||
[['mset', 'multifoo2', 'multibar2', 'multifoo3', 'multibar3'], helper.isString('OK')],
|
||||
@@ -401,15 +398,15 @@ describe('The \'multi\' method', function () {
|
||||
['hmset', 'multihmset', ['multibar', 'multibaz'], helper.isString('OK')]
|
||||
])
|
||||
.hmget(now, 123456789, 'otherTypes')
|
||||
.hmget('key2', arr2, function noop () {})
|
||||
.hmget('key2', arr2, () => {})
|
||||
.hmget(['multihmset2', 'some manner of key', 'multibar3'])
|
||||
.mget('multifoo2', ['multifoo3', 'multifoo'], function (err, res) {
|
||||
.mget('multifoo2', ['multifoo3', 'multifoo'], (err, res) => {
|
||||
assert.strictEqual(err, null)
|
||||
assert(res[0], 'multifoo3')
|
||||
assert(res[1], 'multifoo')
|
||||
called = true
|
||||
})
|
||||
.exec(function (err, replies) {
|
||||
.exec((err, replies) => {
|
||||
assert(called)
|
||||
assert.strictEqual(arr.length, 3)
|
||||
assert.strictEqual(arr2.length, 2)
|
||||
@@ -427,7 +424,7 @@ describe('The \'multi\' method', function () {
|
||||
})
|
||||
})
|
||||
|
||||
it('converts a non string key to a string', function (done) {
|
||||
it('converts a non string key to a string', (done) => {
|
||||
// TODO: Converting the key might change soon again.
|
||||
client.multi().hmset(true, {
|
||||
test: 123,
|
||||
@@ -435,16 +432,15 @@ describe('The \'multi\' method', function () {
|
||||
}).exec(done)
|
||||
})
|
||||
|
||||
it('runs a multi without any further commands', function (done) {
|
||||
var buffering = client.multi().exec(function (err, res) {
|
||||
it('runs a multi without any further commands', (done) => {
|
||||
client.multi().exec((err, res) => {
|
||||
assert.strictEqual(err, null)
|
||||
assert.strictEqual(res.length, 0)
|
||||
done()
|
||||
})
|
||||
assert(typeof buffering === 'boolean')
|
||||
})
|
||||
|
||||
it('allows multiple operations to be performed using a chaining API', function (done) {
|
||||
it('allows multiple operations to be performed using a chaining API', (done) => {
|
||||
client.multi()
|
||||
.mset('some', '10', 'keys', '20')
|
||||
.incr('some')
|
||||
@@ -453,7 +449,7 @@ describe('The \'multi\' method', function () {
|
||||
.exec(helper.isDeepEqual(['OK', 11, 21, ['11', '21']], done))
|
||||
})
|
||||
|
||||
it('allows multiple commands to work the same as normal to be performed using a chaining API', function (done) {
|
||||
it('allows multiple commands to work the same as normal to be performed using a chaining API', (done) => {
|
||||
client.multi()
|
||||
.mset(['some', '10', 'keys', '20'])
|
||||
.incr('some', helper.isNumber(11))
|
||||
@@ -462,14 +458,14 @@ describe('The \'multi\' method', function () {
|
||||
.exec(helper.isDeepEqual(['OK', 11, 21, ['11', '21']], done))
|
||||
})
|
||||
|
||||
it('allows multiple commands to work the same as normal to be performed using a chaining API promisified', function () {
|
||||
it('allows multiple commands to work the same as normal to be performed using a chaining API promisified', () => {
|
||||
return client.multi()
|
||||
.mset(['some', '10', 'keys', '20'])
|
||||
.incr('some', helper.isNumber(11))
|
||||
.incr(['keys'], helper.isNumber(21))
|
||||
.mget('some', 'keys')
|
||||
.execAsync()
|
||||
.then(function (replies) {
|
||||
.then((replies) => {
|
||||
assert.strictEqual('OK', replies[0])
|
||||
assert.strictEqual(11, replies[1])
|
||||
assert.strictEqual(21, replies[2])
|
||||
@@ -478,7 +474,7 @@ describe('The \'multi\' method', function () {
|
||||
})
|
||||
})
|
||||
|
||||
it('allows an array to be provided indicating multiple operations to perform', function (done) {
|
||||
it('allows an array to be provided indicating multiple operations to perform', (done) => {
|
||||
// test nested multi-bulk replies with nulls.
|
||||
client.multi([
|
||||
['mget', ['multifoo', 'some', 'random value', 'keys']],
|
||||
@@ -486,7 +482,7 @@ describe('The \'multi\' method', function () {
|
||||
]).exec(helper.isDeepEqual([[null, null, null, null], 1], done))
|
||||
})
|
||||
|
||||
it('allows multiple operations to be performed on a hash', function (done) {
|
||||
it('allows multiple operations to be performed on a hash', (done) => {
|
||||
client.multi()
|
||||
.hmset('multihash', 'a', 'foo', 'b', 1)
|
||||
.hmset('multihash', {
|
||||
@@ -494,7 +490,7 @@ describe('The \'multi\' method', function () {
|
||||
things: 'here'
|
||||
})
|
||||
.hgetall('multihash')
|
||||
.exec(function (err, replies) {
|
||||
.exec((err, replies) => {
|
||||
assert.strictEqual(null, err)
|
||||
assert.strictEqual('OK', replies[0])
|
||||
assert.strictEqual(Object.keys(replies[2]).length, 4)
|
||||
@@ -506,8 +502,8 @@ describe('The \'multi\' method', function () {
|
||||
})
|
||||
})
|
||||
|
||||
it('reports EXECABORT exceptions when they occur (while queueing)', function (done) {
|
||||
client.multi().config('bar').set('foo').set('bar').exec(function (err, reply) {
|
||||
it('reports EXECABORT exceptions when they occur (while queueing)', (done) => {
|
||||
client.multi().config('bar').set('foo').set('bar').exec((err, reply) => {
|
||||
assert.strictEqual(err.code, 'EXECABORT')
|
||||
assert.strictEqual(reply, undefined, 'The reply should have been discarded')
|
||||
assert(err.message.match(/^EXECABORT/), 'Error message should begin with EXECABORT')
|
||||
@@ -520,8 +516,8 @@ describe('The \'multi\' method', function () {
|
||||
})
|
||||
})
|
||||
|
||||
it('reports multiple exceptions when they occur (while EXEC is running)', function (done) {
|
||||
client.multi().config('bar').debug('foo').eval('return {err=\'this is an error\'}', 0).exec(function (err, reply) {
|
||||
it('reports multiple exceptions when they occur (while EXEC is running)', (done) => {
|
||||
client.multi().config('bar').debug('foo').eval('return {err=\'this is an error\'}', 0).exec((err, reply) => {
|
||||
assert.strictEqual(err, null)
|
||||
assert.strictEqual(reply.length, 3)
|
||||
assert.strictEqual(reply[0].code, 'ERR')
|
||||
@@ -535,8 +531,8 @@ describe('The \'multi\' method', function () {
|
||||
})
|
||||
})
|
||||
|
||||
it('reports multiple exceptions when they occur (while EXEC is running) promisified', function () {
|
||||
return client.multi().config('bar').debug('foo').eval('return {err=\'this is an error\'}', 0).execAsync().then(function (reply) {
|
||||
it('reports multiple exceptions when they occur (while EXEC is running) promisified', () => {
|
||||
return client.multi().config('bar').debug('foo').eval('return {err=\'this is an error\'}', 0).execAsync().then((reply) => {
|
||||
assert.strictEqual(reply.length, 3)
|
||||
assert.strictEqual(reply[0].code, 'ERR')
|
||||
assert.strictEqual(reply[0].command, 'CONFIG')
|
||||
@@ -548,11 +544,11 @@ describe('The \'multi\' method', function () {
|
||||
})
|
||||
})
|
||||
|
||||
it('reports multiple exceptions when they occur (while EXEC is running) and calls cb', function (done) {
|
||||
var multi = client.multi()
|
||||
it('reports multiple exceptions when they occur (while EXEC is running) and calls cb', (done) => {
|
||||
const multi = client.multi()
|
||||
multi.config('bar', helper.isError())
|
||||
multi.set('foo', 'bar', helper.isString('OK'))
|
||||
multi.debug('foo').exec(function (err, reply) {
|
||||
multi.debug('foo').exec((err, reply) => {
|
||||
assert.strictEqual(err, null)
|
||||
assert.strictEqual(reply.length, 3)
|
||||
assert.strictEqual(reply[0].code, 'ERR')
|
||||
@@ -563,20 +559,20 @@ describe('The \'multi\' method', function () {
|
||||
})
|
||||
})
|
||||
|
||||
it('emits an error if no callback has been provided and execabort error occured', function (done) {
|
||||
var multi = client.multi()
|
||||
it('emits an error if no callback has been provided and execabort error occured', (done) => {
|
||||
const multi = client.multi()
|
||||
multi.config('bar')
|
||||
multi.set('foo')
|
||||
multi.exec()
|
||||
|
||||
client.on('error', function (err) {
|
||||
client.on('error', (err) => {
|
||||
assert.strictEqual(err.code, 'EXECABORT')
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
it('should work without any callback', function (done) {
|
||||
var multi = client.multi()
|
||||
it('should work without any callback', (done) => {
|
||||
const multi = client.multi()
|
||||
multi.set('baz', 'binary')
|
||||
multi.set('foo', 'bar')
|
||||
multi.exec()
|
||||
@@ -584,9 +580,9 @@ describe('The \'multi\' method', function () {
|
||||
client.get('foo', helper.isString('bar', done))
|
||||
})
|
||||
|
||||
it('should not use a transaction with execAtomic if no command is used', function () {
|
||||
var multi = client.multi()
|
||||
var test = false
|
||||
it('should not use a transaction with execAtomic if no command is used', () => {
|
||||
const multi = client.multi()
|
||||
let test = false
|
||||
multi.execBatch = function () {
|
||||
test = true
|
||||
}
|
||||
@@ -594,9 +590,9 @@ describe('The \'multi\' method', function () {
|
||||
assert(test)
|
||||
})
|
||||
|
||||
it('should not use a transaction with execAtomic if only one command is used', function () {
|
||||
var multi = client.multi()
|
||||
var test = false
|
||||
it('should not use a transaction with execAtomic if only one command is used', () => {
|
||||
const multi = client.multi()
|
||||
let test = false
|
||||
multi.execBatch = function () {
|
||||
test = true
|
||||
}
|
||||
@@ -605,9 +601,9 @@ describe('The \'multi\' method', function () {
|
||||
assert(test)
|
||||
})
|
||||
|
||||
it('should use transaction with execAtomic and more than one command used', function (done) {
|
||||
var multi = client.multi()
|
||||
var test = false
|
||||
it('should use transaction with execAtomic and more than one command used', (done) => {
|
||||
const multi = client.multi()
|
||||
let test = false
|
||||
multi.execBatch = function () {
|
||||
test = true
|
||||
}
|
||||
@@ -617,9 +613,9 @@ describe('The \'multi\' method', function () {
|
||||
assert(!test)
|
||||
})
|
||||
|
||||
it('do not mutate arguments in the multi constructor', function (done) {
|
||||
var input = [['set', 'foo', 'bar'], ['get', 'foo']]
|
||||
client.multi(input).exec(function (err, res) {
|
||||
it('do not mutate arguments in the multi constructor', (done) => {
|
||||
const input = [['set', 'foo', 'bar'], ['get', 'foo']]
|
||||
client.multi(input).exec((err, res) => {
|
||||
assert.strictEqual(err, null)
|
||||
assert.strictEqual(input.length, 2)
|
||||
assert.strictEqual(input[0].length, 3)
|
||||
@@ -628,13 +624,13 @@ describe('The \'multi\' method', function () {
|
||||
})
|
||||
})
|
||||
|
||||
it('works properly after a reconnect. issue #897', function (done) {
|
||||
it('works properly after a reconnect. issue #897', (done) => {
|
||||
client.stream.destroy()
|
||||
client.on('error', function (err) {
|
||||
client.on('error', (err) => {
|
||||
assert.strictEqual(err.code, 'ECONNREFUSED')
|
||||
})
|
||||
client.on('ready', function () {
|
||||
client.multi([['set', 'foo', 'bar'], ['get', 'foo']]).exec(function (err, res) {
|
||||
client.on('ready', () => {
|
||||
client.multi([['set', 'foo', 'bar'], ['get', 'foo']]).exec((err, res) => {
|
||||
assert(!err)
|
||||
assert.strictEqual(res[1], 'bar')
|
||||
done()
|
||||
@@ -642,10 +638,10 @@ describe('The \'multi\' method', function () {
|
||||
})
|
||||
})
|
||||
|
||||
it('emits error once if reconnecting after multi has been executed but not yet returned without callback', function (done) {
|
||||
it('emits error once if reconnecting after multi has been executed but not yet returned without callback', (done) => {
|
||||
// NOTE: If uncork is called async by postponing it to the next tick, this behavior is going to change.
|
||||
// The command won't be processed anymore two errors are returned instead of one
|
||||
client.on('error', function (err) {
|
||||
client.on('error', (err) => {
|
||||
assert.strictEqual(err.code, 'UNCERTAIN_STATE')
|
||||
client.get('foo', helper.isString('bar', done))
|
||||
})
|
||||
@@ -656,7 +652,7 @@ describe('The \'multi\' method', function () {
|
||||
client.stream.destroy()
|
||||
})
|
||||
|
||||
it('indivdual commands work properly with multi', function (done) {
|
||||
it('indivdual commands work properly with multi', (done) => {
|
||||
// Neither of the following work properly in a transactions:
|
||||
// (This is due to Redis not returning the reply as expected / resulting in undefined behavior)
|
||||
// (Likely there are more commands that do not work with a transaction)
|
||||
@@ -675,8 +671,8 @@ describe('The \'multi\' method', function () {
|
||||
}
|
||||
|
||||
assert.strictEqual(client.selectedDb, undefined)
|
||||
var multi = client.multi()
|
||||
multi.select(5, function (err, res) {
|
||||
const multi = client.multi()
|
||||
multi.select(5, (err, res) => {
|
||||
assert.strictEqual(err, null)
|
||||
assert.strictEqual(client.selectedDb, 5)
|
||||
assert.strictEqual(res, 'OK')
|
||||
@@ -684,13 +680,13 @@ describe('The \'multi\' method', function () {
|
||||
})
|
||||
// multi.client('reply', 'on', helper.isString('OK')); // Redis v.3.2
|
||||
multi.set('foo', 'bar', helper.isString('OK'))
|
||||
multi.info(function (err, res) {
|
||||
multi.info((err, res) => {
|
||||
assert.strictEqual(err, null)
|
||||
assert.strictEqual(res.indexOf('# Server\r\nredis_version:'), 0)
|
||||
assert.deepEqual(client.serverInfo.db5, { avg_ttl: 0, expires: 0, keys: 1 })
|
||||
})
|
||||
multi.get('foo', helper.isString('bar'))
|
||||
multi.exec(function (err, res) {
|
||||
multi.exec((err, res) => {
|
||||
assert.strictEqual(err, null)
|
||||
res[2] = res[2].substr(0, 10)
|
||||
assert.deepEqual(res, ['OK', 'OK', '# Server\r\n', 'bar'])
|
||||
|
Reference in New Issue
Block a user