diff --git a/tests/timeago.test.js b/tests/timeago.test.js index 7b4a718ccd0..887d3f19b89 100644 --- a/tests/timeago.test.js +++ b/tests/timeago.test.js @@ -7,6 +7,8 @@ describe('timeago', function() { ctx.ddata = require('../lib/data/ddata')(); ctx.notifications = require('../lib/notifications')(env, ctx); ctx.language = require('../lib/language')(); + ctx.settings = require('../lib/settings')(); + ctx.settings.heartbeat = 0.5; // short heartbeat to speedup tests var timeago = require('../lib/plugins/timeago')(ctx); @@ -41,6 +43,32 @@ describe('timeago', function() { done(); }); + it('should suspend alarms due to hibernation when 2 heartbeats are skipped', function() { + ctx.ddata.sgvs = [{ mills: Date.now() - times.mins(16).msecs, mgdl: 100, type: 'sgv' }]; + + var sbx = freshSBX() + var status = timeago.checkStatus(sbx); + // By default (no hibernation detected) a warning should be given + should.equal(status, 'warn') + + // 10ms more than suspend-threshold to prevent flapping tests + var timeoutMs = 2 * ctx.settings.heartbeat * 1000 + 100; + return new Promise(function(resolve, reject) { + setTimeout(function() { + status = timeago.checkStatus(sbx); + // Because hibernation should now be detected, no warning should be given + should.equal(status, 'current') + + // We immediately ask status again, so hibernation should not be detected anymore, + // and we should receive a warning again + status = timeago.checkStatus(sbx); + should.equal(status, 'warn') + + resolve() + }, timeoutMs) + }) + }); + it('should trigger a warning when data older than 15m', function(done) { ctx.notifications.initRequests(); ctx.ddata.sgvs = [{ mills: Date.now() - times.mins(16).msecs, mgdl: 100, type: 'sgv' }];