Skip to content

Commit ad805b2

Browse files
committed
count failed attempts on server and verify it matches the expected count, document retry defaults
1 parent 4aebab3 commit ad805b2

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

README.md

+11-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,17 @@ Start an anger instance against a given target.
5858
* `auth`: A `Function` or `Object` passed to the nes client for authentication. If a `Function`, it is passed the `client` and `index` of that client as params. Must return the auth object options. If an `Object`, it must be passed the auth object options. [auth object reference.][nes-auth]
5959
* `identifier`: A function used to map some payload response data to a requests uid.
6060
* `trigger`: A function which is passed a nes client to emit a message to the server for testing. Must return some uid of a message sent.
61-
* `retryOpts`: An object which is passed to [try-again](try-again) to achieve exponential backoff for retries. [Check the try-again docs for reference on how to use it.](try-again)
61+
* `retryOpts`: An object which is passed to [try-again](try-again) to achieve exponential backoff for retries. [Check the try-again docs for reference on how to use it.](try-again). Default values below:
62+
```js
63+
{
64+
retries: 8,
65+
max: 10000,
66+
jitter: 0.2,
67+
factor: 2,
68+
min: 100
69+
}
70+
```
71+
6272

6373
**Returns** an instance/event emitter for tracking progress, etc.
6474

test/authServer.js

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ function build (cb) {
1111
})
1212

1313
server.count = 0
14+
server.failedCount = 0
1415

1516
server.register([Basic, Nes], function (err) {
1617
if (err) { throw err }
@@ -32,6 +33,7 @@ function build (cb) {
3233
var validate = function (request, username, password, callback) {
3334
var user = server.users[username]
3435
if (!user) {
36+
server.failedCount++
3537
return callback(null, false)
3638
}
3739
server.users[username].signin++

test/failed-auth.test.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const test = require('tap').test
44
const anger = require('..')
55

66
test('failed auth', { timeout: 3000 }, (t) => {
7-
t.plan(2)
7+
t.plan(3)
88

99
require('./authServer')((err, server) => {
1010
t.error(err)
@@ -18,7 +18,7 @@ test('failed auth', { timeout: 3000 }, (t) => {
1818
senders: 1,
1919
connections: 10,
2020
identifier: (payload) => payload.meta.id,
21-
auth: { headers: { authorization: 'Basic failing' } },
21+
auth: { headers: { authorization: `Basic ${new Buffer('jane:jane').toString('base64')}` } },
2222
requests: 1,
2323
responses: 10,
2424
trigger: (sender) => {
@@ -38,6 +38,7 @@ test('failed auth', { timeout: 3000 }, (t) => {
3838

3939
instance.on('error', (err) => {
4040
t.ok(err, 'error happened')
41+
t.equal(server.failedCount, 10)
4142
})
4243

4344
instance.on('end', () => {

0 commit comments

Comments
 (0)