diff --git a/test/functional/services/remote/network_profiles.ts b/test/functional/services/remote/network_profiles.ts new file mode 100644 index 000000000000000..34af9ffb7a1fcc1 --- /dev/null +++ b/test/functional/services/remote/network_profiles.ts @@ -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 }, +}; diff --git a/test/functional/services/remote/webdriver.ts b/test/functional/services/remote/webdriver.ts index 23ef34b9ff1a96c..fb5ce4b4980b054 100644 --- a/test/functional/services/remote/webdriver.ts +++ b/test/functional/services/remote/webdriver.ts @@ -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; @@ -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, }); }