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,73 +1,73 @@
|
||||
'use strict'
|
||||
|
||||
var assert = require('assert')
|
||||
var config = require('./lib/config')
|
||||
var helper = require('./helper')
|
||||
var redis = config.redis
|
||||
const assert = require('assert')
|
||||
const config = require('./lib/config')
|
||||
const helper = require('./helper')
|
||||
const redis = config.redis
|
||||
|
||||
describe('The \'batch\' method', function () {
|
||||
helper.allTests(function (ip, args) {
|
||||
describe('using ' + ip, function () {
|
||||
describe('when not connected', function () {
|
||||
var client
|
||||
describe('The \'batch\' method', () => {
|
||||
helper.allTests((ip, args) => {
|
||||
describe(`using ${ip}`, () => {
|
||||
describe('when not connected', () => {
|
||||
let client
|
||||
|
||||
beforeEach(function (done) {
|
||||
beforeEach((done) => {
|
||||
client = redis.createClient.apply(null, args)
|
||||
client.once('connect', function () {
|
||||
client.once('connect', () => {
|
||||
client.quit()
|
||||
})
|
||||
client.on('end', done)
|
||||
})
|
||||
|
||||
it('returns an empty array for missing commands', function (done) {
|
||||
var batch = client.batch()
|
||||
batch.exec(function (err, res) {
|
||||
it('returns an empty array for missing commands', (done) => {
|
||||
const batch = client.batch()
|
||||
batch.exec((err, res) => {
|
||||
assert.strictEqual(err, null)
|
||||
assert.strictEqual(res.length, 0)
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
it('returns an error for batch with commands', function (done) {
|
||||
var batch = client.batch()
|
||||
it('returns an error for batch with commands', (done) => {
|
||||
const batch = client.batch()
|
||||
batch.set('foo', 'bar')
|
||||
batch.exec(function (err, res) {
|
||||
batch.exec((err, res) => {
|
||||
assert.strictEqual(err, null)
|
||||
assert.strictEqual(res[0].code, 'NR_CLOSED')
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
it('returns an empty array for missing commands if promisified', function () {
|
||||
return client.batch().execAsync().then(function (res) {
|
||||
it('returns an empty array for missing commands if promisified', () => {
|
||||
return client.batch().execAsync().then((res) => {
|
||||
assert.strictEqual(res.length, 0)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('when connected', function () {
|
||||
var client
|
||||
describe('when connected', () => {
|
||||
let client
|
||||
|
||||
beforeEach(function (done) {
|
||||
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)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
afterEach(function () {
|
||||
afterEach(() => {
|
||||
client.end(true)
|
||||
})
|
||||
|
||||
it('returns an empty array and keep the execution order in tact', function (done) {
|
||||
var called = false
|
||||
client.set('foo', 'bar', function () {
|
||||
it('returns an empty array and keep the execution order in tact', (done) => {
|
||||
let called = false
|
||||
client.set('foo', 'bar', () => {
|
||||
called = true
|
||||
})
|
||||
var batch = client.batch()
|
||||
batch.exec(function (err, res) {
|
||||
const batch = client.batch()
|
||||
batch.exec((err, res) => {
|
||||
assert.strictEqual(err, null)
|
||||
assert.strictEqual(res.length, 0)
|
||||
assert(called)
|
||||
@@ -75,47 +75,45 @@ describe('The \'batch\' method', function () {
|
||||
})
|
||||
})
|
||||
|
||||
it('runs normal calls in-between batch', function (done) {
|
||||
var batch = client.batch()
|
||||
it('runs normal calls in-between batch', (done) => {
|
||||
const batch = client.batch()
|
||||
batch.set('m1', '123')
|
||||
client.set('m2', '456', done)
|
||||
})
|
||||
|
||||
it('returns an empty array if promisified', function () {
|
||||
return client.batch().execAsync().then(function (res) {
|
||||
it('returns an empty array if promisified', () => {
|
||||
return client.batch().execAsync().then((res) => {
|
||||
assert.strictEqual(res.length, 0)
|
||||
})
|
||||
})
|
||||
|
||||
it('returns an empty result array', function (done) {
|
||||
var batch = client.batch()
|
||||
var async = true
|
||||
var notBuffering = batch.exec(function (err, res) {
|
||||
it('returns an empty result array', (done) => {
|
||||
const batch = client.batch()
|
||||
let async = true
|
||||
batch.exec((err, res) => {
|
||||
assert.strictEqual(err, null)
|
||||
assert.strictEqual(res.length, 0)
|
||||
async = false
|
||||
done()
|
||||
})
|
||||
assert(async)
|
||||
assert.strictEqual(notBuffering, true)
|
||||
})
|
||||
|
||||
it('fail individually when one command fails using chaining notation', function (done) {
|
||||
var batch1, batch2
|
||||
batch1 = client.batch()
|
||||
it('fail individually when one command fails using chaining notation', (done) => {
|
||||
const batch1 = client.batch()
|
||||
batch1.mset('batchfoo', '10', 'batchbar', '20', helper.isString('OK'))
|
||||
|
||||
// Provoke an error at queue time
|
||||
batch1.set('foo2', helper.isError())
|
||||
batch1.incr('batchfoo')
|
||||
batch1.incr('batchbar')
|
||||
batch1.exec(function () {
|
||||
batch1.exec(() => {
|
||||
// Confirm that the previous command, while containing an error, still worked.
|
||||
batch2 = client.batch()
|
||||
const batch2 = client.batch()
|
||||
batch2.get('foo2', helper.isNull())
|
||||
batch2.incr('batchbar', helper.isNumber(22))
|
||||
batch2.incr('batchfoo', helper.isNumber(12))
|
||||
batch2.exec(function (err, replies) {
|
||||
batch2.exec((err, replies) => {
|
||||
assert.strictEqual(err, null)
|
||||
assert.strictEqual(null, replies[0])
|
||||
assert.strictEqual(22, replies[1])
|
||||
@@ -125,19 +123,18 @@ describe('The \'batch\' method', function () {
|
||||
})
|
||||
})
|
||||
|
||||
it('fail individually when one command fails and emit the error if no callback has been provided', function (done) {
|
||||
var batch1
|
||||
client.on('error', function (err) {
|
||||
it('fail individually when one command fails and emit the error if no callback has been provided', (done) => {
|
||||
client.on('error', (err) => {
|
||||
done(err)
|
||||
})
|
||||
batch1 = client.batch()
|
||||
const batch1 = client.batch()
|
||||
batch1.mset('batchfoo', '10', 'batchbar', '20', helper.isString('OK'))
|
||||
|
||||
// Provoke an error at queue time
|
||||
batch1.set('foo2')
|
||||
batch1.incr('batchfoo')
|
||||
batch1.incr('batchbar')
|
||||
batch1.exec(function (err, res) {
|
||||
batch1.exec((err, res) => {
|
||||
// TODO: This should actually return an error!
|
||||
assert.strictEqual(err, null)
|
||||
assert.strictEqual(res[1].command, 'SET')
|
||||
@@ -146,14 +143,14 @@ describe('The \'batch\' method', function () {
|
||||
})
|
||||
})
|
||||
|
||||
it('fail individually when one command in an array of commands fails', function (done) {
|
||||
it('fail individually when one command in an array of commands fails', (done) => {
|
||||
// test nested batch-bulk replies
|
||||
client.batch([
|
||||
['mget', 'batchfoo', 'batchbar', helper.isDeepEqual([null, null])],
|
||||
['set', 'foo2', helper.isError()],
|
||||
['incr', 'batchfoo'],
|
||||
['incr', 'batchbar']
|
||||
]).exec(function (err, replies) {
|
||||
]).exec((err, replies) => {
|
||||
// TODO: This should actually return an error!
|
||||
assert.strictEqual(err, null)
|
||||
assert.strictEqual(2, replies[0].length)
|
||||
@@ -166,7 +163,7 @@ describe('The \'batch\' method', function () {
|
||||
})
|
||||
})
|
||||
|
||||
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')
|
||||
@@ -174,7 +171,7 @@ describe('The \'batch\' method', function () {
|
||||
|
||||
// make sure empty mb reply works
|
||||
client.del('some missing set')
|
||||
client.smembers('some missing set', function (err, reply) {
|
||||
client.smembers('some missing set', (err, reply) => {
|
||||
assert.strictEqual(err, null)
|
||||
// make sure empty mb reply works
|
||||
assert.strictEqual(0, reply.length)
|
||||
@@ -187,7 +184,7 @@ describe('The \'batch\' method', function () {
|
||||
['smembers', 'some set', undefined] // The explicit undefined is handled as a callback that is undefined
|
||||
])
|
||||
.scard('some set')
|
||||
.exec(function (err, replies) {
|
||||
.exec((err, replies) => {
|
||||
assert.strictEqual(err, null)
|
||||
assert.strictEqual(4, replies[0].length)
|
||||
assert.strictEqual(0, replies[2].length)
|
||||
@@ -195,12 +192,12 @@ describe('The \'batch\' method', function () {
|
||||
})
|
||||
})
|
||||
|
||||
it('allows multiple operations to be performed using constructor with all kinds of syntax', function (done) {
|
||||
var now = Date.now()
|
||||
var arr = ['batchhmset', 'batchbar', 'batchbaz']
|
||||
var arr2 = ['some manner of key', 'otherTypes']
|
||||
var arr3 = [5768, 'batchbarx', 'batchfoox']
|
||||
var arr4 = ['mset', [578, 'batchbar'], helper.isString('OK')]
|
||||
it('allows multiple operations to be performed using constructor with all kinds of syntax', (done) => {
|
||||
const now = Date.now()
|
||||
const arr = ['batchhmset', 'batchbar', 'batchbaz']
|
||||
const arr2 = ['some manner of key', 'otherTypes']
|
||||
const arr3 = [5768, 'batchbarx', 'batchfoox']
|
||||
const arr4 = ['mset', [578, 'batchbar'], helper.isString('OK')]
|
||||
client.batch([
|
||||
arr4,
|
||||
[['mset', 'batchfoo2', 'batchbar2', 'batchfoo3', 'batchbar3'], helper.isString('OK')],
|
||||
@@ -214,15 +211,15 @@ describe('The \'batch\' method', function () {
|
||||
['hmset', 'batchhmset', ['batchbar', 'batchbaz'], helper.isString('OK')]
|
||||
])
|
||||
.hmget(now, 123456789, 'otherTypes')
|
||||
.hmget('key2', arr2, function noop () {})
|
||||
.hmget('key2', arr2, () => {})
|
||||
.hmget(['batchhmset2', 'some manner of key', 'batchbar3'])
|
||||
.mget('batchfoo2', ['batchfoo3', 'batchfoo'], function (err, res) {
|
||||
.mget('batchfoo2', ['batchfoo3', 'batchfoo'], (err, res) => {
|
||||
assert.strictEqual(err, null)
|
||||
assert.strictEqual(res[0], 'batchbar2')
|
||||
assert.strictEqual(res[1], 'batchbar3')
|
||||
assert.strictEqual(res[2], null)
|
||||
})
|
||||
.exec(function (err, replies) {
|
||||
.exec((err, replies) => {
|
||||
assert.strictEqual(arr.length, 3)
|
||||
assert.strictEqual(arr2.length, 2)
|
||||
assert.strictEqual(arr3.length, 3)
|
||||
@@ -239,7 +236,7 @@ describe('The \'batch\' 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.batch().hmset(true, {
|
||||
test: 123,
|
||||
@@ -247,21 +244,19 @@ describe('The \'batch\' method', function () {
|
||||
}).exec(done)
|
||||
})
|
||||
|
||||
it('runs a batch without any further commands', function (done) {
|
||||
var buffering = client.batch().exec(function (err, res) {
|
||||
it('runs a batch without any further commands', (done) => {
|
||||
client.batch().exec((err, res) => {
|
||||
assert.strictEqual(err, null)
|
||||
assert.strictEqual(res.length, 0)
|
||||
done()
|
||||
})
|
||||
assert(typeof buffering === 'boolean')
|
||||
})
|
||||
|
||||
it('runs a batch without any further commands and without callback', function () {
|
||||
var buffering = client.batch().exec()
|
||||
assert.strictEqual(buffering, true)
|
||||
it('runs a batch without any further commands and without callback', () => {
|
||||
client.batch().exec()
|
||||
})
|
||||
|
||||
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.batch()
|
||||
.mset('some', '10', 'keys', '20')
|
||||
.incr('some')
|
||||
@@ -270,7 +265,7 @@ describe('The \'batch\' 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.batch()
|
||||
.mset(['some', '10', 'keys', '20'])
|
||||
.incr('some', helper.isNumber(11))
|
||||
@@ -279,25 +274,25 @@ describe('The \'batch\' 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.batch()
|
||||
.mset(['some', '10', 'keys', '20'])
|
||||
.incr('some', helper.isNumber(11))
|
||||
.incr(['keys'], helper.isNumber(21))
|
||||
.mget('some', 'keys')
|
||||
.execAsync()
|
||||
.then(function (res) {
|
||||
.then((res) => {
|
||||
helper.isDeepEqual(['OK', 11, 21, ['11', '21']])(null, res)
|
||||
})
|
||||
})
|
||||
|
||||
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 batch-bulk replies with nulls.
|
||||
client.batch([
|
||||
['mget', ['batchfoo', 'some', 'random value', 'keys']],
|
||||
['incr', 'batchfoo']
|
||||
])
|
||||
.exec(function (err, replies) {
|
||||
.exec((err, replies) => {
|
||||
assert.strictEqual(err, null)
|
||||
assert.strictEqual(replies.length, 2)
|
||||
assert.strictEqual(replies[0].length, 4)
|
||||
@@ -305,7 +300,7 @@ describe('The \'batch\' method', function () {
|
||||
})
|
||||
})
|
||||
|
||||
it('allows multiple operations to be performed on a hash', function (done) {
|
||||
it('allows multiple operations to be performed on a hash', (done) => {
|
||||
client.batch()
|
||||
.hmset('batchhash', 'a', 'foo', 'b', 1)
|
||||
.hmset('batchhash', {
|
||||
@@ -316,8 +311,8 @@ describe('The \'batch\' method', function () {
|
||||
.exec(done)
|
||||
})
|
||||
|
||||
it('should work without any callback or arguments', function (done) {
|
||||
var batch = client.batch()
|
||||
it('should work without any callback or arguments', (done) => {
|
||||
const batch = client.batch()
|
||||
batch.set('baz', 'binary')
|
||||
batch.set('foo', 'bar')
|
||||
batch.ping()
|
||||
|
Reference in New Issue
Block a user