chore: add support for class MultiplexedSession#2191
chore: add support for class MultiplexedSession#2191alkatrivedi wants to merge 9 commits intogoogleapis:mainfrom
Conversation
27cf336 to
51df606
Compare
|
Warning: This pull request is touching the following templated files:
|
No region tags are edited in this PR.This comment is generated by snippet-bot.
|
10899dc to
ba378f2
Compare
04b8f76 to
f6674b9
Compare
25cec8e to
5101675
Compare
5101675 to
99a18ae
Compare
b978f8c to
cda3ed3
Compare
src/multiplexed-session.ts
Outdated
| span.addEvent( | ||
| `Created multiplexed session ${this._multiplexedSession.formattedName_}` | ||
| ); | ||
| this.emit('mux-session-available'); |
There was a problem hiding this comment.
use the constant MUX_SESSION_AVAILABLE
There was a problem hiding this comment.
and everywhere else, in the tests as well
cea4617 to
2815e24
Compare
c57a1be to
e8935b4
Compare
src/multiplexed-session.ts
Outdated
| // frequency to create new mux session | ||
| refreshRate: number; | ||
| _multiplexedSession: Session | null; | ||
| _pingHandle!: NodeJS.Timer; |
There was a problem hiding this comment.
is this used anywhere?
There was a problem hiding this comment.
no where, I have removed it. thanks!
src/multiplexed-session.ts
Outdated
| span.addEvent('Waiting for a multiplexed session to become available'); | ||
| let removeListener: Function; | ||
| const promise = new Promise(resolve => { | ||
| this.once(MUX_SESSION_AVAILABLE, resolve); |
There was a problem hiding this comment.
What happens if this event is never emitted? Is there any timeout?
As per my understanding the MUX_SESSION_AVAILABLE event will be emitted only when there is no error during initial multiplexed session creation
There was a problem hiding this comment.
Thanks for pointing this out.
What happens if this event is never emitted?
In case MUX_SESSION_AVAILABLE event will not get emitted, an error event MUX_SESSION_CREATE_ERROR will get emitted.
Hence, in _getSession we either will wait for the MUX_SESSION_AVAILABLE or for the MUX_SESSION_CREATE_ERROR.
Is there any timeout?
There is no any timeout in the method, we are relying on the events
src/multiplexed-session.ts
Outdated
| }); | ||
|
|
||
| try { | ||
| await promise; |
There was a problem hiding this comment.
In case the multiplexed session creation fails with error, then will that error be captured by getsession and surfaced to customers?
There was a problem hiding this comment.
yes, the error will get surfaced to the customers
| }); | ||
| }); | ||
|
|
||
| describe('_getSession', () => { |
There was a problem hiding this comment.
Can you add a negative case when create session fails with error? What will be the behaviour of getSession?
There was a problem hiding this comment.
Since, we are listening to the error event in _getSession in case of the error from the _createSession, I have added a test for the case when the error event will get emitted, if we are able to listen to that event in _getSession
ed7e9b6 to
625787b
Compare
e6b1c24 to
4584d5e
Compare
| }); | ||
| }); | ||
|
|
||
| it('should propagate errors for Multiplexed Session which gets emitted', async () => { |
There was a problem hiding this comment.
There is no assert in this test ?
There was a problem hiding this comment.
The assertion part is in the if condition
if (err === fakeError) {
resolve();
}
if both the errors are same the promise will get resolve and test will get pass
else {
reject(new Error('Unexpected error emitted'));
}
otherwise the promise will fail with the rejected promise
There was a problem hiding this comment.
Based on our 1:1. I have updated the test, and have used assert instead of if condition
| multiplexedSession.on(MUX_SESSION_CREATE_ERROR, () => { | ||
| done(); | ||
| }); | ||
| multiplexedSession._createSession().catch(err => { |
There was a problem hiding this comment.
Here will .on event called first ? In that case you are calling done here and then .catch will never be called ?
There was a problem hiding this comment.
it will call the done as soon as the error event will get emitted, after that the pointer will go to throw e in getSession hence, we need to catch that error here.
.catch will never be called ?
it will get called, on not calling .catch here will result into the unhandled exception error
src/multiplexed-session.ts
Outdated
| * This method sets up a periodic refresh interval for maintaining the session. The interval duration | ||
| * is determined by the @param refreshRate option, which is provided in days. | ||
| * The default value is 7 days. | ||
| * @throws {Error} In case the multiplexed session creation will get fail, and an error occurs within `_createSession`, |
There was a problem hiding this comment.
| * @throws {Error} In case the multiplexed session creation will get fail, and an error occurs within `_createSession`, | |
| * @throws {Error} If the multiplexed session creation fails in `_createSession`, the error is caught and ignored. This is because the currently active multiplexed session has a 30-day expiry, providing the maintainer with four opportunities (one every 7 days) to refresh the active session. |
| const promises = [ | ||
| new Promise((_, reject) => { | ||
| this.once(MUX_SESSION_CREATE_ERROR, reject); | ||
| removeErrorListener = this.removeListener.bind( |
There was a problem hiding this comment.
For my understanding,
In get_session, we are listening only to the error event but not emitting any error? The actual error gets emitted from the create_Session call?
which means the error surfaced to customer is from the error event emitted by create_session and not get_session?
There was a problem hiding this comment.
No, the _createSession call will emit the error along with the event, which the listener will listen in _getSession. Now, we have two promises in _getSession, for the error case the promise for error event will be there which on begin await will resolve into a rejected promise. hence, an error will get propagated to the parent call
src/multiplexed-session.ts
Outdated
| * @returns {Promise<void>} A Promise that resolves when the session has been successfully created and assigned, an event | ||
| * `mux-session-available` will be emitted to signal that the session is ready. | ||
| * | ||
| * In case of error, an error will get emitted along with the erorr event. |
There was a problem hiding this comment.
| * In case of error, an error will get emitted along with the erorr event. | |
| * In case of error, an error will get emitted along with the error event. |
| * | ||
| * Waits for the `MUX_SESSION_AVAILABLE` event or for the `MUX_SESSION_CREATE_ERROR` | ||
| * to be emitted if the multiplexed session is not yet available. The method listens | ||
| * for these events, and once `mux-session-available` is emitted, it resolves and returns |
There was a problem hiding this comment.
Can you add the behavior when error event is emitted?
|
Marking it as |
|
Closing this PR, since we are facing issues in presubmit check for Owlbot Processor. I have moved the changes into another branch which has been created from the main repo. Link to the new PR. |
This PR contains the code for the newly introduced class
MultiplexedSession.