Skip to content

Commit eba6f0f

Browse files
jvigliottaozyx
andauthored
fix(#7670): Ensure objects unsubscribe from staleness when destroyed (#7736)
* clear any staleness subscriptions before viewing a new object * add checkbox to options for createDomainObjectWithDefaults, update swg staleness provider to use new time api, add test * revert * modified for simplification and to remove the need to update helper methods * consistent naming convention * Update e2e/tests/functional/staleness.e2e.spec.js Co-authored-by: Jesse Mazzella <[email protected]> * adding back vars that were removed --------- Co-authored-by: Jesse Mazzella <[email protected]>
1 parent 017380b commit eba6f0f

File tree

3 files changed

+74
-13
lines changed

3 files changed

+74
-13
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*****************************************************************************
2+
* Open MCT, Copyright (c) 2014-2023, United States Government
3+
* as represented by the Administrator of the National Aeronautics and Space
4+
* Administration. All rights reserved.
5+
*
6+
* Open MCT is licensed under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
* http://www.apache.org/licenses/LICENSE-2.0.
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14+
* License for the specific language governing permissions and limitations
15+
* under the License.
16+
*
17+
* Open MCT includes source code licensed under additional open source
18+
* licenses. See the Open Source Licenses file (LICENSES.md) included with
19+
* this source code distribution or the Licensing information page available
20+
* at runtime from the About dialog for additional information.
21+
*****************************************************************************/
22+
23+
import { createDomainObjectWithDefaults, navigateToObjectWithRealTime } from '../../appActions.js';
24+
import { expect, test } from '../../pluginFixtures.js';
25+
26+
test.describe('Staleness', () => {
27+
test.beforeEach(async ({ page }) => {
28+
await page.goto('./', { waitUntil: 'domcontentloaded' });
29+
});
30+
31+
test('Does not show staleness after navigating from a stale object', async ({ page }) => {
32+
const objectViewSelector = '.c-object-view';
33+
const isStaleClass = 'is-stale';
34+
const staleSWG = await createDomainObjectWithDefaults(page, {
35+
type: 'Sine Wave Generator',
36+
name: 'SWG'
37+
});
38+
39+
// edit properties and enable staleness updates
40+
await page.getByLabel('More actions').click();
41+
await page.getByLabel('Edit properties...').click();
42+
await page.getByLabel('Provide Staleness Updates', { exact: true }).click();
43+
await page.getByLabel('Save').click();
44+
45+
const folder = await createDomainObjectWithDefaults(page, {
46+
type: 'Folder',
47+
name: 'Folder 1'
48+
});
49+
50+
// Navigate to the stale object
51+
await navigateToObjectWithRealTime(page, staleSWG.url);
52+
53+
// Assert that staleness is shown
54+
await expect(page.locator(`${objectViewSelector} .${isStaleClass}`)).toBeAttached({
55+
timeout: 30 * 1000 // Give 30 seconds for the staleness to be updated
56+
});
57+
58+
// Immediately navigate to the folder
59+
await page.goto(folder.url);
60+
61+
// Verify that staleness is not shown
62+
await expect(page.locator(`${objectViewSelector} .${isStaleClass}`)).not.toBeAttached();
63+
});
64+
});

example/generator/SinewaveStalenessProvider.js

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,13 @@ export default class SinewaveLimitProvider extends EventEmitter {
2626
#openmct;
2727
#observingStaleness;
2828
#watchingTheClock;
29-
#isRealTime;
3029

3130
constructor(openmct) {
3231
super();
3332

3433
this.#openmct = openmct;
3534
this.#observingStaleness = {};
3635
this.#watchingTheClock = false;
37-
this.#isRealTime = undefined;
3836
}
3937

4038
supportsStaleness(domainObject) {
@@ -61,10 +59,7 @@ export default class SinewaveLimitProvider extends EventEmitter {
6159
subscribeToStaleness(domainObject, callback) {
6260
const id = this.#getObjectKeyString(domainObject);
6361

64-
if (this.#isRealTime === undefined) {
65-
this.#updateRealTime(this.#openmct.time.getMode());
66-
}
67-
62+
this.#realTimeCheck();
6863
this.#handleClockUpdate();
6964

7065
if (this.#observerExists(id)) {
@@ -92,17 +87,15 @@ export default class SinewaveLimitProvider extends EventEmitter {
9287

9388
if (observers && !this.#watchingTheClock) {
9489
this.#watchingTheClock = true;
95-
this.#openmct.time.on('modeChanged', this.#updateRealTime, this);
90+
this.#openmct.time.on('modeChanged', this.#realTimeCheck, this);
9691
} else if (!observers && this.#watchingTheClock) {
9792
this.#watchingTheClock = false;
98-
this.#openmct.time.off('modeChanged', this.#updateRealTime, this);
93+
this.#openmct.time.off('modeChanged', this.#realTimeCheck, this);
9994
}
10095
}
10196

102-
#updateRealTime(mode) {
103-
this.#isRealTime = mode !== 'fixed';
104-
105-
if (!this.#isRealTime) {
97+
#realTimeCheck() {
98+
if (!this.#openmct.time.isRealTime()) {
10699
Object.keys(this.#observingStaleness).forEach((id) => {
107100
this.#updateStaleness(id, false);
108101
});
@@ -140,7 +133,7 @@ export default class SinewaveLimitProvider extends EventEmitter {
140133
}
141134

142135
#providingStaleness(domainObject) {
143-
return domainObject.telemetry?.staleness === true && this.#isRealTime;
136+
return domainObject.telemetry?.staleness === true && this.#openmct.time.isRealTime();
144137
}
145138

146139
#getObjectKeyString(object) {

src/ui/components/ObjectView.vue

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,10 @@ export default {
352352
show(object, viewKey, immediatelySelect, currentObjectPath) {
353353
this.updateStyle();
354354
355+
if (this.domainObject) {
356+
this.triggerUnsubscribeFromStaleness(this.domainObject);
357+
}
358+
355359
if (this.removeSelectable) {
356360
this.removeSelectable();
357361
delete this.removeSelectable;

0 commit comments

Comments
 (0)