Skip to content

Commit

Permalink
move beforeLogin to inside try/catch
Browse files Browse the repository at this point in the history
  • Loading branch information
sampaiodiego committed Jun 23, 2023
1 parent 94ed872 commit 867e611
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
19 changes: 10 additions & 9 deletions src/client/WebClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as prom from '../lib/prom';
import { Client } from './Client';

export class WebClient extends Client {
loginPromise: Promise<boolean> | undefined;
loginPromise: Promise<void> | undefined;

async beforeLogin(): Promise<void> {
await this.client.connect({});
Expand All @@ -28,17 +28,18 @@ export class WebClient extends Client {

async login(): Promise<void> {
if (this.loginPromise) {
await this.loginPromise;
return;
return this.loginPromise;
}

this.loginPromise = new Promise(async (resolve) => {
await this.beforeLogin();

const end = prom.login.startTimer();
const endAction = prom.actions.startTimer({ action: 'login' });

const { credentials } = this;

try {
await this.beforeLogin();

const user = await this.client.login(credentials);

// await this.client.subscribeLoggedNotify();
Expand Down Expand Up @@ -102,12 +103,12 @@ export class WebClient extends Client {
this.getLoginMethods().map((params) => this.methodViaRest(...params))
);

this.loggedIn = true;

const subscriptions = await this.methodViaRest('subscriptions/get', {});

this.subscriptions = subscriptions as unknown as Subscription[];

this.loggedIn = true;

end({ status: 'success' });
endAction({ action: 'login', status: 'success' });
} catch (e) {
Expand All @@ -116,11 +117,11 @@ export class WebClient extends Client {
endAction({ action: 'login', status: 'error' });
throw e;
} finally {
resolve(true);
resolve();
}
});

await this.loginPromise;
return this.loginPromise;
}

async listenPresence(userIds: string[]): Promise<void> {
Expand Down
8 changes: 1 addition & 7 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,13 @@ const {
TASK_ID,
DATABASE_URL = '', // 'mongodb://localhost:27017';
DATABASE_NAME = 'rocketchat',

MESSAGES_PER_SECOND = '10',
MESSAGE_SENDING_RATE = '0.00115428571', // ='0.001428571,

SET_STATUS_PER_SECOND = '0',
SET_STATUS_RATE = '0.000115428571',

REGISTER_PER_SECOND = '0',
REGISTER_RATE = '0.000115428571',

OPEN_ROOM_PER_SECOND = '0',
OPEN_ROOM_RATE = '0.000115428571',

Expand Down Expand Up @@ -92,10 +90,6 @@ export const config = {
? parseInt(HOW_MANY_USERS) * parseFloat(SET_STATUS_RATE)
: parseInt(SET_STATUS_PER_SECOND),

REGISTER_PER_SECOND: REGISTER_RATE
? parseInt(HOW_MANY_USERS) * parseFloat(REGISTER_RATE)
: parseInt(REGISTER_PER_SECOND),

OPEN_ROOM_PER_SECOND: OPEN_ROOM_RATE
? parseInt(HOW_MANY_USERS) * parseFloat(OPEN_ROOM_RATE)
: parseInt(OPEN_ROOM_PER_SECOND),
Expand Down

0 comments on commit 867e611

Please sign in to comment.