Skip to content

Commit

Permalink
Add unit tests for ExponentialBackoff
Browse files Browse the repository at this point in the history
  • Loading branch information
orangejulius committed Jul 15, 2015
1 parent 5e1a184 commit bc459d2
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
33 changes: 33 additions & 0 deletions test/ExponentialBackoff.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@

var tape = require( 'tape' );
var ExponentialBackoff = require( '../lib/ExponentialBackoff' );


tape( 'ExponentialBackoff', function(test) {
test.test( 'calling increaseBackoff() makes backoff larger', function(t) {
var eb = new ExponentialBackoff();
var startBackoff = eb.getBackoff();
eb.increaseBackoff();
t.ok(startBackoff < eb.getBackoff(), 'backoff was not higher');
t.end();
});

test.test( 'calling decreaseBackoff() lowers backoff', function(t) {
var eb = new ExponentialBackoff();
eb.increaseBackoff();
var startBackoff = eb.getBackoff();
eb.decreaseBackoff();
t.ok(startBackoff > eb.getBackoff(), 'backoff was not lower');
t.end();
});

test.test( 'calling decreaseBackoff() will not lower backoff below minimum', function(t) {
var eb = new ExponentialBackoff();
var startBackoff = eb.getBackoff();
eb.decreaseBackoff();
t.ok(startBackoff === eb.getBackoff(), 'backoff was not equal');
t.end();
});

test.end();
});
1 change: 1 addition & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
'use strict';

require('./fuzzy-tester');
require('./ExponentialBackoff');

0 comments on commit bc459d2

Please sign in to comment.