mirror of
https://github.com/nasa/openmct.git
synced 2025-01-19 03:06:54 +00:00
[Inspector] Add check to prevent race condition before setting the scope composition. (#1931)
Fixes #1918
This commit is contained in:
parent
0225cbab6a
commit
6145843e86
@ -88,11 +88,15 @@ define(
|
||||
* @private
|
||||
*/
|
||||
ElementsController.prototype.refreshComposition = function (domainObject) {
|
||||
var selectedObjectComposition = domainObject && domainObject.useCapability('composition');
|
||||
var refreshTracker = {};
|
||||
this.currentRefresh = refreshTracker;
|
||||
|
||||
var selectedObjectComposition = domainObject && domainObject.useCapability('composition');
|
||||
if (selectedObjectComposition) {
|
||||
selectedObjectComposition.then(function (composition) {
|
||||
this.scope.composition = composition;
|
||||
if (this.currentRefresh === refreshTracker) {
|
||||
this.scope.composition = composition;
|
||||
}
|
||||
}.bind(this));
|
||||
} else {
|
||||
this.scope.composition = [];
|
||||
|
@ -31,11 +31,34 @@ define(
|
||||
mockSelection,
|
||||
mockDomainObject,
|
||||
mockMutationCapability,
|
||||
mockCompositionCapability,
|
||||
mockCompositionObjects,
|
||||
mockComposition,
|
||||
mockUnlisten,
|
||||
selectable = [],
|
||||
controller;
|
||||
|
||||
function mockPromise(value) {
|
||||
return {
|
||||
then: function (thenFunc) {
|
||||
return mockPromise(thenFunc(value));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function createDomainObject() {
|
||||
return {
|
||||
useCapability: function () {
|
||||
return mockCompositionCapability;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
beforeEach(function () {
|
||||
mockComposition = ["a", "b"];
|
||||
mockCompositionObjects = mockComposition.map(createDomainObject);
|
||||
mockCompositionCapability = mockPromise(mockCompositionObjects);
|
||||
|
||||
mockUnlisten = jasmine.createSpy('unlisten');
|
||||
mockMutationCapability = jasmine.createSpyObj("mutationCapability", [
|
||||
"listen"
|
||||
@ -45,7 +68,7 @@ define(
|
||||
"getCapability",
|
||||
"useCapability"
|
||||
]);
|
||||
mockDomainObject.useCapability.andCallThrough();
|
||||
mockDomainObject.useCapability.andReturn(mockCompositionCapability);
|
||||
mockDomainObject.getCapability.andReturn(mockMutationCapability);
|
||||
|
||||
mockScope = jasmine.createSpyObj("$scope", ['$on']);
|
||||
@ -65,7 +88,7 @@ define(
|
||||
}
|
||||
};
|
||||
|
||||
spyOn(ElementsController.prototype, 'refreshComposition');
|
||||
spyOn(ElementsController.prototype, 'refreshComposition').andCallThrough();
|
||||
|
||||
controller = new ElementsController(mockScope, mockOpenMCT);
|
||||
});
|
||||
@ -137,6 +160,25 @@ define(
|
||||
|
||||
expect(mockDomainObject.getCapability).not.toHaveBeenCalledWith('mutation');
|
||||
});
|
||||
|
||||
it("checks concurrent changes to composition", function () {
|
||||
var secondMockComposition = ["a", "b", "c"],
|
||||
secondMockCompositionObjects = secondMockComposition.map(createDomainObject),
|
||||
firstCompositionCallback,
|
||||
secondCompositionCallback;
|
||||
|
||||
spyOn(mockCompositionCapability, "then").andCallThrough();
|
||||
|
||||
controller.refreshComposition(mockDomainObject);
|
||||
controller.refreshComposition(mockDomainObject);
|
||||
|
||||
firstCompositionCallback = mockCompositionCapability.then.calls[0].args[0];
|
||||
secondCompositionCallback = mockCompositionCapability.then.calls[1].args[0];
|
||||
secondCompositionCallback(secondMockCompositionObjects);
|
||||
firstCompositionCallback(mockCompositionObjects);
|
||||
|
||||
expect(mockScope.composition).toBe(secondMockCompositionObjects);
|
||||
});
|
||||
});
|
||||
}
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user