Skip to content

Commit 6e324b6

Browse files
use constants
1 parent 0108c7c commit 6e324b6

5 files changed

Lines changed: 44 additions & 23 deletions

File tree

src/config/constants.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
export const POLLING = {
2+
MIN_INTERVAL_MS: 5000,
3+
MAX_INTERVAL_MS: 30000,
4+
BACKOFF_MULTIPLIER: 1.5,
5+
MAX_DURATION_MS: 60 * 60 * 1000,
6+
} as const;
7+
8+
export const HTTP = {
9+
TIMEOUT_MS: 30000,
10+
} as const;
11+
12+
export const SOCKET = {
13+
RECONNECTION_ATTEMPTS: 3,
14+
RECONNECTION_DELAY_MS: 1000,
15+
TIMEOUT_MS: 10000,
16+
} as const;

src/providers/base_provider.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
checkInternetConnectivity,
2121
formatConnectivityResults,
2222
} from '../utils/connectivity';
23+
import { POLLING } from '../config/constants';
2324

2425
/**
2526
* Common interface for run information shared by all providers
@@ -54,10 +55,11 @@ export interface BaseProviderOptions {
5455
export default abstract class BaseProvider<
5556
TOptions extends BaseProviderOptions,
5657
> {
57-
protected readonly MIN_POLL_INTERVAL_MS = 5000;
58-
protected readonly MAX_POLL_INTERVAL_MS = 30000;
59-
protected readonly POLL_BACKOFF_MULTIPLIER = 1.5;
60-
protected readonly MAX_POLL_DURATION_MS = 60 * 60 * 1000; // 1 hour
58+
protected readonly MIN_POLL_INTERVAL_MS: number = POLLING.MIN_INTERVAL_MS;
59+
protected readonly MAX_POLL_INTERVAL_MS: number = POLLING.MAX_INTERVAL_MS;
60+
protected readonly POLL_BACKOFF_MULTIPLIER: number =
61+
POLLING.BACKOFF_MULTIPLIER;
62+
protected readonly MAX_POLL_DURATION_MS: number = POLLING.MAX_DURATION_MS;
6163

6264
/**
6365
* Returns the next polling interval based on whether the status payload

src/providers/espresso.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { io, Socket } from 'socket.io-client';
88
import TestingBotError from '../models/testingbot_error';
99
import utils from '../utils';
1010
import BaseProvider from './base_provider';
11+
import { HTTP, SOCKET } from '../config/constants';
1112

1213
export interface EspressoRunEnvironment {
1314
device?: string;
@@ -247,7 +248,7 @@ export default class Espresso extends BaseProvider<EspressoOptions> {
247248
username: this.credentials.userName,
248249
password: this.credentials.accessKey,
249250
},
250-
timeout: 30000, // 30 second timeout
251+
timeout: HTTP.TIMEOUT_MS,
251252
},
252253
);
253254

@@ -294,7 +295,7 @@ export default class Espresso extends BaseProvider<EspressoOptions> {
294295
username: this.credentials.userName,
295296
password: this.credentials.accessKey,
296297
},
297-
timeout: 30000, // 30 second timeout
298+
timeout: HTTP.TIMEOUT_MS,
298299
});
299300

300301
// Check for version update notification
@@ -482,7 +483,7 @@ export default class Espresso extends BaseProvider<EspressoOptions> {
482483
username: this.credentials.userName,
483484
password: this.credentials.accessKey,
484485
},
485-
timeout: 30000, // 30 second timeout
486+
timeout: HTTP.TIMEOUT_MS,
486487
});
487488

488489
// Check for version update notification
@@ -520,9 +521,9 @@ export default class Espresso extends BaseProvider<EspressoOptions> {
520521
this.socket = io(this.updateServer, {
521522
transports: ['websocket'],
522523
reconnection: true,
523-
reconnectionAttempts: 3,
524-
reconnectionDelay: 1000,
525-
timeout: 10000,
524+
reconnectionAttempts: SOCKET.RECONNECTION_ATTEMPTS,
525+
reconnectionDelay: SOCKET.RECONNECTION_DELAY_MS,
526+
timeout: SOCKET.TIMEOUT_MS,
526527
});
527528

528529
this.socket.on('connect', () => {

src/providers/maestro.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import utils from '../utils';
1414
import { detectPlatformFromFile } from '../utils/file-type-detector';
1515
import pc from 'picocolors';
1616
import BaseProvider from './base_provider';
17+
import { HTTP, SOCKET } from '../config/constants';
1718

1819
export interface MaestroRunAssets {
1920
logs?: Record<string, string>;
@@ -1566,7 +1567,7 @@ export default class Maestro extends BaseProvider<MaestroOptions> {
15661567
username: this.credentials.userName,
15671568
password: this.credentials.accessKey,
15681569
},
1569-
timeout: 30000, // 30 second timeout
1570+
timeout: HTTP.TIMEOUT_MS,
15701571
},
15711572
);
15721573

@@ -1614,7 +1615,7 @@ export default class Maestro extends BaseProvider<MaestroOptions> {
16141615
username: this.credentials.userName,
16151616
password: this.credentials.accessKey,
16161617
},
1617-
timeout: 30000, // 30 second timeout
1618+
timeout: HTTP.TIMEOUT_MS,
16181619
});
16191620

16201621
// Check for version update notification
@@ -2177,7 +2178,7 @@ export default class Maestro extends BaseProvider<MaestroOptions> {
21772178
username: this.credentials.userName,
21782179
password: this.credentials.accessKey,
21792180
},
2180-
timeout: 30000, // 30 second timeout
2181+
timeout: HTTP.TIMEOUT_MS,
21812182
},
21822183
);
21832184

@@ -2225,7 +2226,7 @@ export default class Maestro extends BaseProvider<MaestroOptions> {
22252226
username: this.credentials.userName,
22262227
password: this.credentials.accessKey,
22272228
},
2228-
timeout: 30000, // 30 second timeout
2229+
timeout: HTTP.TIMEOUT_MS,
22292230
},
22302231
);
22312232

@@ -2553,9 +2554,9 @@ export default class Maestro extends BaseProvider<MaestroOptions> {
25532554
this.socket = io(this.updateServer, {
25542555
transports: ['websocket'],
25552556
reconnection: true,
2556-
reconnectionAttempts: 3,
2557-
reconnectionDelay: 1000,
2558-
timeout: 10000,
2557+
reconnectionAttempts: SOCKET.RECONNECTION_ATTEMPTS,
2558+
reconnectionDelay: SOCKET.RECONNECTION_DELAY_MS,
2559+
timeout: SOCKET.TIMEOUT_MS,
25592560
});
25602561

25612562
this.socket.on('connect', () => {

src/providers/xcuitest.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { io, Socket } from 'socket.io-client';
88
import TestingBotError from '../models/testingbot_error';
99
import utils from '../utils';
1010
import BaseProvider from './base_provider';
11+
import { HTTP, SOCKET } from '../config/constants';
1112

1213
export interface XCUITestRunEnvironment {
1314
device?: string;
@@ -247,7 +248,7 @@ export default class XCUITest extends BaseProvider<XCUITestOptions> {
247248
username: this.credentials.userName,
248249
password: this.credentials.accessKey,
249250
},
250-
timeout: 30000, // 30 second timeout
251+
timeout: HTTP.TIMEOUT_MS,
251252
},
252253
);
253254

@@ -294,7 +295,7 @@ export default class XCUITest extends BaseProvider<XCUITestOptions> {
294295
username: this.credentials.userName,
295296
password: this.credentials.accessKey,
296297
},
297-
timeout: 30000, // 30 second timeout
298+
timeout: HTTP.TIMEOUT_MS,
298299
});
299300

300301
// Check for version update notification
@@ -483,7 +484,7 @@ export default class XCUITest extends BaseProvider<XCUITestOptions> {
483484
password: this.credentials.accessKey,
484485
},
485486
responseType: reportFormat === 'html' ? 'arraybuffer' : 'text',
486-
timeout: 30000, // 30 second timeout
487+
timeout: HTTP.TIMEOUT_MS,
487488
});
488489

489490
// Check for version update notification
@@ -523,9 +524,9 @@ export default class XCUITest extends BaseProvider<XCUITestOptions> {
523524
this.socket = io(this.updateServer, {
524525
transports: ['websocket'],
525526
reconnection: true,
526-
reconnectionAttempts: 3,
527-
reconnectionDelay: 1000,
528-
timeout: 10000,
527+
reconnectionAttempts: SOCKET.RECONNECTION_ATTEMPTS,
528+
reconnectionDelay: SOCKET.RECONNECTION_DELAY_MS,
529+
timeout: SOCKET.TIMEOUT_MS,
529530
});
530531

531532
this.socket.on('connect', () => {

0 commit comments

Comments
 (0)