|
1 | 1 | /**
|
2 |
| - * Copyright 2019, Optimizely |
| 2 | + * Copyright 2019-2020, Optimizely |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
14 | 14 | * limitations under the License.
|
15 | 15 | */
|
16 | 16 |
|
17 |
| -import BackoffController from '../src/backoffController' |
| 17 | +import BackoffController from '../src/backoffController'; |
18 | 18 |
|
19 | 19 | describe('backoffController', () => {
|
20 | 20 | describe('getDelay', () => {
|
21 | 21 | it('returns 0 from getDelay if there have been no errors', () => {
|
22 |
| - const controller = new BackoffController() |
23 |
| - expect(controller.getDelay()).toBe(0) |
24 |
| - }) |
| 22 | + const controller = new BackoffController(); |
| 23 | + expect(controller.getDelay()).toBe(0); |
| 24 | + }); |
25 | 25 |
|
26 | 26 | it('increases the delay returned from getDelay (up to a maximum value) after each call to countError', () => {
|
27 |
| - const controller = new BackoffController() |
28 |
| - controller.countError() |
29 |
| - expect(controller.getDelay()).toBeGreaterThanOrEqual(8000) |
30 |
| - expect(controller.getDelay()).toBeLessThan(9000) |
31 |
| - controller.countError() |
32 |
| - expect(controller.getDelay()).toBeGreaterThanOrEqual(16000) |
33 |
| - expect(controller.getDelay()).toBeLessThan(17000) |
34 |
| - controller.countError() |
35 |
| - expect(controller.getDelay()).toBeGreaterThanOrEqual(32000) |
36 |
| - expect(controller.getDelay()).toBeLessThan(33000) |
37 |
| - controller.countError() |
38 |
| - expect(controller.getDelay()).toBeGreaterThanOrEqual(64000) |
39 |
| - expect(controller.getDelay()).toBeLessThan(65000) |
40 |
| - controller.countError() |
41 |
| - expect(controller.getDelay()).toBeGreaterThanOrEqual(128000) |
42 |
| - expect(controller.getDelay()).toBeLessThan(129000) |
43 |
| - controller.countError() |
44 |
| - expect(controller.getDelay()).toBeGreaterThanOrEqual(256000) |
45 |
| - expect(controller.getDelay()).toBeLessThan(257000) |
46 |
| - controller.countError() |
47 |
| - expect(controller.getDelay()).toBeGreaterThanOrEqual(512000) |
48 |
| - expect(controller.getDelay()).toBeLessThan(513000) |
| 27 | + const controller = new BackoffController(); |
| 28 | + controller.countError(); |
| 29 | + expect(controller.getDelay()).toBeGreaterThanOrEqual(8000); |
| 30 | + expect(controller.getDelay()).toBeLessThan(9000); |
| 31 | + controller.countError(); |
| 32 | + expect(controller.getDelay()).toBeGreaterThanOrEqual(16000); |
| 33 | + expect(controller.getDelay()).toBeLessThan(17000); |
| 34 | + controller.countError(); |
| 35 | + expect(controller.getDelay()).toBeGreaterThanOrEqual(32000); |
| 36 | + expect(controller.getDelay()).toBeLessThan(33000); |
| 37 | + controller.countError(); |
| 38 | + expect(controller.getDelay()).toBeGreaterThanOrEqual(64000); |
| 39 | + expect(controller.getDelay()).toBeLessThan(65000); |
| 40 | + controller.countError(); |
| 41 | + expect(controller.getDelay()).toBeGreaterThanOrEqual(128000); |
| 42 | + expect(controller.getDelay()).toBeLessThan(129000); |
| 43 | + controller.countError(); |
| 44 | + expect(controller.getDelay()).toBeGreaterThanOrEqual(256000); |
| 45 | + expect(controller.getDelay()).toBeLessThan(257000); |
| 46 | + controller.countError(); |
| 47 | + expect(controller.getDelay()).toBeGreaterThanOrEqual(512000); |
| 48 | + expect(controller.getDelay()).toBeLessThan(513000); |
49 | 49 | // Maximum reached - additional errors should not increase the delay further
|
50 |
| - controller.countError() |
51 |
| - expect(controller.getDelay()).toBeGreaterThanOrEqual(512000) |
52 |
| - expect(controller.getDelay()).toBeLessThan(513000) |
53 |
| - }) |
| 50 | + controller.countError(); |
| 51 | + expect(controller.getDelay()).toBeGreaterThanOrEqual(512000); |
| 52 | + expect(controller.getDelay()).toBeLessThan(513000); |
| 53 | + }); |
54 | 54 |
|
55 | 55 | it('resets the error count when reset is called', () => {
|
56 |
| - const controller = new BackoffController() |
57 |
| - controller.countError() |
58 |
| - expect(controller.getDelay()).toBeGreaterThan(0) |
59 |
| - controller.reset() |
60 |
| - expect(controller.getDelay()).toBe(0) |
61 |
| - }) |
62 |
| - }) |
63 |
| -}) |
| 56 | + const controller = new BackoffController(); |
| 57 | + controller.countError(); |
| 58 | + expect(controller.getDelay()).toBeGreaterThan(0); |
| 59 | + controller.reset(); |
| 60 | + expect(controller.getDelay()).toBe(0); |
| 61 | + }); |
| 62 | + }); |
| 63 | +}); |
0 commit comments