Skip to content

fix(#7670): Ensure objects unsubscribe from staleness when destroyed #7736

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions e2e/tests/functional/staleness.e2e.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*****************************************************************************
* Open MCT, Copyright (c) 2014-2023, United States Government
* as represented by the Administrator of the National Aeronautics and Space
* Administration. All rights reserved.
*
* Open MCT is licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
* Open MCT includes source code licensed under additional open source
* licenses. See the Open Source Licenses file (LICENSES.md) included with
* this source code distribution or the Licensing information page available
* at runtime from the About dialog for additional information.
*****************************************************************************/

import { createDomainObjectWithDefaults, navigateToObjectWithRealTime } from '../../appActions.js';
import { expect, test } from '../../pluginFixtures.js';

test.describe('Staleness', () => {
test.beforeEach(async ({ page }) => {
await page.goto('./', { waitUntil: 'domcontentloaded' });
});

test('Does not show staleness after navigating from a stale object', async ({ page }) => {
const objectViewSelector = '.c-object-view';
const isStaleClass = 'is-stale';
const staleSWG = await createDomainObjectWithDefaults(page, {
type: 'Sine Wave Generator',
name: 'SWG'
});

// edit properties and enable staleness updates
await page.getByLabel('More actions').click();
await page.getByLabel('Edit properties...').click();
await page.getByLabel('Provide Staleness Updates', { exact: true }).click();
await page.getByLabel('Save').click();
Comment on lines +39 to +43
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙌


const folder = await createDomainObjectWithDefaults(page, {
type: 'Folder',
name: 'Folder 1'
});

// Navigate to the stale object
await navigateToObjectWithRealTime(page, staleSWG.url);

// Assert that staleness is shown
await expect(page.locator(`.c-object-view .${isStaleClass}`)).toBeAttached({
timeout: 30 * 1000 // Give 30 seconds for the staleness to be updated
});

// Immediately navigate to the folder
await page.goto(folder.url);

// Verify that staleness is not shown
await expect(page.locator(`.c-object-view .${isStaleClass}`)).not.toBeAttached();
});
});
19 changes: 6 additions & 13 deletions example/generator/SinewaveStalenessProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,13 @@
#openmct;
#observingStaleness;
#watchingTheClock;
#isRealTime;

constructor(openmct) {
super();

this.#openmct = openmct;
this.#observingStaleness = {};
this.#watchingTheClock = false;
this.#isRealTime = undefined;
}

supportsStaleness(domainObject) {
Expand All @@ -61,10 +59,7 @@
subscribeToStaleness(domainObject, callback) {
const id = this.#getObjectKeyString(domainObject);

if (this.#isRealTime === undefined) {
this.#updateRealTime(this.#openmct.time.getMode());
}

this.#realTimeCheck();

Check warning on line 62 in example/generator/SinewaveStalenessProvider.js

View check run for this annotation

Codecov / codecov/patch

example/generator/SinewaveStalenessProvider.js#L62

Added line #L62 was not covered by tests
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whoomp there it is

this.#handleClockUpdate();

if (this.#observerExists(id)) {
Expand Down Expand Up @@ -92,17 +87,15 @@

if (observers && !this.#watchingTheClock) {
this.#watchingTheClock = true;
this.#openmct.time.on('modeChanged', this.#updateRealTime, this);
this.#openmct.time.on('modeChanged', this.#realTimeCheck, this);

Check warning on line 90 in example/generator/SinewaveStalenessProvider.js

View check run for this annotation

Codecov / codecov/patch

example/generator/SinewaveStalenessProvider.js#L90

Added line #L90 was not covered by tests
} else if (!observers && this.#watchingTheClock) {
this.#watchingTheClock = false;
this.#openmct.time.off('modeChanged', this.#updateRealTime, this);
this.#openmct.time.off('modeChanged', this.#realTimeCheck, this);

Check warning on line 93 in example/generator/SinewaveStalenessProvider.js

View check run for this annotation

Codecov / codecov/patch

example/generator/SinewaveStalenessProvider.js#L93

Added line #L93 was not covered by tests
}
}

#updateRealTime(mode) {
this.#isRealTime = mode !== 'fixed';

if (!this.#isRealTime) {
#realTimeCheck() {
if (!this.#openmct.time.isRealTime()) {

Check warning on line 98 in example/generator/SinewaveStalenessProvider.js

View check run for this annotation

Codecov / codecov/patch

example/generator/SinewaveStalenessProvider.js#L98

Added line #L98 was not covered by tests
Object.keys(this.#observingStaleness).forEach((id) => {
this.#updateStaleness(id, false);
});
Expand Down Expand Up @@ -140,7 +133,7 @@
}

#providingStaleness(domainObject) {
return domainObject.telemetry?.staleness === true && this.#isRealTime;
return domainObject.telemetry?.staleness === true && this.#openmct.time.isRealTime();

Check warning on line 136 in example/generator/SinewaveStalenessProvider.js

View check run for this annotation

Codecov / codecov/patch

example/generator/SinewaveStalenessProvider.js#L136

Added line #L136 was not covered by tests
}

#getObjectKeyString(object) {
Expand Down
4 changes: 4 additions & 0 deletions src/ui/components/ObjectView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,10 @@ export default {
show(object, viewKey, immediatelySelect, currentObjectPath) {
this.updateStyle();

if (this.domainObject) {
this.triggerUnsubscribeFromStaleness(this.domainObject);
}

if (this.removeSelectable) {
this.removeSelectable();
delete this.removeSelectable;
Expand Down
Loading