Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added sanity check for the bridge interval value #4717

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion lib/plugins/bridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,17 @@ function options (env) {
, minutes: env.extendedSettings.bridge.minutes || 1440
};

var interval = env.extendedSettings.bridge.interval || 60000 * 2.5; // Default: 2.5 minutes

if (interval < 1000 || interval > 300000) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I bet 1000 would be too low, too

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will not kill dexcom share to poll every second...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but will ask quite some computing resources on the nightscout instance and thus stress the cpu usage with Azure, Heroku or self hosted quite a lot. Want to look at smarter ways of implementing this.

// Invalid interval range. Revert to default
console.error("Invalid interval set: [" + interval + "ms]. Defaulting to 2.5 minutes.")
interval = 60000 * 2.5 // 2.5 minutes
}

return {
login: config
, interval: env.extendedSettings.bridge.interval || 60000 * 2.5
, interval: interval
, fetch: fetch_config
, nightscout: { }
, maxFailures: env.extendedSettings.bridge.maxFailures || 3
Expand Down
41 changes: 41 additions & 0 deletions tests/bridge.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ describe('bridge', function ( ) {
bridge: {
userName: 'nightscout'
, password: 'wearenotwaiting'
, interval: 60000
}
}
};
Expand All @@ -27,6 +28,7 @@ describe('bridge', function ( ) {

opts.login.accountName.should.equal('nightscout');
opts.login.password.should.equal('wearenotwaiting');
opts.interval.should.equal(60000);
});

it('store entries from share', function (done) {
Expand All @@ -39,4 +41,43 @@ describe('bridge', function ( ) {
bridge.bridged(mockEntries)(null);
});

it('set too low bridge interval option from env', function () {
var tooLowInterval = {
extendedSettings: {
bridge: { interval: 900 }
}
};

var opts = bridge.options(tooLowInterval);
should.exist(opts);

opts.interval.should.equal(150000);
});

it('set too high bridge interval option from env', function () {
var tooHighInterval = {
extendedSettings: {
bridge: { interval: 500000 }
}
};

var opts = bridge.options(tooHighInterval);
should.exist(opts);

opts.interval.should.equal(150000);
});

it('set no bridge interval option from env', function () {
var noInterval = {
extendedSettings: {
bridge: { }
}
};

var opts = bridge.options(noInterval);
should.exist(opts);

opts.interval.should.equal(150000);
});

});