Skip to content
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

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

Merged
merged 7 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
15 changes: 13 additions & 2 deletions e2e/appActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,19 @@ async function createDomainObjectWithDefaults(
// If there are any further parameters, fill them in
for (const [key, value] of Object.entries(customParameters)) {
const input = page.locator(`form[name="mctForm"] ${key}`);
await input.fill('');
await input.fill(value);
const inputType = await input.getAttribute('type');

if (inputType === 'checkbox') {
// Locate the slider span associated with the checkbox
const slider = input.locator('+ .c-toggle-switch__slider');
const isChecked = await input.isChecked();
if ((value === 'true' && !isChecked) || (value === 'false' && isChecked)) {
await slider.click();
}
} else {
await input.fill('');
await input.fill(value);
}
jvigliotta marked this conversation as resolved.
Show resolved Hide resolved
}

// Click OK button and wait for Navigate event
Expand Down
63 changes: 63 additions & 0 deletions e2e/tests/functional/staleness.e2e.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*****************************************************************************
* 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';
Fixed Show fixed Hide fixed
const isStaleClass = 'is-stale';
const staleSWG = await createDomainObjectWithDefaults(page, {
type: 'Sine Wave Generator',
name: 'SWG',
parent: 'mine',
customParameters: {
'label:has([aria-label="Provide Staleness Updates"]) > input': 'true'
}
});
const folder = await createDomainObjectWithDefaults(page, {
type: 'Folder',
name: 'Folder 1'
});

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

// Wait for staleness to be updated
await page.waitForSelector(`.${isStaleClass}`, { state: 'attached' });

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

// Verify that staleness is not shown
const objectView = page.locator(objectViewSelector);
const containsStaleClass = await objectView.evaluate((node, staleClass) => {
return node.classList.contains(staleClass);
}, isStaleClass);
await expect(containsStaleClass).toBeFalsy();
});
});
jvigliotta marked this conversation as resolved.
Show resolved Hide resolved
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 @@ export default class SinewaveLimitProvider extends EventEmitter {
#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 @@ export default class SinewaveLimitProvider extends EventEmitter {
subscribeToStaleness(domainObject, callback) {
const id = this.#getObjectKeyString(domainObject);

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

this.#realtimeCheck();
Copy link
Contributor

Choose a reason for hiding this comment

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

this method name slaps

this.#handleClockUpdate();

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

if (observers && !this.#watchingTheClock) {
this.#watchingTheClock = true;
this.#openmct.time.on('modeChanged', this.#updateRealTime, this);
this.#openmct.time.on('modeChanged', this.#realtimeCheck, this);
} else if (!observers && this.#watchingTheClock) {
this.#watchingTheClock = false;
this.#openmct.time.off('modeChanged', this.#updateRealTime, this);
this.#openmct.time.off('modeChanged', this.#realtimeCheck, this);
}
}

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

if (!this.#isRealTime) {
#realtimeCheck() {
if (!this.#openmct.time.isRealTime()) {
Object.keys(this.#observingStaleness).forEach((id) => {
this.#updateStaleness(id, false);
});
Expand Down Expand Up @@ -140,7 +133,7 @@ export default class SinewaveLimitProvider extends EventEmitter {
}

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

#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) {
shefalijoshi marked this conversation as resolved.
Show resolved Hide resolved
this.triggerUnsubscribeFromStaleness(this.domainObject);
}

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