Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(e2e): add a new mode to e2e tests to run against logged in sandbox; add rolling index build e2e tests COMPASS-8361 #6411

Merged
merged 2 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .evergreen/buildvariants-and-tasks.in.yml
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,12 @@ buildvariants:
<% } %>
<% } %>

- name: test-web-sandbox-atlas-cloud
display_name: Test Web Sandbox (w/ Atlas Cloud login)
run_on: ubuntu2004-large
tasks:
- name: test-web-sandbox-atlas-cloud

- name: generate-vulnerability-report
display_name: Vulnerability Report
run_on: ubuntu2004-large
Expand Down Expand Up @@ -504,6 +510,21 @@ tasks:
<% } %>
<% } %>

- name: test-web-sandbox-atlas-cloud
tags:
- required-for-publish
- run-on-pr
- assigned_to_jira_team_compass_compass
- foliage_check_task_only
commands:
- func: prepare
- func: install
- func: bootstrap
- func: test-web-sandbox-atlas-cloud
vars:
compass_distribution: compass
debug: 'compass-e2e-tests*,electron*,hadron*,mongo*'

- name: create_static_analysis_report
tags: ['required-for-publish', 'run-on-pr']
depends_on:
Expand Down
19 changes: 19 additions & 0 deletions .evergreen/buildvariants-and-tasks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,11 @@ buildvariants:
- name: test-web-sandbox-firefox-1
- name: test-web-sandbox-firefox-2
- name: test-web-sandbox-firefox-3
- name: test-web-sandbox-atlas-cloud
display_name: Test Web Sandbox (w/ Atlas Cloud login)
run_on: ubuntu2004-large
tasks:
- name: test-web-sandbox-atlas-cloud
- name: generate-vulnerability-report
display_name: Vulnerability Report
run_on: ubuntu2004-large
Expand Down Expand Up @@ -1715,6 +1720,20 @@ tasks:
e2e_test_groups: 3
e2e_test_group: 3
debug: compass-e2e-tests*,electron*,hadron*,mongo*
- name: test-web-sandbox-atlas-cloud
tags:
- required-for-publish
- run-on-pr
- assigned_to_jira_team_compass_compass
- foliage_check_task_only
commands:
- func: prepare
- func: install
- func: bootstrap
- func: test-web-sandbox-atlas-cloud
vars:
compass_distribution: compass
debug: compass-e2e-tests*,electron*,hadron*,mongo*
- name: create_static_analysis_report
tags:
- required-for-publish
Expand Down
36 changes: 36 additions & 0 deletions .evergreen/functions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,42 @@ functions:
eval $(.evergreen/print-compass-env.sh)
npm run --unsafe-perm --workspace compass-e2e-tests test-ci web


test-web-sandbox-atlas-cloud:
- command: shell.exec
# It can take a very long time for Atlas cluster to get deployed
timeout_secs: 2400
params:
working_dir: src
shell: bash
env:
<<: *compass-env
DEBUG: ${debug|}
COMPASS_E2E_ATLAS_CLOUD_SANDBOX_CLOUD_CONFIG: 'qa'
COMPASS_E2E_ATLAS_CLOUD_SANDBOX_USERNAME: ${e2e_tests_compass_web_atlas_username}
COMPASS_E2E_ATLAS_CLOUD_SANDBOX_PASSWORD: ${e2e_tests_compass_web_atlas_password}
COMPASS_E2E_ATLAS_CLOUD_SANDBOX_DBUSER_USERNAME: ${e2e_tests_compass_web_atlas_db_username}
COMPASS_E2E_ATLAS_CLOUD_SANDBOX_DBUSER_PASSWORD: ${e2e_tests_compass_web_atlas_password}
MCLI_PUBLIC_API_KEY: ${e2e_tests_mcli_public_api_key}
MCLI_PRIVATE_API_KEY: ${e2e_tests_mcli_private_api_key}
MCLI_ORG_ID: ${e2e_tests_mcli_org_id}
MCLI_PROJECT_ID: ${e2e_tests_mcli_project_id}
MCLI_OPS_MANAGER_URL: ${e2e_tests_mcli_ops_manager_url}
script: |
set -e
# Load environment variables
eval $(.evergreen/print-compass-env.sh)
# Create Atlas cluster for test project
source .evergreen/start-atlas-cloud-cluster.sh
# Run the tests
echo "Starting e2e tests..."
# We're only running a special subset of tests as provisioning atlas
# clusters in CI is both pricey and flakey, so we want to limit the
# coverage to reduce those factors (at least for now)
npm run --unsafe-perm --workspace compass-e2e-tests test-ci -- -- web \
--test-atlas-cloud-sandbox \
--test-filter="atlas-cloud/**/*"

