2019-09-12 15:26:21 +00:00
|
|
|
import * as Bluebird from 'bluebird';
|
2020-05-20 05:03:53 +00:00
|
|
|
import { stripIndent } from 'common-tags';
|
2019-09-12 15:26:21 +00:00
|
|
|
import * as _ from 'lodash';
|
2020-05-20 05:03:53 +00:00
|
|
|
import { SinonSpy, SinonStub, spy, stub } from 'sinon';
|
2019-09-12 15:26:21 +00:00
|
|
|
|
|
|
|
import chai = require('./lib/chai-config');
|
2020-06-09 13:43:45 +00:00
|
|
|
import { StatusCodeError } from '../src/lib/errors';
|
2019-09-12 15:26:21 +00:00
|
|
|
import prepare = require('./lib/prepare');
|
2020-05-20 05:03:53 +00:00
|
|
|
import Log from '../src/lib/supervisor-console';
|
2020-06-02 16:56:58 +00:00
|
|
|
import * as dockerUtils from '../src/lib/docker-utils';
|
2020-06-02 13:29:05 +00:00
|
|
|
import * as config from '../src/config';
|
2020-06-09 13:43:45 +00:00
|
|
|
import * as images from '../src/compose/images';
|
2020-08-07 17:34:32 +00:00
|
|
|
import { ConfigTxt } from '../src/config/backends/config-txt';
|
2019-12-18 15:58:21 +00:00
|
|
|
import DeviceState from '../src/device-state';
|
2020-07-08 09:50:52 +00:00
|
|
|
import * as deviceConfig from '../src/device-config';
|
2019-11-06 16:52:28 +00:00
|
|
|
import { loadTargetFromFile } from '../src/device-state/preload';
|
2019-09-12 15:26:21 +00:00
|
|
|
import Service from '../src/compose/service';
|
2020-04-07 11:22:56 +00:00
|
|
|
import { intialiseContractRequirements } from '../src/lib/contracts';
|
2019-09-12 15:26:21 +00:00
|
|
|
|
2020-05-20 05:03:53 +00:00
|
|
|
// tslint:disable-next-line
|
|
|
|
chai.use(require('chai-events'));
|
|
|
|
const { expect } = chai;
|
|
|
|
|
2019-09-12 15:26:21 +00:00
|
|
|
const mockedInitialConfig = {
|
|
|
|
RESIN_SUPERVISOR_CONNECTIVITY_CHECK: 'true',
|
|
|
|
RESIN_SUPERVISOR_DELTA: 'false',
|
|
|
|
RESIN_SUPERVISOR_DELTA_APPLY_TIMEOUT: '0',
|
|
|
|
RESIN_SUPERVISOR_DELTA_REQUEST_TIMEOUT: '30000',
|
|
|
|
RESIN_SUPERVISOR_DELTA_RETRY_COUNT: '30',
|
|
|
|
RESIN_SUPERVISOR_DELTA_RETRY_INTERVAL: '10000',
|
|
|
|
RESIN_SUPERVISOR_DELTA_VERSION: '2',
|
|
|
|
RESIN_SUPERVISOR_INSTANT_UPDATE_TRIGGER: 'true',
|
|
|
|
RESIN_SUPERVISOR_LOCAL_MODE: 'false',
|
|
|
|
RESIN_SUPERVISOR_LOG_CONTROL: 'true',
|
|
|
|
RESIN_SUPERVISOR_OVERRIDE_LOCK: 'false',
|
|
|
|
RESIN_SUPERVISOR_POLL_INTERVAL: '60000',
|
|
|
|
RESIN_SUPERVISOR_VPN_CONTROL: 'true',
|
|
|
|
};
|
|
|
|
|
|
|
|
const testTarget1 = {
|
|
|
|
local: {
|
|
|
|
name: 'aDevice',
|
|
|
|
config: {
|
|
|
|
HOST_CONFIG_gpu_mem: '256',
|
2020-06-15 16:46:33 +00:00
|
|
|
HOST_FIREWALL_MODE: 'off',
|
2020-07-06 10:13:45 +00:00
|
|
|
HOST_DISCOVERABILITY: 'true',
|
2019-09-12 15:26:21 +00:00
|
|
|
SUPERVISOR_CONNECTIVITY_CHECK: 'true',
|
|
|
|
SUPERVISOR_DELTA: 'false',
|
|
|
|
SUPERVISOR_DELTA_APPLY_TIMEOUT: '0',
|
|
|
|
SUPERVISOR_DELTA_REQUEST_TIMEOUT: '30000',
|
|
|
|
SUPERVISOR_DELTA_RETRY_COUNT: '30',
|
|
|
|
SUPERVISOR_DELTA_RETRY_INTERVAL: '10000',
|
|
|
|
SUPERVISOR_DELTA_VERSION: '2',
|
|
|
|
SUPERVISOR_INSTANT_UPDATE_TRIGGER: 'true',
|
|
|
|
SUPERVISOR_LOCAL_MODE: 'false',
|
|
|
|
SUPERVISOR_LOG_CONTROL: 'true',
|
|
|
|
SUPERVISOR_OVERRIDE_LOCK: 'false',
|
|
|
|
SUPERVISOR_POLL_INTERVAL: '60000',
|
|
|
|
SUPERVISOR_VPN_CONTROL: 'true',
|
|
|
|
SUPERVISOR_PERSISTENT_LOGGING: 'false',
|
|
|
|
},
|
|
|
|
apps: {
|
|
|
|
'1234': {
|
|
|
|
appId: 1234,
|
|
|
|
name: 'superapp',
|
|
|
|
commit: 'abcdef',
|
|
|
|
releaseId: 1,
|
2020-06-08 09:33:19 +00:00
|
|
|
services: {
|
|
|
|
23: {
|
2019-09-12 15:26:21 +00:00
|
|
|
appId: 1234,
|
|
|
|
serviceId: 23,
|
|
|
|
imageId: 12345,
|
|
|
|
serviceName: 'someservice',
|
|
|
|
releaseId: 1,
|
|
|
|
image: 'registry2.resin.io/superapp/abcdef:latest',
|
|
|
|
labels: {
|
|
|
|
'io.resin.something': 'bar',
|
|
|
|
},
|
|
|
|
},
|
2020-06-08 09:33:19 +00:00
|
|
|
},
|
2019-09-12 15:26:21 +00:00
|
|
|
volumes: {},
|
|
|
|
networks: {},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
dependent: { apps: [], devices: [] },
|
|
|
|
};
|
|
|
|
|
|
|
|
const testTarget2 = {
|
|
|
|
local: {
|
|
|
|
name: 'aDeviceWithDifferentName',
|
|
|
|
config: {
|
|
|
|
RESIN_HOST_CONFIG_gpu_mem: '512',
|
|
|
|
},
|
|
|
|
apps: {
|
|
|
|
'1234': {
|
|
|
|
name: 'superapp',
|
|
|
|
commit: 'afafafa',
|
|
|
|
releaseId: 2,
|
|
|
|
services: {
|
|
|
|
'23': {
|
|
|
|
serviceName: 'aservice',
|
|
|
|
imageId: 12345,
|
|
|
|
image: 'registry2.resin.io/superapp/edfabc',
|
|
|
|
environment: {
|
|
|
|
FOO: 'bar',
|
|
|
|
},
|
|
|
|
labels: {},
|
|
|
|
},
|
|
|
|
'24': {
|
|
|
|
serviceName: 'anotherService',
|
|
|
|
imageId: 12346,
|
|
|
|
image: 'registry2.resin.io/superapp/afaff',
|
|
|
|
environment: {
|
|
|
|
FOO: 'bro',
|
|
|
|
},
|
|
|
|
labels: {},
|
|
|
|
},
|
|
|
|
},
|
2019-12-18 15:58:21 +00:00
|
|
|
volumes: {},
|
|
|
|
networks: {},
|
2019-09-12 15:26:21 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
dependent: { apps: [], devices: [] },
|
|
|
|
};
|
|
|
|
|
|
|
|
const testTargetWithDefaults2 = {
|
|
|
|
local: {
|
|
|
|
name: 'aDeviceWithDifferentName',
|
|
|
|
config: {
|
|
|
|
HOST_CONFIG_gpu_mem: '512',
|
2020-06-15 16:46:33 +00:00
|
|
|
HOST_FIREWALL_MODE: 'off',
|
2020-07-06 10:13:45 +00:00
|
|
|
HOST_DISCOVERABILITY: 'true',
|
2019-09-12 15:26:21 +00:00
|
|
|
SUPERVISOR_CONNECTIVITY_CHECK: 'true',
|
|
|
|
SUPERVISOR_DELTA: 'false',
|
|
|
|
SUPERVISOR_DELTA_APPLY_TIMEOUT: '0',
|
|
|
|
SUPERVISOR_DELTA_REQUEST_TIMEOUT: '30000',
|
|
|
|
SUPERVISOR_DELTA_RETRY_COUNT: '30',
|
|
|
|
SUPERVISOR_DELTA_RETRY_INTERVAL: '10000',
|
|
|
|
SUPERVISOR_DELTA_VERSION: '2',
|
|
|
|
SUPERVISOR_INSTANT_UPDATE_TRIGGER: 'true',
|
|
|
|
SUPERVISOR_LOCAL_MODE: 'false',
|
|
|
|
SUPERVISOR_LOG_CONTROL: 'true',
|
|
|
|
SUPERVISOR_OVERRIDE_LOCK: 'false',
|
|
|
|
SUPERVISOR_POLL_INTERVAL: '60000',
|
|
|
|
SUPERVISOR_VPN_CONTROL: 'true',
|
|
|
|
SUPERVISOR_PERSISTENT_LOGGING: 'false',
|
|
|
|
},
|
|
|
|
apps: {
|
|
|
|
'1234': {
|
|
|
|
appId: 1234,
|
|
|
|
name: 'superapp',
|
|
|
|
commit: 'afafafa',
|
|
|
|
releaseId: 2,
|
|
|
|
services: [
|
|
|
|
_.merge(
|
|
|
|
{ appId: 1234, serviceId: 23, releaseId: 2 },
|
|
|
|
_.clone(testTarget2.local.apps['1234'].services['23']),
|
|
|
|
),
|
|
|
|
_.merge(
|
|
|
|
{ appId: 1234, serviceId: 24, releaseId: 2 },
|
|
|
|
_.clone(testTarget2.local.apps['1234'].services['24']),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
volumes: {},
|
|
|
|
networks: {},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
dependent: { apps: [], devices: [] },
|
|
|
|
};
|
|
|
|
|
|
|
|
const testTargetInvalid = {
|
|
|
|
local: {
|
|
|
|
name: 'aDeviceWithDifferentName',
|
|
|
|
config: {
|
|
|
|
RESIN_HOST_CONFIG_gpu_mem: '512',
|
|
|
|
},
|
2020-06-08 09:33:19 +00:00
|
|
|
apps: {
|
|
|
|
1234: {
|
2019-09-12 15:26:21 +00:00
|
|
|
appId: '1234',
|
|
|
|
name: 'superapp',
|
|
|
|
commit: 'afafafa',
|
|
|
|
releaseId: '2',
|
|
|
|
config: {},
|
2020-06-08 09:33:19 +00:00
|
|
|
services: {
|
|
|
|
23: {
|
2019-09-12 15:26:21 +00:00
|
|
|
serviceId: '23',
|
|
|
|
serviceName: 'aservice',
|
|
|
|
imageId: '12345',
|
|
|
|
image: 'registry2.resin.io/superapp/edfabc',
|
|
|
|
config: {},
|
|
|
|
environment: {
|
|
|
|
' FOO': 'bar',
|
|
|
|
},
|
|
|
|
labels: {},
|
|
|
|
},
|
2020-06-08 09:33:19 +00:00
|
|
|
24: {
|
2019-09-12 15:26:21 +00:00
|
|
|
serviceId: '24',
|
|
|
|
serviceName: 'anotherService',
|
|
|
|
imageId: '12346',
|
|
|
|
image: 'registry2.resin.io/superapp/afaff',
|
|
|
|
config: {},
|
|
|
|
environment: {
|
|
|
|
FOO: 'bro',
|
|
|
|
},
|
|
|
|
labels: {},
|
|
|
|
},
|
2020-06-08 09:33:19 +00:00
|
|
|
},
|
2019-09-12 15:26:21 +00:00
|
|
|
},
|
2020-06-08 09:33:19 +00:00
|
|
|
},
|
2019-09-12 15:26:21 +00:00
|
|
|
},
|
|
|
|
dependent: { apps: [], devices: [] },
|
|
|
|
};
|
|
|
|
|
|
|
|
describe('deviceState', () => {
|
|
|
|
let deviceState: DeviceState;
|
2020-06-08 09:33:19 +00:00
|
|
|
let source: string;
|
2020-06-09 13:43:45 +00:00
|
|
|
const originalImagesSave = images.save;
|
|
|
|
const originalImagesInspect = images.inspectByName;
|
2020-07-08 09:50:52 +00:00
|
|
|
const originalGetCurrent = deviceConfig.getCurrent;
|
2019-09-12 15:26:21 +00:00
|
|
|
before(async () => {
|
2020-05-28 17:15:33 +00:00
|
|
|
await prepare();
|
2020-06-08 09:33:19 +00:00
|
|
|
await config.initialized;
|
|
|
|
source = await config.get('apiEndpoint');
|
2019-09-12 15:26:21 +00:00
|
|
|
|
2020-05-15 11:01:51 +00:00
|
|
|
stub(Service as any, 'extendEnvVars').callsFake((env) => {
|
2019-09-12 15:26:21 +00:00
|
|
|
env['ADDITIONAL_ENV_VAR'] = 'foo';
|
|
|
|
return env;
|
|
|
|
});
|
|
|
|
|
2020-04-07 11:22:56 +00:00
|
|
|
intialiseContractRequirements({
|
|
|
|
supervisorVersion: '11.0.0',
|
|
|
|
deviceType: 'intel-nuc',
|
|
|
|
});
|
|
|
|
|
2019-09-12 15:26:21 +00:00
|
|
|
deviceState = new DeviceState({
|
2020-04-06 16:29:59 +00:00
|
|
|
apiBinder: null as any,
|
2019-09-12 15:26:21 +00:00
|
|
|
});
|
|
|
|
|
2020-06-02 16:56:58 +00:00
|
|
|
stub(dockerUtils, 'getNetworkGateway').returns(
|
2019-09-12 15:26:21 +00:00
|
|
|
Promise.resolve('172.17.0.1'),
|
|
|
|
);
|
|
|
|
|
2020-06-09 13:43:45 +00:00
|
|
|
// @ts-expect-error Assigning to a RO property
|
|
|
|
images.save = () => Promise.resolve();
|
|
|
|
|
|
|
|
// @ts-expect-error Assigning to a RO property
|
|
|
|
images.inspectByName = () => {
|
|
|
|
const err: StatusCodeError = new Error();
|
2019-09-12 15:26:21 +00:00
|
|
|
err.statusCode = 404;
|
|
|
|
return Promise.reject(err);
|
2020-06-09 13:43:45 +00:00
|
|
|
};
|
2019-09-12 15:26:21 +00:00
|
|
|
|
2020-07-08 09:50:52 +00:00
|
|
|
// @ts-expect-error Assigning to a RO property
|
2020-08-07 17:34:32 +00:00
|
|
|
deviceConfig.configBackend = new ConfigTxt();
|
2020-07-08 09:50:52 +00:00
|
|
|
|
|
|
|
// @ts-expect-error Assigning to a RO property
|
|
|
|
deviceConfig.getCurrent = async () => mockedInitialConfig;
|
2019-09-12 15:26:21 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
after(() => {
|
|
|
|
(Service as any).extendEnvVars.restore();
|
2020-06-02 16:56:58 +00:00
|
|
|
(dockerUtils.getNetworkGateway as sinon.SinonStub).restore();
|
2020-06-09 13:43:45 +00:00
|
|
|
|
|
|
|
// @ts-expect-error Assigning to a RO property
|
|
|
|
images.save = originalImagesSave;
|
|
|
|
// @ts-expect-error Assigning to a RO property
|
|
|
|
images.inspectByName = originalImagesInspect;
|
2020-07-08 09:50:52 +00:00
|
|
|
// @ts-expect-error Assigning to a RO property
|
|
|
|
deviceConfig.getCurrent = originalGetCurrent;
|
2019-09-12 15:26:21 +00:00
|
|
|
});
|
|
|
|
|
2020-06-08 09:33:19 +00:00
|
|
|
beforeEach(async () => {
|
|
|
|
await prepare();
|
|
|
|
});
|
|
|
|
|
2019-09-12 15:26:21 +00:00
|
|
|
it('loads a target state from an apps.json file and saves it as target state, then returns it', async () => {
|
2020-07-08 09:50:52 +00:00
|
|
|
await loadTargetFromFile(
|
|
|
|
process.env.ROOT_MOUNTPOINT + '/apps.json',
|
|
|
|
deviceState,
|
2019-09-12 15:26:21 +00:00
|
|
|
);
|
2020-07-08 09:50:52 +00:00
|
|
|
const targetState = await deviceState.getTarget();
|
2019-09-12 15:26:21 +00:00
|
|
|
|
2020-07-08 09:50:52 +00:00
|
|
|
const testTarget = _.cloneDeep(testTarget1);
|
|
|
|
testTarget.local.apps['1234'].services = _.mapValues(
|
|
|
|
testTarget.local.apps['1234'].services,
|
|
|
|
(s: any) => {
|
|
|
|
s.imageName = s.image;
|
|
|
|
return Service.fromComposeObject(s, { appName: 'superapp' } as any);
|
|
|
|
},
|
|
|
|
) as any;
|
|
|
|
// @ts-ignore
|
|
|
|
testTarget.local.apps['1234'].source = source;
|
2019-09-12 15:26:21 +00:00
|
|
|
|
2020-07-08 09:50:52 +00:00
|
|
|
expect(JSON.parse(JSON.stringify(targetState))).to.deep.equal(
|
|
|
|
JSON.parse(JSON.stringify(testTarget)),
|
|
|
|
);
|
2019-09-12 15:26:21 +00:00
|
|
|
});
|
|
|
|
|
2020-03-23 19:02:17 +00:00
|
|
|
it('stores info for pinning a device after loading an apps.json with a pinDevice field', async () => {
|
|
|
|
await loadTargetFromFile(
|
2019-11-06 16:52:28 +00:00
|
|
|
process.env.ROOT_MOUNTPOINT + '/apps-pin.json',
|
|
|
|
deviceState,
|
2020-03-23 19:02:17 +00:00
|
|
|
);
|
2019-09-12 15:26:21 +00:00
|
|
|
|
2020-03-23 19:02:17 +00:00
|
|
|
const pinned = await config.get('pinDevice');
|
2020-05-15 11:01:51 +00:00
|
|
|
expect(pinned).to.have.property('app').that.equals(1234);
|
|
|
|
expect(pinned).to.have.property('commit').that.equals('abcdef');
|
2019-09-12 15:26:21 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('emits a change event when a new state is reported', () => {
|
2019-12-18 15:58:21 +00:00
|
|
|
deviceState.reportCurrentState({ someStateDiff: 'someValue' } as any);
|
2019-09-12 15:26:21 +00:00
|
|
|
return (expect as any)(deviceState).to.emit('change');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns the current state');
|
|
|
|
|
|
|
|
it('writes the target state to the db with some extra defaults', async () => {
|
|
|
|
const testTarget = _.cloneDeep(testTargetWithDefaults2);
|
|
|
|
|
|
|
|
const services: Service[] = [];
|
|
|
|
for (const service of testTarget.local.apps['1234'].services) {
|
2020-06-09 13:43:45 +00:00
|
|
|
const imageName = await images.normalise(service.image);
|
2019-09-12 15:26:21 +00:00
|
|
|
service.image = imageName;
|
|
|
|
(service as any).imageName = imageName;
|
|
|
|
services.push(
|
|
|
|
Service.fromComposeObject(service, { appName: 'supertest' } as any),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-06-08 09:33:19 +00:00
|
|
|
(testTarget as any).local.apps['1234'].services = _.keyBy(
|
|
|
|
services,
|
|
|
|
'serviceId',
|
|
|
|
);
|
|
|
|
(testTarget as any).local.apps['1234'].source = source;
|
2019-09-12 15:26:21 +00:00
|
|
|
await deviceState.setTarget(testTarget2);
|
|
|
|
const target = await deviceState.getTarget();
|
|
|
|
expect(JSON.parse(JSON.stringify(target))).to.deep.equal(
|
|
|
|
JSON.parse(JSON.stringify(testTarget)),
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not allow setting an invalid target state', () => {
|
2019-12-18 15:58:21 +00:00
|
|
|
expect(deviceState.setTarget(testTargetInvalid as any)).to.be.rejected;
|
2019-09-12 15:26:21 +00:00
|
|
|
});
|
|
|
|
|
2020-05-15 11:01:51 +00:00
|
|
|
it('allows triggering applying the target state', (done) => {
|
2019-09-12 15:26:21 +00:00
|
|
|
stub(deviceState as any, 'applyTarget').returns(Promise.resolve());
|
|
|
|
|
|
|
|
deviceState.triggerApplyTarget({ force: true });
|
|
|
|
expect((deviceState as any).applyTarget).to.not.be.called;
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
expect((deviceState as any).applyTarget).to.be.calledWith({
|
|
|
|
force: true,
|
|
|
|
initial: false,
|
|
|
|
});
|
|
|
|
(deviceState as any).applyTarget.restore();
|
|
|
|
done();
|
|
|
|
}, 5);
|
|
|
|
});
|
|
|
|
|
2020-05-15 11:01:51 +00:00
|
|
|
it('cancels current promise applying the target state', (done) => {
|
2019-09-12 15:26:21 +00:00
|
|
|
(deviceState as any).scheduledApply = { force: false, delay: 100 };
|
|
|
|
(deviceState as any).applyInProgress = true;
|
|
|
|
(deviceState as any).applyCancelled = false;
|
|
|
|
|
|
|
|
new Bluebird((resolve, reject) => {
|
|
|
|
setTimeout(resolve, 100000);
|
|
|
|
(deviceState as any).cancelDelay = reject;
|
|
|
|
})
|
|
|
|
.catch(() => {
|
|
|
|
(deviceState as any).applyCancelled = true;
|
|
|
|
})
|
|
|
|
.finally(() => {
|
|
|
|
expect((deviceState as any).scheduledApply).to.deep.equal({
|
|
|
|
force: true,
|
|
|
|
delay: 0,
|
|
|
|
});
|
|
|
|
expect((deviceState as any).applyCancelled).to.be.true;
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
|
|
|
deviceState.triggerApplyTarget({ force: true, isFromApi: true });
|
|
|
|
});
|
|
|
|
|
|
|
|
it('applies the target state for device config');
|
|
|
|
|
|
|
|
it('applies the target state for applications');
|
2020-05-20 05:03:53 +00:00
|
|
|
|
|
|
|
describe('healthchecks', () => {
|
|
|
|
let configStub: SinonStub;
|
|
|
|
let infoLobSpy: SinonSpy;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
// This configStub will be modified in each test case so we can
|
|
|
|
// create the exact conditions we want to for testing healthchecks
|
2020-06-02 13:29:05 +00:00
|
|
|
configStub = stub(config, 'get');
|
2020-05-20 05:03:53 +00:00
|
|
|
infoLobSpy = spy(Log, 'info');
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
configStub.restore();
|
|
|
|
infoLobSpy.restore();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('passes with correct conditions', async () => {
|
|
|
|
// Setup passing condition
|
|
|
|
const previousValue = deviceState.applyInProgress;
|
|
|
|
deviceState.applyInProgress = false;
|
|
|
|
expect(await deviceState.healthcheck()).to.equal(true);
|
|
|
|
// Restore value
|
|
|
|
deviceState.applyInProgress = previousValue;
|
|
|
|
});
|
|
|
|
|
|
|
|
it('passes if unmanaged is true and exit early', async () => {
|
|
|
|
// Setup failing conditions
|
|
|
|
const previousValue = deviceState.applyInProgress;
|
|
|
|
deviceState.applyInProgress = true;
|
|
|
|
// Verify this causes healthcheck to fail
|
|
|
|
expect(await deviceState.healthcheck()).to.equal(false);
|
|
|
|
// Do it again but set unmanaged to true
|
|
|
|
configStub.resolves({
|
|
|
|
unmanaged: true,
|
|
|
|
});
|
|
|
|
expect(await deviceState.healthcheck()).to.equal(true);
|
|
|
|
// Restore value
|
|
|
|
deviceState.applyInProgress = previousValue;
|
|
|
|
});
|
|
|
|
|
|
|
|
it('fails when applyTargetHealthy is false', async () => {
|
|
|
|
// Copy previous values to restore later
|
|
|
|
const previousValue = deviceState.applyInProgress;
|
|
|
|
// Setup failing conditions
|
|
|
|
deviceState.applyInProgress = true;
|
|
|
|
expect(await deviceState.healthcheck()).to.equal(false);
|
|
|
|
expect(Log.info).to.be.calledOnce;
|
|
|
|
expect((Log.info as SinonSpy).lastCall?.lastArg).to.equal(
|
|
|
|
stripIndent`
|
2020-07-29 15:55:22 +00:00
|
|
|
Healthcheck failure - At least ONE of the following conditions must be true:
|
2020-05-20 05:03:53 +00:00
|
|
|
- No applyInProgress ? false
|
|
|
|
- fetchesInProgress ? false
|
|
|
|
- cycleTimeWithinInterval ? false`,
|
|
|
|
);
|
|
|
|
// Restore value
|
|
|
|
deviceState.applyInProgress = previousValue;
|
|
|
|
});
|
|
|
|
});
|
2019-09-12 15:26:21 +00:00
|
|
|
});
|