Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
alkatrivedi committed Dec 9, 2024
1 parent 5c2e5f6 commit a6f098f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/multiplexed-session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export class MultiplexedSession
* @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.
* In case of error, an error will get emitted along with the error event.
*
* @private
*/
Expand All @@ -127,7 +127,7 @@ export class MultiplexedSession
});
this._multiplexedSession = createSessionResponse;
span.addEvent(
`Created multiplexed session ${this._multiplexedSession.formattedName_}`
`Created multiplexed session ${this._multiplexedSession.id}`
);
this.emit(MUX_SESSION_AVAILABLE);
} catch (e) {
Expand All @@ -147,8 +147,10 @@ export class MultiplexedSession
* 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`,
* it is caught and ignored.
*
* @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.
*
* @returns {void} This method does not return any value.
*
Expand Down Expand Up @@ -206,6 +208,8 @@ export class MultiplexedSession
* for these events, and once `mux-session-available` is emitted, it resolves and returns
* the session.
*
* In case of error, the promise will get rejected and the error will get bubble up to the parent method.
*
* @returns {Promise<Session | null>} A promise that resolves with the current multiplexed session if available,
* or `null` if the session is not available.
*
Expand Down
7 changes: 7 additions & 0 deletions test/multiplexed-session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,18 @@ describe('MultiplexedSession', () => {
describe('_maintain', () => {
let clock;
let createSessionStub;

beforeEach(() => {
createSessionStub = sandbox
.stub(multiplexedSession, '_createSession')
.resolves();
clock = sandbox.useFakeTimers();
});

afterEach(() => {
clock.restore();
});

it('should set an interval to refresh mux sessions', () => {
const expectedInterval =
multiplexedSession.refreshRate! * 24 * 60 * 60000;
Expand All @@ -155,6 +158,10 @@ describe('MultiplexedSession', () => {

it('should emit the MUX_SESSION_AVAILABLE event on successfully creating mux session', done => {
multiplexedSession.on(MUX_SESSION_AVAILABLE, () => {
assert.strictEqual(
multiplexedSession._multiplexedSession,
fakeMuxSession
);
done();
});
multiplexedSession._createSession();
Expand Down

0 comments on commit a6f098f

Please sign in to comment.