-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added tests for Builder * Added test for ExponentialBackoff * Updated README.md * Added default-values for constructor-parameters * Bumped version to rc5
- Loading branch information
Showing
5 changed files
with
117 additions
and
6 deletions.
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 |
---|---|---|
@@ -1,14 +1,26 @@ | ||
import {ExponentialBackoff} from "../../src/backoff/exponentialbackoff"; | ||
|
||
describe("Testsuite for ExponentialBackoff", () => { | ||
const p = 0, expMin = 0, expMax = 0; | ||
const k = 0, expMin = 0, expMax = 8; | ||
let backoff: ExponentialBackoff; | ||
|
||
beforeEach(() => { | ||
backoff = new ExponentialBackoff(p, expMin, expMax); | ||
backoff = new ExponentialBackoff(k, expMin, expMax); | ||
}); | ||
|
||
test("ExponentialBackoff should increase exponentially", () => { | ||
expect(true).toBe(true); | ||
let expCur = expMin; | ||
const calc = (): number => { | ||
const next = k * Math.pow(2, expCur); | ||
if (expMax > expCur) | ||
expCur++; | ||
return next; | ||
} | ||
for (let i = 0; i < expMax + 5; i++) | ||
expect(backoff.Next()).toBe(calc()); | ||
backoff.Reset() | ||
expCur = expMin; | ||
for (let i = 0; i < expMax + 5; i++) | ||
expect(backoff.Next()).toBe(calc()); | ||
}); | ||
}); |
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,40 @@ | ||
import {Builder, LRUBuffer, Websocket} from "../src"; | ||
import {ConstantBackoff} from "../src/backoff/constantbackoff"; | ||
|
||
describe("Testsuite for Builder", () => { | ||
const url = "ws://localhost:42421"; | ||
let builder: Builder | ||
|
||
beforeEach(() => { | ||
builder = new Builder(url); | ||
}); | ||
|
||
test("Builder should set protocols", () => { | ||
const protocols = ["p1", "p2", "p3"]; | ||
builder.withProtocols(protocols); | ||
expect(builder["protocols"]).toBe(protocols); | ||
}); | ||
|
||
test("Builder should set backoff", () => { | ||
const backoff = new ConstantBackoff(100); | ||
builder.withBackoff(backoff); | ||
expect(builder["backoff"]).toBe(backoff); | ||
}); | ||
|
||
test("Builder should set buffer", () => { | ||
const buffer = new LRUBuffer(10); | ||
builder.withBuffer(buffer); | ||
expect(builder["buffer"]).toBe(buffer); | ||
}); | ||
|
||
test("Builder should set onOpen-callbacks", () => { | ||
let i = 0; | ||
const cb1 = () => i += 2 | ||
const cb2 = () => i += 3 | ||
builder.onOpen(cb1).onOpen(cb2); | ||
const fns = builder["onOpenChain"] | ||
expect(fns).not.toBeUndefined(); | ||
fns!(null as unknown as Websocket, null as unknown as Event); | ||
expect(i).toBe(5); | ||
}) | ||
}); |