-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Conversation
8697fde
to
13c4887
Compare
There was a problem hiding this 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 = {}; |
There was a problem hiding this comment.
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'; |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
?
- `all`: every failure currently active | |
- `active`: every failure currently active |
- 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- 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 |
} | ||
} | ||
}), | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
}; | |
}; | |
triggerToAllSubscribers: jest.fn((event, ...args) => { | ||
const subs = listeners[event]; | ||
|
||
const jsonArgs = args.map((it) => JSON.stringify(it)).map((it) => JSON.parse(it)); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 = { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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'; |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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?
const o = orchestrator(); | ||
const rfp = remoteProvider(); | ||
|
||
await deactivateFailure(o); | ||
|
||
expect(rfp.isActive(identifier)).toBe(false); |
There was a problem hiding this comment.
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.
const o = orchestrator(); | ||
const rfp = remoteProvider(); | ||
|
||
await remoteDeactivateFailure(o, rfp); | ||
|
||
expect(o.isActive(identifier)).toBe(false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: As above.
Thanks for the review. Will be looking at those shortly. |
This will need to be redone because of #7821 anyway |
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 bothFailuresOrchestrator
and a newRemoteFailuresProvider
.RemoteFailuresProvider
instances can be unlimited in numbers and recieve / send data from and to theFailuresOrchestrator
via Coherent events. It recieves state updates and asks the orchestrator to activate or deactivate failures when a user interaction is made.Testing instructions
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.