Fix watchdog requires

This commit is contained in:
Łukasz Mierzwa
2017-07-22 23:30:34 -07:00
parent e963a3fd6c
commit 17f1e2c811
2 changed files with 18 additions and 4 deletions

View File

@@ -1,3 +1,10 @@
const $ = require("jquery");
const moment = require("moment");
const config = require("./config");
const counter = require("./counter");
const templates = require("./templates");
var selectors = {
countdown: "#reload-counter"
};
@@ -14,15 +21,15 @@ function timerTick() {
if (lastTs === 0) return;
// don't raise an error if autorefresh is disabled
if (!Config.GetOption("autorefresh").Get()) return;
if (!config.getOption("autorefresh").Get()) return;
var now = moment().utc().unix();
if (now - lastTs > maxLag) {
$("#errors").html(Templates.Render("fatalError", {
$("#errors").html(templates.renderTemplate("fatalError", {
lastTs: lastTs,
secondsLeft: fatalCountdown
})).show();
Counter.Unknown();
counter.markUnknown();
if (!inCountdown) {
fatalCountdown = 60;
fatalReloadTimer = setTimeout(function() {

View File

@@ -1,20 +1,27 @@
const watchdog = require("./watchdog");
const moment = require("moment");
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);
expect(watchdog.getLastUpdate()).toBe(ts.utc().unix());
});
test("watchdog isFatal() should be false by default", () => {
window.jQuery = require("jquery");
const watchdog = require("./watchdog");
expect(watchdog.isFatal()).toBe(false);
});