Name: js-handler/node_modules/restify/node_modules/backoff/tests/fibonacci_backoff_strategy.js 
1:
/*
2:
 * Copyright (c) 2012 Mathieu Turcotte
3:
 * Licensed under the MIT license.
4:
 */
5:
 
6:
var sinon = require('sinon');
7:
 
8:
var FibonacciBackoffStrategy = require('../lib/strategy/fibonacci');
9:
 
10:
exports["FibonacciBackoffStrategy"] = {
11:
    setUp: function(callback) {
12:
        this.strategy = new FibonacciBackoffStrategy({
13:
            initialDelay: 10,
14:
            maxDelay: 1000
15:
        });
16:
        callback();
17:
    },
18:
 
19:
    "backoff delays should follow a Fibonacci sequence": function(test) {
20:
        // Fibonacci sequence: x[i] = x[i-1] + x[i-2].
21:
        var expectedDelays = [10, 10, 20, 30, 50, 80, 130, 210, 340, 550, 890, 1000];
22:
        var actualDelays = [];
23:
 
24:
        for (var i = 0; i < expectedDelays.length; i++) {
25:
            actualDelays.push(this.strategy.next());
26:
        }
27:
 
28:
        test.deepEqual(expectedDelays, actualDelays,
29:
            'Generated delays should follow a Fibonacci sequence.');
30:
        test.done();
31:
    },
32:
 
33:
    "backoff delays should restart from the initial delay after reset": function(test) {
34:
        var strategy = new FibonacciBackoffStrategy({
35:
            initialDelay: 10,
36:
            maxDelay: 1000
37:
        });
38:
 
39:
        strategy.next();
40:
        strategy.reset();
41:
 
42:
        var backoffDelay = strategy.next();
43:
        test.equals(backoffDelay, 10,
44:
            'Strategy should return the initial delay after reset.');
45:
        test.done();
46:
    }
47:
};