[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:
Victor Woeltjen 2015-01-28 15:53:13 -08:00
parent 6947e0aa42
commit a0f216764b
2 changed files with 15 additions and 7 deletions

View File

@ -46,7 +46,7 @@ define(
function linkChart(scope, element) {
var canvas = element.find("canvas")[0],
releaseInterval,
activeInterval,
chart;
// 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
releaseInterval = $interval(drawIfResized, 1000);
activeInterval = $interval(drawIfResized, 1000);
// Watch "draw" for external changes to the set of
// things to be drawn.

View File

@ -15,7 +15,7 @@ define(
mockElement,
mockCanvas,
mockGL,
mockCancelInterval,
mockPromise,
mctChart;
beforeEach(function () {
@ -27,7 +27,8 @@ define(
jasmine.createSpyObj("$scope", ["$watchCollection", "$on"]);
mockElement =
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
@ -72,7 +73,7 @@ define(
mockElement.find.andReturn([mockCanvas]);
mockCanvas.getContext.andReturn(mockGL);
mockInterval.andReturn(mockCancelInterval);
mockInterval.andReturn(mockPromise);
mctChart = new MCTChart(mockInterval, mockLog);
});
@ -164,13 +165,13 @@ define(
);
// Precondition - interval still active
expect(mockCancelInterval).not.toHaveBeenCalled();
expect(mockInterval.cancel).not.toHaveBeenCalled();
// Broadcast a $destroy
mockScope.$on.mostRecentCall.args[1]();
// Should have stopped the interval
expect(mockCancelInterval).toHaveBeenCalled();
expect(mockInterval.cancel).toHaveBeenCalledWith(mockPromise);
});
});