mirror of
https://github.com/nasa/openmct.git
synced 2025-03-11 06:54:01 +00:00
[Plot] Cancel interval correctly
Fix approach used for interval cancellation associated with resource leak closing for WTD-717; this avoids the exception observed in WTD-750.
This commit is contained in:
parent
6947e0aa42
commit
a0f216764b
@ -46,7 +46,7 @@ define(
|
|||||||
|
|
||||||
function linkChart(scope, element) {
|
function linkChart(scope, element) {
|
||||||
var canvas = element.find("canvas")[0],
|
var canvas = element.find("canvas")[0],
|
||||||
releaseInterval,
|
activeInterval,
|
||||||
chart;
|
chart;
|
||||||
|
|
||||||
// Try to initialize GLChart, which allows drawing using WebGL.
|
// Try to initialize GLChart, which allows drawing using WebGL.
|
||||||
@ -111,8 +111,15 @@ define(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Stop watching for changes to size (scope destroyed)
|
||||||
|
function releaseInterval() {
|
||||||
|
if (activeInterval) {
|
||||||
|
$interval.cancel(activeInterval);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Check for resize, on a timer
|
// Check for resize, on a timer
|
||||||
releaseInterval = $interval(drawIfResized, 1000);
|
activeInterval = $interval(drawIfResized, 1000);
|
||||||
|
|
||||||
// Watch "draw" for external changes to the set of
|
// Watch "draw" for external changes to the set of
|
||||||
// things to be drawn.
|
// things to be drawn.
|
||||||
|
@ -15,7 +15,7 @@ define(
|
|||||||
mockElement,
|
mockElement,
|
||||||
mockCanvas,
|
mockCanvas,
|
||||||
mockGL,
|
mockGL,
|
||||||
mockCancelInterval,
|
mockPromise,
|
||||||
mctChart;
|
mctChart;
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
@ -27,7 +27,8 @@ define(
|
|||||||
jasmine.createSpyObj("$scope", ["$watchCollection", "$on"]);
|
jasmine.createSpyObj("$scope", ["$watchCollection", "$on"]);
|
||||||
mockElement =
|
mockElement =
|
||||||
jasmine.createSpyObj("element", ["find"]);
|
jasmine.createSpyObj("element", ["find"]);
|
||||||
mockCancelInterval = jasmine.createSpy("cancelInterval");
|
mockInterval.cancel = jasmine.createSpy("cancelInterval");
|
||||||
|
mockPromise = jasmine.createSpyObj("promise", ["then"]);
|
||||||
|
|
||||||
|
|
||||||
// mct-chart uses GLChart, so it needs WebGL API
|
// mct-chart uses GLChart, so it needs WebGL API
|
||||||
@ -72,7 +73,7 @@ define(
|
|||||||
|
|
||||||
mockElement.find.andReturn([mockCanvas]);
|
mockElement.find.andReturn([mockCanvas]);
|
||||||
mockCanvas.getContext.andReturn(mockGL);
|
mockCanvas.getContext.andReturn(mockGL);
|
||||||
mockInterval.andReturn(mockCancelInterval);
|
mockInterval.andReturn(mockPromise);
|
||||||
|
|
||||||
mctChart = new MCTChart(mockInterval, mockLog);
|
mctChart = new MCTChart(mockInterval, mockLog);
|
||||||
});
|
});
|
||||||
@ -164,13 +165,13 @@ define(
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Precondition - interval still active
|
// Precondition - interval still active
|
||||||
expect(mockCancelInterval).not.toHaveBeenCalled();
|
expect(mockInterval.cancel).not.toHaveBeenCalled();
|
||||||
|
|
||||||
// Broadcast a $destroy
|
// Broadcast a $destroy
|
||||||
mockScope.$on.mostRecentCall.args[1]();
|
mockScope.$on.mostRecentCall.args[1]();
|
||||||
|
|
||||||
// Should have stopped the interval
|
// Should have stopped the interval
|
||||||
expect(mockCancelInterval).toHaveBeenCalled();
|
expect(mockInterval.cancel).toHaveBeenCalledWith(mockPromise);
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user