mirror of
https://github.com/nasa/openmct.git
synced 2025-01-31 16:36:13 +00:00
[VIPEROMCT-16] Creates a closure for telemetryObject so that requests can resolve correctly even if the telemetryObject is destroyed (#3210)
Co-authored-by: Deep Tailor <deep.j.tailor@nasa.gov>
This commit is contained in:
parent
07992f0b2a
commit
afeb89a51a
@ -127,7 +127,7 @@ export default class AllTelemetryCriterion extends TelemetryCriterion {
|
|||||||
|
|
||||||
if (validatedData) {
|
if (validatedData) {
|
||||||
if (this.isStalenessCheck()) {
|
if (this.isStalenessCheck()) {
|
||||||
if (this.stalenessSubscription[validatedData.id]) {
|
if (this.stalenessSubscription && this.stalenessSubscription[validatedData.id]) {
|
||||||
this.stalenessSubscription[validatedData.id].update(validatedData);
|
this.stalenessSubscription[validatedData.id].update(validatedData);
|
||||||
}
|
}
|
||||||
this.telemetryDataCache[validatedData.id] = false;
|
this.telemetryDataCache[validatedData.id] = false;
|
||||||
|
@ -142,12 +142,14 @@ export default class TelemetryCriterion extends EventEmitter {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let telemetryObject = this.telemetryObject;
|
||||||
|
|
||||||
return this.openmct.telemetry.request(
|
return this.openmct.telemetry.request(
|
||||||
this.telemetryObject,
|
this.telemetryObject,
|
||||||
options
|
options
|
||||||
).then(results => {
|
).then(results => {
|
||||||
const latestDatum = results.length ? results[results.length - 1] : {};
|
const latestDatum = results.length ? results[results.length - 1] : {};
|
||||||
const normalizedDatum = this.createNormalizedDatum(latestDatum, this.telemetryObject);
|
const normalizedDatum = this.createNormalizedDatum(latestDatum, telemetryObject);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: this.id,
|
id: this.id,
|
||||||
|
@ -21,12 +21,14 @@
|
|||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
|
||||||
import TelemetryCriterion from "./TelemetryCriterion";
|
import TelemetryCriterion from "./TelemetryCriterion";
|
||||||
|
import { getMockTelemetry } from "utils/testing";
|
||||||
|
|
||||||
let openmct = {},
|
let openmct = {},
|
||||||
mockListener,
|
mockListener,
|
||||||
testCriterionDefinition,
|
testCriterionDefinition,
|
||||||
testTelemetryObject,
|
testTelemetryObject,
|
||||||
telemetryCriterion;
|
telemetryCriterion,
|
||||||
|
mockTelemetry = getMockTelemetry();
|
||||||
|
|
||||||
describe("The telemetry criterion", function () {
|
describe("The telemetry criterion", function () {
|
||||||
|
|
||||||
@ -60,7 +62,7 @@ describe("The telemetry criterion", function () {
|
|||||||
};
|
};
|
||||||
openmct.objects = jasmine.createSpyObj('objects', ['get', 'makeKeyString']);
|
openmct.objects = jasmine.createSpyObj('objects', ['get', 'makeKeyString']);
|
||||||
openmct.objects.makeKeyString.and.returnValue(testTelemetryObject.identifier.key);
|
openmct.objects.makeKeyString.and.returnValue(testTelemetryObject.identifier.key);
|
||||||
openmct.telemetry = jasmine.createSpyObj('telemetry', ['isTelemetryObject', "subscribe", "getMetadata", "getValueFormatter"]);
|
openmct.telemetry = jasmine.createSpyObj('telemetry', ['isTelemetryObject', "subscribe", "getMetadata", "getValueFormatter", "request"]);
|
||||||
openmct.telemetry.isTelemetryObject.and.returnValue(true);
|
openmct.telemetry.isTelemetryObject.and.returnValue(true);
|
||||||
openmct.telemetry.subscribe.and.returnValue(function () {});
|
openmct.telemetry.subscribe.and.returnValue(function () {});
|
||||||
openmct.telemetry.getValueFormatter.and.returnValue({
|
openmct.telemetry.getValueFormatter.and.returnValue({
|
||||||
@ -109,4 +111,30 @@ describe("The telemetry criterion", function () {
|
|||||||
});
|
});
|
||||||
expect(telemetryCriterion.result).toBeTrue();
|
expect(telemetryCriterion.result).toBeTrue();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('the LAD request', () => {
|
||||||
|
beforeEach(async () => {
|
||||||
|
let telemetryRequestResolve;
|
||||||
|
let telemetryRequestPromise = new Promise((resolve) => {
|
||||||
|
telemetryRequestResolve = resolve;
|
||||||
|
});
|
||||||
|
openmct.telemetry.request.and.callFake(() => {
|
||||||
|
setTimeout(() => {
|
||||||
|
telemetryRequestResolve(mockTelemetry);
|
||||||
|
}, 100);
|
||||||
|
return telemetryRequestPromise;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("returns results for slow LAD requests", async function () {
|
||||||
|
const criteriaRequest = telemetryCriterion.requestLAD();
|
||||||
|
telemetryCriterion.destroy();
|
||||||
|
expect(telemetryCriterion.telemetryObject).toBeUndefined();
|
||||||
|
setTimeout(() => {
|
||||||
|
criteriaRequest.then((result) => {
|
||||||
|
expect(result).toBeDefined();
|
||||||
|
});
|
||||||
|
}, 300);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user