mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2024-12-23 23:42:29 +00:00
Merge pull request #1715 from balena-os/1673-prevent-recursive-state-report
Prevent a recursive loop when reporting current state
This commit is contained in:
commit
35d9a32a6d
@ -203,14 +203,10 @@ const reportCurrentState = (): null => {
|
|||||||
...currentDeviceState.dependent,
|
...currentDeviceState.dependent,
|
||||||
};
|
};
|
||||||
|
|
||||||
const stateDiff = getStateDiff();
|
// Report current state
|
||||||
if (_.size(stateDiff) === 0) {
|
|
||||||
reportPending = false;
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
await report();
|
await report();
|
||||||
reportCurrentState();
|
// Finishing pending report
|
||||||
|
reportPending = false;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
eventTracker.track('Device state report failure', { error: e });
|
eventTracker.track('Device state report failure', { error: e });
|
||||||
// We use the poll interval as the upper limit of
|
// We use the poll interval as the upper limit of
|
||||||
@ -241,5 +237,6 @@ export const startReporting = () => {
|
|||||||
// But check once every max report frequency to ensure that changes in system
|
// But check once every max report frequency to ensure that changes in system
|
||||||
// info are picked up (CPU temp etc)
|
// info are picked up (CPU temp etc)
|
||||||
setInterval(doReport, constants.maxReportFrequency);
|
setInterval(doReport, constants.maxReportFrequency);
|
||||||
return reportCurrentState();
|
// Try to perform a report right away
|
||||||
|
return doReport();
|
||||||
};
|
};
|
||||||
|
@ -505,25 +505,6 @@ describe('device-state/current-state', () => {
|
|||||||
report.cancel();
|
report.cancel();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not report if current state has not changed', async () => {
|
|
||||||
// Use a temporary unhandledRejectionHandler to catch the promise
|
|
||||||
// rejection from the Bluebird.delay stub
|
|
||||||
process.on('unhandledRejection', unhandledRejectionHandler);
|
|
||||||
spy(_, 'size');
|
|
||||||
|
|
||||||
reportCurrentState();
|
|
||||||
|
|
||||||
// Wait 200ms for anonymous async IIFE inside reportCurrentState to finish executing
|
|
||||||
// TODO: is there a better way to test this? Possible race condition
|
|
||||||
await sleep(200);
|
|
||||||
|
|
||||||
expect(stateForReport).to.deep.equal({ local: {}, dependent: {} });
|
|
||||||
expect(_.size as SinonSpy).to.have.returned(0);
|
|
||||||
|
|
||||||
(_.size as SinonSpy).restore();
|
|
||||||
process.removeListener('unhandledRejection', unhandledRejectionHandler);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('sends a null patch for system metrics when HARDWARE_METRICS is false', async () => {
|
it('sends a null patch for system metrics when HARDWARE_METRICS is false', async () => {
|
||||||
// Use a temporary unhandledRejectionHandler to catch the promise
|
// Use a temporary unhandledRejectionHandler to catch the promise
|
||||||
// rejection from the Bluebird.delay stub
|
// rejection from the Bluebird.delay stub
|
||||||
|
Loading…
Reference in New Issue
Block a user