1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-09 00:22:08 +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

@@ -2,22 +2,22 @@
// helpers for configuring a redis client in
// its various modes, ipV6, ipV4, socket.
var redis = require('../../index')
var bluebird = require('bluebird')
const redis = require('../../index')
const bluebird = require('bluebird')
// Promisify everything
bluebird.promisifyAll(redis.RedisClient.prototype)
bluebird.promisifyAll(redis.Multi.prototype)
var config = {
redis: redis,
const config = {
redis,
PORT: 6379,
HOST: {
IPv4: '127.0.0.1',
IPv6: '::1'
},
configureClient: function (ip, opts) {
var args = []
configureClient (ip, opts) {
const args = []
// Do not manipulate the opts => copy them each time
opts = opts ? JSON.parse(JSON.stringify(opts)) : {}

View File

@@ -1,20 +1,20 @@
// Spawned by the goodStacks.spec.js tests
'use strict'
var assert = require('assert')
var redis = require('../../index')
var client = redis.createClient()
const assert = require('assert')
const redis = require('../../index')
const client = redis.createClient()
// Both error cases would normally return bad stack traces
client.set('foo', function (err, res) {
client.set('foo', (err, res) => {
assert(/good-traces.js:9:8/.test(err.stack))
client.set('foo', 'bar', function (err, res) {
client.set('foo', 'bar', (err, res) => {
assert(/good-traces.js:11:10/.test(err.stack))
client.quit(function () {
client.quit(() => {
process.exit(0)
})
})
process.nextTick(function () {
process.nextTick(() => {
client.stream.destroy()
})
})

View File

@@ -1,82 +1,82 @@
'use strict'
// helper to start and stop the redis process.
var config = require('./config')
var fs = require('fs')
var path = require('path')
var spawn = require('win-spawn')
var tcpPortUsed = require('tcp-port-used')
var bluebird = require('bluebird')
const config = require('./config')
const fs = require('fs')
const path = require('path')
const spawn = require('win-spawn')
const tcpPortUsed = require('tcp-port-used')
const bluebird = require('bluebird')
// wait for redis to be listening in
// all three modes (ipv4, ipv6, socket).
function waitForRedis (available, cb, port) {
if (process.platform === 'win32') return cb()
var time = Date.now()
var running = false
var socket = '/tmp/redis.sock'
const time = Date.now()
let running = false
let socket = '/tmp/redis.sock'
if (port) {
// We have to distinguish the redis sockets if we have more than a single redis instance running
socket = '/tmp/redis' + port + '.sock'
socket = `/tmp/redis${port}.sock`
}
port = port || config.PORT
var id = setInterval(function () {
const id = setInterval(() => {
if (running) return
running = true
bluebird.join(
tcpPortUsed.check(port, '127.0.0.1'),
tcpPortUsed.check(port, '::1'),
function (ipV4, ipV6) {
(ipV4, ipV6) => {
if (ipV6 === available && ipV4 === available) {
if (fs.existsSync(socket) === available) {
clearInterval(id)
return cb()
}
// The same message applies for can't stop but we ignore that case
throw new Error('Port ' + port + ' is already in use. Tests can\'t start.\n')
throw new Error(`Port ${port} is already in use. Tests can't start.\n`)
}
if (Date.now() - time > 6000) {
throw new Error('Redis could not start on port ' + (port || config.PORT) + '\n')
throw new Error(`Redis could not start on port ${port || config.PORT}\n`)
}
running = false
}).catch(function (err) {
console.error('\x1b[31m' + err.stack + '\x1b[0m\n')
}).catch((err) => {
console.error(`\x1b[31m${err.stack}\x1b[0m\n`)
process.exit(1)
})
}, 100)
}
module.exports = {
start: function (done, conf, port) {
var spawnFailed = false
start (done, conf, port) {
let spawnFailed = false
// spawn redis with our testing configuration.
var confFile = conf || path.resolve(__dirname, '../conf/redis.conf')
var rp = spawn('redis-server', [confFile], {})
const confFile = conf || path.resolve(__dirname, '../conf/redis.conf')
const rp = spawn('redis-server', [confFile], {})
// capture a failure booting redis, and give
// the user running the test some directions.
rp.once('exit', function (code) {
rp.once('exit', (code) => {
if (code !== 0) spawnFailed = true
})
// wait for redis to become available, by
// checking the port we bind on.
waitForRedis(true, function () {
waitForRedis(true, () => {
// return an object that can be used in
// an after() block to shutdown redis.
return done(null, {
spawnFailed: function () {
spawnFailed () {
return spawnFailed
},
stop: function (done) {
stop (done) {
if (spawnFailed) return done()
rp.once('exit', function (code) {
var error = null
rp.once('exit', (code) => {
let error = null
if (code !== null && code !== 0) {
error = new Error('Redis shutdown failed with code ' + code)
error = new Error(`Redis shutdown failed with code ${code}`)
}
waitForRedis(false, function () {
waitForRedis(false, () => {
return done(error)
}, port)
})

View File

@@ -1,14 +1,14 @@
'use strict'
// helper to start and stop the stunnel process.
var spawn = require('child_process').spawn
var EventEmitter = require('events')
var fs = require('fs')
var path = require('path')
var util = require('util')
const spawn = require('child_process').spawn
const EventEmitter = require('events')
const fs = require('fs')
const path = require('path')
const util = require('util')
function once (cb) {
var called = false
let called = false
return function () {
if (called) return
called = true
@@ -20,29 +20,29 @@ function StunnelProcess (confDir) {
EventEmitter.call(this)
// set up an stunnel to redis; edit the conf file to include required absolute paths
var confFile = path.resolve(confDir, 'stunnel.conf')
var confText = fs.readFileSync(confFile + '.template').toString().replace(/__dirname,/g, confDir)
const confFile = path.resolve(confDir, 'stunnel.conf')
const confText = fs.readFileSync(`${confFile }.template`).toString().replace(/__dirname,/g, confDir)
fs.writeFileSync(confFile, confText)
var stunnel = this.stunnel = spawn('stunnel', [confFile])
const stunnel = this.stunnel = spawn('stunnel', [confFile])
// handle child process events, and failure to set up tunnel
var self = this
this.timer = setTimeout(function () {
const self = this
this.timer = setTimeout(() => {
self.emit('error', new Error('Timeout waiting for stunnel to start'))
}, 8000)
stunnel.on('error', function (err) {
stunnel.on('error', (err) => {
self.clear()
self.emit('error', err)
})
stunnel.on('exit', function (code) {
stunnel.on('exit', (code) => {
self.clear()
if (code === 0) {
self.emit('stopped')
} else {
self.emit('error', new Error('Stunnel exited unexpectedly; code = ' + code))
self.emit('error', new Error(`Stunnel exited unexpectedly; code = ${code}`))
}
})
@@ -68,13 +68,13 @@ StunnelProcess.prototype.stop = function (done) {
}
module.exports = {
start: function (done, confDir) {
start (done, confDir) {
done = once(done)
var stunnel = new StunnelProcess(confDir)
const stunnel = new StunnelProcess(confDir)
stunnel.once('error', done.bind(done))
stunnel.once('started', done.bind(done, null, stunnel))
},
stop: function (stunnel, done) {
stop (stunnel, done) {
stunnel.removeAllListeners()
stunnel.stop()
stunnel.once('error', done.bind(done))

View File

@@ -3,13 +3,13 @@
// as soon as there are no outstanding commands.
'use strict'
var redis = require('../../index')
var HOST = process.argv[2] || '127.0.0.1'
var PORT = process.argv[3]
var args = PORT ? [PORT, HOST] : [HOST]
const redis = require('../../index')
const HOST = process.argv[2] || '127.0.0.1'
const PORT = process.argv[3]
const args = PORT ? [PORT, HOST] : [HOST]
var c = redis.createClient.apply(redis, args)
c.info(function (err, reply) {
const c = redis.createClient.apply(redis, args)
c.info((err, reply) => {
if (err) process.exit(-1)
if (!reply.length) process.exit(-1)
process.stdout.write(reply.length.toString())