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

refactor: remote failures provider #6971

Closed

Conversation

Benjozork
Copy link
Member

Summary of Changes

In order to support a remote instance of the flyPad, global failure state needs to be available across multiple instruments.

Since the FailuresOrchestrator is meant to be unique across all instruments, the one in the flyPad present in the cockpit must remain the coordinator of failure state and control.

This patch introduces an interface, FailuresProvider, which is implemented by both FailuresOrchestrator and a new RemoteFailuresProvider. RemoteFailuresProvider instances can be unlimited in numbers and recieve / send data from and to the FailuresOrchestrator via Coherent events. It recieves state updates and asks the orchestrator to activate or deactivate failures when a user interaction is made.

Testing instructions

  • Make sure Failures page on the EFB still works.

How to download the PR for QA

Every new commit to this PR will cause a new A32NX artifact to be created, built, and uploaded.

  1. Make sure you are signed in to GitHub
  2. Click on the Checks tab on the PR
  3. On the left side, click on the bottom PR tab
  4. Click on the A32NX download link at the bottom of the page

@Benjozork Benjozork marked this pull request as draft March 26, 2022 00:38
@Benjozork Benjozork marked this pull request as ready for review April 2, 2022 00:59
Copy link
Member

@tracernz tracernz left a comment

Choose a reason for hiding this comment

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

LGTM.... Would be nice for @davidwalschots to take a look as the architect of the system.

@@ -0,0 +1,16 @@
export let listeners = {};
Copy link
Member

Choose a reason for hiding this comment

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

/external/jest/ViewListener.ts
  1:1  error  Parsing error: 'import' and 'export' may appear only with 'sourceType: module'

@@ -1,6 +1,5 @@
import React, { useState } from 'react';
import { MemoryRouter as Router } from 'react-router-dom';
Copy link
Member

Choose a reason for hiding this comment

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

 /external/src/instruments/src/EFB/index.tsx
  66:14  error  'Router' is not defined  react/jsx-no-undef

- Dataflow: Failures orchestrator -> Remote failures providers
- Notifies any remote failures providers of available, active and changing failures
- Payload: `[active: number[], changing: number[]]`
- `all`: every failure currently active
Copy link
Member

Choose a reason for hiding this comment

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

I'm guessing this should be active?

Suggested change
- `all`: every failure currently active
- `active`: every failure currently active

Comment on lines +46 to +52
- CONFIRM_ACTIVATE_FAILURE
- Dataflow: Failures orchestrator -> Remote failures providers
- Confirms to remote providers that a failure was activated
- Payload: `[identifier: number]`
- `identifier`: failure identifier

- CONFIRM_DEACTIVATE_FAILURE
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
- CONFIRM_ACTIVATE_FAILURE
- Dataflow: Failures orchestrator -> Remote failures providers
- Confirms to remote providers that a failure was activated
- Payload: `[identifier: number]`
- `identifier`: failure identifier
- CONFIRM_DEACTIVATE_FAILURE
- A32NX_CONFIRM_ACTIVATE_FAILURE
- Dataflow: Failures orchestrator -> Remote failures providers
- Confirms to remote providers that a failure was activated
- Payload: `[identifier: number]`
- `identifier`: failure identifier
- A32NX_CONFIRM_DEACTIVATE_FAILURE

}
}
}),
};
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
};
};

triggerToAllSubscribers: jest.fn((event, ...args) => {
const subs = listeners[event];

const jsonArgs = args.map((it) => JSON.stringify(it)).map((it) => JSON.parse(it));
Copy link
Member

Choose a reason for hiding this comment

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

thought: You copy the arguments. If your goal is to protect the caller of triggerToAllSubscribers from suddenly having its own objects changed under him, then this works. If your goal is for every individual subscriber to have their own copy of objects, then this will need to move within the loop.

Copy link
Member Author

Choose a reason for hiding this comment

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

The goal here is to reproduce what MSFS does (value -> json -> value), and lose the prototypes and object identities.

triggerToAllSubscribers: jest.fn((event, ...args) => {
const subs = listeners[event];

const jsonArgs = args.map((it) => JSON.stringify(it)).map((it) => JSON.parse(it));
Copy link
Member

Choose a reason for hiding this comment

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

thought: You copy the arguments. If your goal is to protect the caller of triggerToAllSubscribers from suddenly having its own objects changed under him, then this works. If your goal is for every individual subscriber to have their own copy of objects, then this will need to move within the loop.

Copy link
Member Author

Choose a reason for hiding this comment

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

The goal here is to reproduce what MSFS does (value -> json -> value), and lose the prototypes and object identities.

});

/** @type {Partial<ViewListener.ViewListener>} */
const MockViewListener = {
Copy link
Member

Choose a reason for hiding this comment

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

question: Is the code duplicate intentional?

Copy link
Member Author

Choose a reason for hiding this comment

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

No. The TS file wasn't meant to be committed.

return new Promise((resolve) => setImmediate(resolve));
}

const prefix = 'PREFIX';
Copy link
Member

Choose a reason for hiding this comment

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

thought: I'd be very careful about putting all these items in one file. I deliberately chose not to, because understanding tests where everything can be found locally is easier.
suggestion: Move code back to their original position.

*/
export class FailuresOrchestrator {
export class FailuresOrchestrator implements FailuresProvider {
Copy link
Member

Choose a reason for hiding this comment

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

thought: I have the feeling we're missing some abstractions in these changes. Now this type needs to know about Coherent's on, RegisterViewListener, and publishing. Maybe there's some additional work here?

Comment on lines +37 to +42
const o = orchestrator();
const rfp = remoteProvider();

await deactivateFailure(o);

expect(rfp.isActive(identifier)).toBe(false);
Copy link
Member

Choose a reason for hiding this comment

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

suggestion: First bring the test in a state where the failure is active in the rfp, then remove the failure and assert.

Comment on lines +85 to +90
const o = orchestrator();
const rfp = remoteProvider();

await remoteDeactivateFailure(o, rfp);

expect(o.isActive(identifier)).toBe(false);
Copy link
Member

Choose a reason for hiding this comment

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

suggestion: As above.

@tracernz tracernz added this to the v0.8.0 milestone Apr 5, 2022
@Benjozork
Copy link
Member Author

Thanks for the review. Will be looking at those shortly.

@beheh beheh removed this from the v0.8.0 milestone Apr 29, 2022
@2hwk 2hwk added this to the v0.9.0 milestone Apr 29, 2022
@2hwk 2hwk modified the milestones: v0.9.0, Backlog Aug 6, 2022
@Benjozork
Copy link
Member Author

This will need to be redone because of #7821 anyway

@Benjozork Benjozork closed this Dec 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: ❌ Cancelled/Unfinished
Development

Successfully merging this pull request may close these issues.

5 participants