mirror of
https://github.com/prymitive/karma
synced 2026-05-11 03:46:48 +00:00
Add more watchdog tests
This commit is contained in:
@@ -1,19 +1,19 @@
|
||||
window.jQuery = require("jquery");
|
||||
const moment = require("moment");
|
||||
|
||||
jest.useFakeTimers();
|
||||
|
||||
test("watchdog init()", () => {
|
||||
window.jQuery = require("jquery");
|
||||
const watchdog = require("./watchdog");
|
||||
watchdog.init(1, 1);
|
||||
});
|
||||
|
||||
test("watchdog getLastUpdate() without pong", () => {
|
||||
window.jQuery = require("jquery");
|
||||
const watchdog = require("./watchdog");
|
||||
expect(watchdog.getLastUpdate()).toBe(0);
|
||||
});
|
||||
|
||||
test("watchdog getLastUpdate() with pong", () => {
|
||||
window.jQuery = require("jquery");
|
||||
const watchdog = require("./watchdog");
|
||||
var ts = moment();
|
||||
watchdog.pong(ts);
|
||||
@@ -21,7 +21,43 @@ test("watchdog getLastUpdate() with pong", () => {
|
||||
});
|
||||
|
||||
test("watchdog isFatal() should be false by default", () => {
|
||||
window.jQuery = require("jquery");
|
||||
const watchdog = require("./watchdog");
|
||||
expect(watchdog.isFatal()).toBe(false);
|
||||
});
|
||||
|
||||
test("watchdog isFatal() should be true after deadline passes", () => {
|
||||
const counter = require("./counter");
|
||||
counter.init();
|
||||
|
||||
const config = require("./config");
|
||||
config.newOption({
|
||||
Cookie: "autoRefresh",
|
||||
QueryParam: "autorefresh",
|
||||
Selector: "#autorefresh",
|
||||
Getter: function() {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
const templatesMock = require("./__mocks__/templatesMock");
|
||||
document.body.innerHTML = templatesMock.loadTemplates();
|
||||
const templates = require("./templates");
|
||||
templates.init();
|
||||
|
||||
const watchdog = require("./watchdog");
|
||||
jest.clearAllTimers();
|
||||
watchdog.init(1, 60); // 1s interval, 60s tolerance
|
||||
// should be false before we pong() the first time
|
||||
expect(watchdog.isFatal()).toBe(false);
|
||||
|
||||
watchdog.pong(moment());
|
||||
// should be false after first pong since we're < maxLag
|
||||
expect(watchdog.isFatal()).toBe(false);
|
||||
|
||||
// last timestamp is too old, should be true
|
||||
var ts = moment().subtract(61, "seconds");
|
||||
watchdog.pong(ts);
|
||||
expect(watchdog.getLastUpdate()).toBe(ts.utc().unix());
|
||||
jest.runTimersToTime(2 * 1000);
|
||||
expect(watchdog.isFatal()).toBe(true);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user