test-connectivity:
- command: shell.exec
# Fail the task if it's idle for 10 mins
Expand Down
39 changes: 39 additions & 0 deletions .evergreen/start-atlas-cloud-cluster.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash

# Atlas limits the naming to something like /^[\w\d-]{,23}$/ (and will auto
# truncate if it's too long) so we're very limited in terms of how unique this
# name can be. Hopefully the epoch + part of git hash is enough for these to not
# overlap when tests are running
ATLAS_CLOUD_TEST_CLUSTER_NAME="e2e-$(date +"%s")-$(git rev-parse HEAD)"

function atlascli() {
docker run \
-e MCLI_PUBLIC_API_KEY \
-e MCLI_PRIVATE_API_KEY \
-e MCLI_ORG_ID \
-e MCLI_PROJECT_ID \
-e MCLI_OPS_MANAGER_URL \
mongodb/atlas atlas $@
}

cleanup() {
echo "Scheduling Atlas deployment \`$ATLAS_CLOUD_TEST_CLUSTER_NAME\` for deletion..."
atlascli clusters delete $ATLAS_CLOUD_TEST_CLUSTER_NAME --force
}

trap cleanup EXIT

echo "Creating Atlas deployment \`$ATLAS_CLOUD_TEST_CLUSTER_NAME\` to test against..."
atlascli clusters create $ATLAS_CLOUD_TEST_CLUSTER_NAME \
--provider AWS \
--region US_EAST_1 \
--tier M10

echo "Waiting for the deployment to be provisioned..."
atlascli clusters watch "$ATLAS_CLOUD_TEST_CLUSTER_NAME"

echo "Getting connection string for provisioned cluster..."
ATLAS_CLOUD_TEST_CLUSTER_CONNECTION_STRING_JSON="$(atlascli clusters connectionStrings describe $ATLAS_CLOUD_TEST_CLUSTER_NAME -o json)"

