-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add udpSocketOptions as a StatsD option (#231)
This options allows the library user to control how the UDP socket is created. If not specified, we maintain existing compatibility by defaulting to a udp4 socket family with no other options. Fixes #223
- Loading branch information
Showing
5 changed files
with
54 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
const assert = require('assert'); | ||
const helpers = require('./helpers/helpers.js'); | ||
const dns = require('dns'); | ||
const dgram = require('dgram'); | ||
|
||
const closeAll = helpers.closeAll; | ||
const createServer = helpers.createServer; | ||
const createHotShotsClient = helpers.createHotShotsClient; | ||
|
||
describe('#udpSocketOptions', () => { | ||
const udpServerType = 'udp'; | ||
const originalDnsLookup = dns.lookup; | ||
const originalDgramCreateSocket = dgram.createSocket; | ||
let server; | ||
let statsd; | ||
|
||
afterEach(done => { | ||
dns.lookup = originalDnsLookup; | ||
dgram.createSocket = originalDgramCreateSocket; | ||
closeAll(server, statsd, false, done); | ||
}); | ||
|
||
it('should use custom DNS lookup function', done => { | ||
const resolvedHostAddress = '127.0.0.1'; | ||
let dnsLookupCount = 0; | ||
const customDnsLookup = (host, options, callback) => { | ||
dnsLookupCount++; | ||
callback(undefined, resolvedHostAddress); | ||
}; | ||
|
||
server = createServer(udpServerType, opts => { | ||
statsd = createHotShotsClient(Object.assign(opts, { | ||
cacheDns: true, | ||
udpSocketOptions: { | ||
type: 'udp4', | ||
lookup: customDnsLookup, | ||
}, | ||
}), 'client'); | ||
|
||
statsd.send('test title', {}, (error) => { | ||
assert.strictEqual(error, null); | ||
setTimeout(() => { | ||
assert.strictEqual(dnsLookupCount, 2); | ||
done(); | ||
}, 1000); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters