Skip to content

Commit

Permalink
refactor(test/functional/services/remote/network_profiles.ts): mv net…
Browse files Browse the repository at this point in the history
…work consts to network_profiles
  • Loading branch information
Cavit Baturalp Gurdin committed Nov 9, 2021
1 parent b3c103e commit 9b5ef5a
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 7 deletions.
31 changes: 31 additions & 0 deletions test/functional/services/remote/network_profiles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

interface NetworkOptions {
DOWNLOAD: number;
UPLOAD: number;
LATENCY: number;
}

// Download (kb/s) Upload (kb/s) Latency (ms)
// https://gist.github.com/theodorosploumis/fd4086ee58369b68aea6b0782dc96a2e
export const NETWORK_PROFILES: { [key: string]: NetworkOptions } = {
DEFAULT: { DOWNLOAD: 5000, UPLOAD: 1000, LATENCY: 100 },
GPRS: { DOWNLOAD: 50, UPLOAD: 20, LATENCY: 500 },
MOBILE_EDGE: { DOWNLOAD: 240, UPLOAD: 200, LATENCY: 840 },
'2G_REGULAR': { DOWNLOAD: 250, UPLOAD: 50, LATENCY: 300 },
'2G_GOOD': { DOWNLOAD: 450, UPLOAD: 150, LATENCY: 150 },
'3G_SLOW': { DOWNLOAD: 780, UPLOAD: 330, LATENCY: 200 },
'3G_REGULAR': { DOWNLOAD: 750, UPLOAD: 250, LATENCY: 100 },
'3G_GOOD': { DOWNLOAD: 1500, UPLOAD: 750, LATENCY: 40 },
'4G_REGULAR': { DOWNLOAD: 4000, UPLOAD: 3000, LATENCY: 20 },
DSL: { DOWNLOAD: 2000, UPLOAD: 1000, LATENCY: 5 },
CABLE_5MBPS: { DOWNLOAD: 5000, UPLOAD: 1000, LATENCY: 28 },
CABLE_8MBPS: { DOWNLOAD: 8000, UPLOAD: 2000, LATENCY: 10 },
WIFI: { DOWNLOAD: 30000, UPLOAD: 15000, LATENCY: 2 },
};
17 changes: 10 additions & 7 deletions test/functional/services/remote/webdriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { createStdoutSocket } from './create_stdout_stream';
import { preventParallelCalls } from './prevent_parallel_calls';

import { Browsers } from './browsers';
import { NETWORK_PROFILES } from './network_profiles';

const throttleOption: string = process.env.TEST_THROTTLE_NETWORK as string;
const headlessBrowser: string = process.env.TEST_BROWSER_HEADLESS as string;
Expand Down Expand Up @@ -288,20 +289,22 @@ async function attemptToCreateCommand(
const { session, consoleLog$ } = await buildDriverInstance();

if (throttleOption === '1' && browserType === 'chrome') {
const latency: number = +(process.env.KBN_TEST_NETWORK_LATENCY ?? 100);
const downloadThroughput: number = +(process.env.KBN_TEST_DOWNLOAD_THROUGHPUT ?? 1024 * 5); // 5120 bytes
const uploadThroughput: number = +(process.env.KBN_TEST_UPLOAD_THROUGHPUT ?? 1024); // 1024 bytes
const {
DOWNLOAD: downloadThroughput,
UPLOAD: uploadThroughput,
LATENCY: latency,
} = NETWORK_PROFILES[process.env.KBN_NETWORK_TEST_PROFILE ?? 'DEFAULT'];

// Only chrome supports this option.
log.debug(
`NETWORK THROTTLED: ${downloadThroughput}k down, ${uploadThroughput}k up, ${latency} latency.`
`NETWORK THROTTLED: ${downloadThroughput}kb/s down, ${uploadThroughput}kb/s up, ${latency} ms latency.`
);

(session as any).setNetworkConditions({
offline: false,
latency, // Additional latency (ms).
download_throughput: downloadThroughput * 1024, // These speeds are in bites per second, not kilobytes.
upload_throughput: uploadThroughput * 1024,
latency,
download_throughput: downloadThroughput,
upload_throughput: uploadThroughput,
});
}

Expand Down

0 comments on commit 9b5ef5a

Please sign in to comment.