mirror of
https://github.com/nasa/openmct.git
synced 2025-03-22 03:55:31 +00:00
[Telemetry] Fix failing specs
Fix failing specs related to usage of subscriptions in the TelemetryController, introduced for WTD-644.
This commit is contained in:
parent
de57628b01
commit
12c4863feb
@ -123,6 +123,21 @@ define(
|
||||
}));
|
||||
}
|
||||
|
||||
// Subscribe to streaming telemetry updates
|
||||
function subscribe(telemetryCapability, id) {
|
||||
return telemetryCapability.subscribe(function () {
|
||||
requestTelemetryForId(id, false);
|
||||
});
|
||||
}
|
||||
|
||||
// Stop listening to active subscriptions
|
||||
function unsubscribe() {
|
||||
self.subscriptions.forEach(function (s) {
|
||||
return s && s();
|
||||
});
|
||||
self.subscriptions = [];
|
||||
}
|
||||
|
||||
// Look up domain objects which have telemetry capabilities.
|
||||
// This will either be the object in view, or object that
|
||||
// this object delegates its telemetry capability to.
|
||||
@ -152,12 +167,17 @@ define(
|
||||
function buildResponseContainer(domainObject) {
|
||||
var telemetry = domainObject &&
|
||||
domainObject.getCapability("telemetry"),
|
||||
id,
|
||||
metadata;
|
||||
|
||||
if (telemetry) {
|
||||
id = domainObject.getId();
|
||||
|
||||
self.subscriptions.push(subscribe(telemetry, id));
|
||||
|
||||
metadata = telemetry.getMetadata();
|
||||
|
||||
self.response[domainObject.getId()] = {
|
||||
self.response[id] = {
|
||||
name: domainObject.getModel().name,
|
||||
domainObject: domainObject,
|
||||
metadata: metadata,
|
||||
@ -186,29 +206,13 @@ define(
|
||||
}
|
||||
}
|
||||
|
||||
// Subscribe to streaming telemetry updates
|
||||
function subscribe(domainObject) {
|
||||
var telemetryCapability =
|
||||
domainObject.getCapability("telemetry");
|
||||
return telemetryCapability.subscribe(function () {
|
||||
requestTelemetryForId(
|
||||
domainObject.getId(),
|
||||
false
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
// Stop listening to active subscriptions
|
||||
function unsubscribe() {
|
||||
self.subscriptions.forEach(function (s) {
|
||||
return s && s();
|
||||
});
|
||||
}
|
||||
|
||||
// Build response containers (as above) for all
|
||||
// domain objects, and update some controller-internal
|
||||
// state to support subsequent calls.
|
||||
function buildResponseContainers(domainObjects) {
|
||||
// Clear out any existing subscriptions
|
||||
unsubscribe();
|
||||
|
||||
// Build the containers
|
||||
domainObjects.forEach(buildResponseContainer);
|
||||
|
||||
@ -227,9 +231,6 @@ define(
|
||||
return self.response[id].metadata;
|
||||
});
|
||||
|
||||
// Subscribe to all telemetry objects
|
||||
self.subscriptions = domainObjects.map(subscribe);
|
||||
|
||||
// Issue a request for the new objects, if we
|
||||
// know what our request looks like
|
||||
if (self.request) {
|
||||
|
@ -12,6 +12,7 @@ define(
|
||||
mockLog,
|
||||
mockDomainObject,
|
||||
mockTelemetry,
|
||||
mockUnsubscribe,
|
||||
controller;
|
||||
|
||||
function mockPromise(value) {
|
||||
@ -44,8 +45,9 @@ define(
|
||||
|
||||
mockTelemetry = jasmine.createSpyObj(
|
||||
"telemetry",
|
||||
[ "requestData", "getMetadata" ]
|
||||
[ "requestData", "subscribe", "getMetadata" ]
|
||||
);
|
||||
mockUnsubscribe = jasmine.createSpy("unsubscribe");
|
||||
|
||||
mockQ.when.andCallFake(mockPromise);
|
||||
mockQ.all.andReturn(mockPromise([mockDomainObject]));
|
||||
@ -63,6 +65,7 @@ define(
|
||||
mockTelemetry.requestData.andReturn(mockPromise({
|
||||
telemetryKey: "some value"
|
||||
}));
|
||||
mockTelemetry.subscribe.andReturn(mockUnsubscribe);
|
||||
|
||||
controller = new TelemetryController(
|
||||
mockScope,
|
||||
|
Loading…
x
Reference in New Issue
Block a user