export COMPASS_E2E_ATLAS_CLOUD_SANDBOX_DEFAULT_CONNECTIONS="{\"$ATLAS_CLOUD_TEST_CLUSTER_NAME\": $ATLAS_CLOUD_TEST_CLUSTER_CONNECTION_STRING_JSON}"
echo "Cluster connections: $COMPASS_E2E_ATLAS_CLOUD_SANDBOX_DEFAULT_CONNECTIONS"
3 changes: 2 additions & 1 deletion packages/compass-e2e-tests/helpers/commands/connect-form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import Debug from 'debug';
import {
DEFAULT_CONNECTIONS,
isTestingAtlasCloudExternal,
isTestingAtlasCloudSandbox,
} from '../test-runner-context';
import { getConnectionTitle } from '@mongodb-js/connection-info';
const debug = Debug('compass-e2e-tests');
Expand Down Expand Up @@ -930,7 +931,7 @@ export async function saveConnection(
export async function setupDefaultConnections(browser: CompassBrowser) {
// When running tests against Atlas Cloud, connections can't be added or
// removed from the UI manually, so we skip setup for default connections
if (isTestingAtlasCloudExternal()) {
if (isTestingAtlasCloudExternal() || isTestingAtlasCloudSandbox()) {
return;
}

Expand Down
40 changes: 29 additions & 11 deletions packages/compass-e2e-tests/helpers/commands/connect.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import {
DEFAULT_CONNECTION_NAME_1,
DEFAULT_CONNECTION_NAME_2,
DEFAULT_CONNECTION_STRING_1,
DEFAULT_CONNECTION_NAME_1,
connectionNameFromString,
} from '../compass';
import type { CompassBrowser } from '../compass-browser';
import type { ConnectFormState } from '../connect-form-state';
import * as Selectors from '../selectors';
import Debug from 'debug';
import {
DEFAULT_CONNECTION_NAMES,
isTestingAtlasCloudExternal,
isTestingAtlasCloudSandbox,
} from '../test-runner-context';

const debug = Debug('compass-e2e-tests');

Expand Down Expand Up @@ -35,14 +39,27 @@ type ConnectOptions = ConnectionResultOptions & {
removeConnections?: boolean;
};

/**
* Use this command when you need to add a new connection with a specific
* connection string. Most test files should just be using
* browser.connectToDefaults()
*/
export async function connectWithConnectionString(
browser: CompassBrowser,
connectionString = DEFAULT_CONNECTION_STRING_1,
connectionStringOrName?: string,
options: ConnectOptions = {}
): Promise<void> {
// Use this command when you need to add a new connection with a specific
// connection string. Most test files should just be using
// browser.connectToDefaults()
// When testing Atlas Cloud, we can't really create a new connection, so just
// assume a connection name was passed (with a fallback to a default one) and
// try to use it
if (isTestingAtlasCloudExternal() || isTestingAtlasCloudSandbox()) {
await browser.connectByName(
connectionStringOrName ?? DEFAULT_CONNECTION_NAME_1
);
return;
}

connectionStringOrName ??= DEFAULT_CONNECTION_STRING_1;

// if the modal is still animating away when we're connecting again, things
// are going to get confused
Expand All @@ -52,7 +69,7 @@ export async function connectWithConnectionString(

// if a connection with this name already exists, remove it otherwise we'll
// add a duplicate and things will get complicated fast
const connectionName = connectionNameFromString(connectionString);
const connectionName = connectionNameFromString(connectionStringOrName);
if (await browser.removeConnection(connectionName)) {
debug('Removing existing connection so we do not create a duplicate', {
connectionName,
Expand All @@ -64,7 +81,7 @@ export async function connectWithConnectionString(

await browser.setValueVisible(
Selectors.ConnectionFormStringInput,
connectionString
connectionStringOrName
);

await browser.doConnect(connectionName, options);
Expand Down Expand Up @@ -173,9 +190,10 @@ export async function connectByName(
}

export async function connectToDefaults(browser: CompassBrowser) {
// See setupDefaultConnections() for the details behind the thinking here.
await browser.connectByName(DEFAULT_CONNECTION_NAME_1);
await browser.connectByName(DEFAULT_CONNECTION_NAME_2);
for (const name of DEFAULT_CONNECTION_NAMES) {
// See setupDefaultConnections() for the details behind the thinking here.
await browser.connectByName(name);
}

// We assume that we connected successfully, so just close the success toasts
// early to make sure they aren't in the way of tests. Tests that care about
Expand Down
16 changes: 15 additions & 1 deletion packages/compass-e2e-tests/helpers/commands/create-index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ type CreateIndexOptions = {
wildcardProjection?: string;
customCollation?: string;
sparseIndex?: boolean;
rollingIndex?: boolean;
};

type IndexType = '1' | '-1' | '2dsphere' | 'text';
Expand Down Expand Up @@ -78,7 +79,14 @@ export async function createIndex(
// Select extra options
if (extraOptions) {
await browser.clickVisible(Selectors.IndexToggleOptions);
const { wildcardProjection } = extraOptions;
const { wildcardProjection, rollingIndex, indexName } = extraOptions;

if (indexName) {
await browser.clickVisible(Selectors.indexToggleOption('name'));
await browser
.$(Selectors.indexOptionInput('name', 'text'))
.setValue(indexName);
}

if (wildcardProjection) {
await browser.clickVisible(
Expand All @@ -91,6 +99,12 @@ export async function createIndex(
wildcardProjection
);
}

if (rollingIndex) {
await browser.clickVisible(
Selectors.indexToggleOption('buildInRollingProcess')
);
}
}

if (screenshotName) {
Expand Down
Loading
Loading