Skip to content

Commit

Permalink
Apply prettier formatting (#345)
Browse files Browse the repository at this point in the history
  • Loading branch information
dudleycarr authored Jun 6, 2021
1 parent dabd5ff commit 55f4e44
Show file tree
Hide file tree
Showing 12 changed files with 170 additions and 188 deletions.
4 changes: 2 additions & 2 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ class ConnectionConfig {
* @param {*} value
*/
isLookupdHTTPAddresses(option, value) {
const isAddr = addr => {
const isAddr = (addr) => {
if (addr.indexOf('://') === -1) {
return ConnectionConfig.isBareAddress(addr)
}
Expand Down Expand Up @@ -326,7 +326,7 @@ class ReaderConfig extends ConnectionConfig {
super.validate(...args)

const pass = _.chain(addresses)
.map(key => this[key].length)
.map((key) => this[key].length)
.some(_.identity)
.value()

Expand Down
10 changes: 5 additions & 5 deletions lib/lookupd.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function lookupdRequest(url, callback) {
timeout: 2000,
}

const requestWithRetry = cb => request(options, cb)
const requestWithRetry = (cb) => request(options, cb)
const retryOptions = {times: 3, interval: 500}

async.retry(retryOptions, requestWithRetry, (err, response, data = {}) => {
Expand Down Expand Up @@ -68,7 +68,7 @@ function dedupeOnHostPort(results) {
// Flatten list of lists of objects
.flatten()
// De-dupe nodes by broadcast address / port
.keyBy(item => {
.keyBy((item) => {
if (item.broadcast_address) {
return `${item.broadcast_address}:${item.tcp_port}`
} else {
Expand All @@ -80,14 +80,14 @@ function dedupeOnHostPort(results) {
)
}

const dedupedRequests = function(lookupdEndpoints, urlFn, callback) {
const dedupedRequests = function (lookupdEndpoints, urlFn, callback) {
// Ensure we have a list of endpoints for lookupds.
if (_.isString(lookupdEndpoints)) {
lookupdEndpoints = [lookupdEndpoints]
}

// URLs for querying `nodes` on each of the lookupds.
const urls = Array.from(lookupdEndpoints).map(endpoint => urlFn(endpoint))
const urls = Array.from(lookupdEndpoints).map((endpoint) => urlFn(endpoint))

return async.map(urls, lookupdRequest, (err, results) => {
if (err) {
Expand All @@ -110,7 +110,7 @@ const dedupedRequests = function(lookupdEndpoints, urlFn, callback) {
* is a list of objects return by lookupds and deduped.
*/
function lookup(lookupdEndpoints, topic, callback) {
const endpointURL = endpoint => {
const endpointURL = (endpoint) => {
if (endpoint.indexOf('://') === -1) {
endpoint = `http://${endpoint}`
}
Expand Down
8 changes: 4 additions & 4 deletions lib/nsqdconnection.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,11 @@ class NSQDConnection extends EventEmitter {
* @param {Object} conn
*/
registerStreamListeners(conn) {
conn.on('data', data => this.receiveRawData(data))
conn.on('data', (data) => this.receiveRawData(data))
conn.on('end', () => {
this.statemachine.goto('CLOSED')
})
conn.on('error', err => {
conn.on('error', (err) => {
this.statemachine.goto('ERROR', err)
this.emit('connection_error', err)
})
Expand Down Expand Up @@ -348,7 +348,7 @@ class NSQDConnection extends EventEmitter {
'sample_rate',
]

removableKeys.forEach(key => {
removableKeys.forEach((key) => {
if (identify[key] === null) {
delete identify[key]
}
Expand Down Expand Up @@ -817,7 +817,7 @@ ConnectionState.prototype.states = {

ConnectionState.prototype.transitions = {
'*': {
'*': function(data, callback) {
'*': function (data, callback) {
this.log()
return callback(data)
},
Expand Down
10 changes: 5 additions & 5 deletions lib/writer.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,13 @@ class Writer extends EventEmitter {
this.emit(Writer.CLOSED)
})

this.conn.on(WriterNSQDConnection.ERROR, err => {
this.conn.on(WriterNSQDConnection.ERROR, (err) => {
this.debug('error', err)
this.ready = false
this.emit(Writer.ERROR, err)
})

this.conn.on(WriterNSQDConnection.CONNECTION_ERROR, err => {
this.conn.on(WriterNSQDConnection.CONNECTION_ERROR, (err) => {
this.debug('error', err)
this.ready = false
this.emit(Writer.ERROR, err)
Expand Down Expand Up @@ -121,7 +121,7 @@ class Writer extends EventEmitter {

// Call publish again once the Writer is ready.
if (!this.ready) {
const onReady = err => {
const onReady = (err) => {
if (err) return callback(err)
this.publish(topic, msgs, callback)
}
Expand Down Expand Up @@ -161,7 +161,7 @@ class Writer extends EventEmitter {

// Call publish again once the Writer is ready.
if (!this.ready) {
const onReady = err => {
const onReady = (err) => {
if (err) return callback(err)
this.deferPublish(topic, msg, timeMs, callback)
}
Expand Down Expand Up @@ -224,7 +224,7 @@ class Writer extends EventEmitter {
fn()
}

const failed = err => {
const failed = (err) => {
if (!err) {
err = new Error('Connection closed!')
}
Expand Down
25 changes: 5 additions & 20 deletions test/backofftimer_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,44 +50,29 @@ describe('backofftimer', () => {

describe('getInterval', () => {
it('should initially be 0', () => {
timer
.getInterval()
.toString()
.should.eql('0')
timer.getInterval().toString().should.eql('0')
})

it('should be 0 after 1 success', () => {
timer.success()
timer
.getInterval()
.toString()
.should.eql('0')
timer.getInterval().toString().should.eql('0')
})

it('should be 0 after 2 successes', () => {
timer.success()
timer.success()
timer
.getInterval()
.toString()
.should.eql('0')
timer.getInterval().toString().should.eql('0')
})

it('should be 3.584 after 1 failure', () => {
timer.failure()
timer
.getInterval()
.toString()
.should.eql('3.584')
timer.getInterval().toString().should.eql('3.584')
})

it('should be 7.168 after 2 failure', () => {
timer.failure()
timer.failure()
timer
.getInterval()
.toString()
.should.eql('7.168')
timer.getInterval().toString().should.eql('7.168')
})
})
})
44 changes: 19 additions & 25 deletions test/lookupd_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const LOOKUPD_2 = '127.0.0.1:5161'
const LOOKUPD_3 = 'http://127.0.0.1:6161/'
const LOOKUPD_4 = 'http://127.0.0.1:7161/path/lookup'

const nockUrlSplit = url => {
const nockUrlSplit = (url) => {
const match = url.match(/^(https?:\/\/[^/]+)(\/.*$)/i)
return {
baseUrl: match[1],
Expand All @@ -62,7 +62,7 @@ const registerWithLookupd = (lookupdAddress, nsqd) => {
const producers = nsqd != null ? [nsqd] : []

if (nsqd != null) {
nsqd.topics.forEach(topic => {
nsqd.topics.forEach((topic) => {
if (lookupdAddress.indexOf('://') === -1) {
nock(`http://${lookupdAddress}`)
.get(`/lookup?topic=${topic}`)
Expand All @@ -79,31 +79,27 @@ const registerWithLookupd = (lookupdAddress, nsqd) => {
path = '/lookup'
}

nock(baseUrl)
.get(`${path}?topic=${topic}`)
.reply(200, {
status_code: 200,
status_txt: 'OK',
producers,
})
nock(baseUrl).get(`${path}?topic=${topic}`).reply(200, {
status_code: 200,
status_txt: 'OK',
producers,
})
}
})
}
}

const setFailedTopicReply = (lookupdAddress, topic) =>
nock(`http://${lookupdAddress}`)
.get(`/lookup?topic=${topic}`)
.reply(200, {
status_code: 404,
status_txt: 'TOPIC_NOT_FOUND',
})
nock(`http://${lookupdAddress}`).get(`/lookup?topic=${topic}`).reply(200, {
status_code: 404,
status_txt: 'TOPIC_NOT_FOUND',
})

describe('lookupd.lookup', () => {
afterEach(() => nock.cleanAll())

describe('querying a single lookupd for a topic', () => {
it('should return an empty list if no nsqd nodes', done => {
it('should return an empty list if no nsqd nodes', (done) => {
setFailedTopicReply(LOOKUPD_1, 'sample_topic')

lookup(LOOKUPD_1, 'sample_topic', (err, nodes) => {
Expand All @@ -112,13 +108,13 @@ describe('lookupd.lookup', () => {
})
})

it('should return a list of nsqd nodes for a success reply', done => {
it('should return a list of nsqd nodes for a success reply', (done) => {
registerWithLookupd(LOOKUPD_1, NSQD_1)

lookup(LOOKUPD_1, 'sample_topic', (err, nodes) => {
nodes.should.have.length(1)
;['address', 'broadcast_address', 'tcp_port', 'http_port'].forEach(
key => {
(key) => {
should.ok(_.keys(nodes[0]).includes(key))
}
)
Expand All @@ -128,7 +124,7 @@ describe('lookupd.lookup', () => {
})

describe('querying a multiple lookupd', () => {
it('should combine results from multiple lookupds', done => {
it('should combine results from multiple lookupds', (done) => {
registerWithLookupd(LOOKUPD_1, NSQD_1)
registerWithLookupd(LOOKUPD_2, NSQD_2)
registerWithLookupd(LOOKUPD_3, NSQD_3)
Expand All @@ -138,15 +134,15 @@ describe('lookupd.lookup', () => {
lookup(lookupdAddresses, 'sample_topic', (err, nodes) => {
nodes.should.have.length(4)
_.chain(nodes)
.map(n => n['tcp_port'])
.map((n) => n['tcp_port'])
.sort()
.value()
.should.be.eql([4150, 5150, 6150, 7150])
done(err)
})
})

it('should dedupe combined results', done => {
it('should dedupe combined results', (done) => {
registerWithLookupd(LOOKUPD_1, NSQD_1)
registerWithLookupd(LOOKUPD_2, NSQD_1)
registerWithLookupd(LOOKUPD_3, NSQD_1)
Expand All @@ -159,11 +155,9 @@ describe('lookupd.lookup', () => {
})
})

return it('should succeed inspite of failures to query a lookupd', done => {
return it('should succeed inspite of failures to query a lookupd', (done) => {
registerWithLookupd(LOOKUPD_1, NSQD_1)
nock(`http://${LOOKUPD_2}`)
.get('/lookup?topic=sample_topic')
.reply(500)
nock(`http://${LOOKUPD_2}`).get('/lookup?topic=sample_topic').reply(500)

const lookupdAddresses = [LOOKUPD_1, LOOKUPD_2]
lookup(lookupdAddresses, 'sample_topic', (err, nodes) => {
Expand Down
8 changes: 4 additions & 4 deletions test/message_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const createMessage = (body, requeueDelay, timeout, maxTimeout) => {

describe('Message', () =>
describe('timeout', () => {
it('should not allow finishing a message twice', done => {
it('should not allow finishing a message twice', (done) => {
const msg = createMessage('body', 90, 50, 100)

const firstFinish = () => msg.finish()
Expand All @@ -27,7 +27,7 @@ describe('Message', () =>
setTimeout(secondFinish, 20)
})

it('should not allow requeue after finish', done => {
it('should not allow requeue after finish', (done) => {
const msg = createMessage('body', 90, 50, 100)

const responseSpy = sinon.spy()
Expand All @@ -46,7 +46,7 @@ describe('Message', () =>
setTimeout(check, 20)
})

it('should allow touch and then finish post first timeout', done => {
it('should allow touch and then finish post first timeout', (done) => {
const touchIn = 15
const timeoutIn = 20
const finishIn = 25
Expand All @@ -73,7 +73,7 @@ describe('Message', () =>
setTimeout(check, checkIn)
})

return it('should clear timeout on finish', done => {
return it('should clear timeout on finish', (done) => {
const msg = createMessage('body', 10, 60, 120)
msg.finish()

Expand Down
Loading

0 comments on commit 55f4e44

Please sign in to comment.