Skip to content

Commit

Permalink
chore(ci): Setup Search Index e2e tests with local atlas COMPASS-7255 (
Browse files Browse the repository at this point in the history
…#5954)

* chore(ci): Setup Search Index e2e tests with local atlas COMPASS-7255

* unskip search index tests

* don't throw on exit

* skip when no docker, setup on packaged app

* only run for e2e-coverage

* fix regular indexes test

* fix connection name

---------

Co-authored-by: Basit Chonka <[email protected]>
Co-authored-by: Basit <[email protected]>
  • Loading branch information
3 people authored Aug 6, 2024
1 parent 0ff925d commit a6a5440
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 16 deletions.
4 changes: 4 additions & 0 deletions .evergreen/functions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -589,11 +589,15 @@ functions:
MONGODB_RUNNER_VERSION: ${mongodb_version|}
E2E_TEST_GROUPS: ${e2e_test_groups}
E2E_TEST_GROUP: ${e2e_test_group}
ATLAS_LOCAL_VERSION: latest
script: |
set -e
# Load environment variables
eval $(.evergreen/print-compass-env.sh)
# Start atlas local to test Atlas Search
source .evergreen/start-atlas-local.sh
echo "Running E2E tests while collecting coverage..."
npm run --unsafe-perm --workspace compass-e2e-tests test-ci
Expand Down
72 changes: 72 additions & 0 deletions .evergreen/start-atlas-local.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#!/bin/bash

# Check if ATLAS_LOCAL_VERSION is set
if [ -z "$ATLAS_LOCAL_VERSION" ]; then
echo "ATLAS_LOCAL_VERSION is not set. Skipping script."
return
fi

# Container name
CONTAINER_NAME=compass-e2e-tests-atlas-local

docker rm -f $CONTAINER_NAME || true

cleanup() {
echo "Stopping and removing container..."
docker stop $CONTAINER_NAME || true
docker rm -f $CONTAINER_NAME || true
}

trap cleanup EXIT

# Image name with version
IMAGE_NAME="mongodb/mongodb-atlas-local:$ATLAS_LOCAL_VERSION"
echo docker run --rm --name $CONTAINER_NAME -d -e DO_NOT_TRACK=1 -P "$IMAGE_NAME"

# Start the Docker container
docker run --rm --name $CONTAINER_NAME -d -e DO_NOT_TRACK=1 -P "$IMAGE_NAME"

echo "Waiting for container to become healthy..."

STATUS=""
CONSECUTIVE_FAILED_ATTEMPTS=0
MAX_CONSECUTIVE_FAILED_ATTEMPTS=20

while true; do
INSPECT_OUTPUT=$(docker inspect --format='{{.State.Health.Status}}' $CONTAINER_NAME 2>&1)
if [[ $? -ne 0 ]]; then
echo "Inspect Failed: ${INSPECT_OUTPUT}"
STATUS="failed"
else
STATUS="$INSPECT_OUTPUT"
fi

echo "Status: $STATUS"

if [[ "$STATUS" != "starting" && "$STATUS" != "failed" ]]; then
break
fi

if [[ "$STATUS" == "failed" ]]; then
CONSECUTIVE_FAILED_ATTEMPTS=$((CONSECUTIVE_FAILED_ATTEMPTS + 1))
else
CONSECUTIVE_FAILED_ATTEMPTS=0
fi

if [[ $CONSECUTIVE_FAILED_ATTEMPTS -ge $MAX_CONSECUTIVE_FAILED_ATTEMPTS ]]; then
echo "Maximum number of consecutive failed attempts reached. Exiting."
exit 1
fi

sleep 2
done

if [[ "$STATUS" != "healthy" ]]; then
echo "Atlas Local is not healthy, exiting."
exit 1
fi

EXPOSED_PORT=$(docker inspect --format='{{ (index (index .NetworkSettings.Ports "27017/tcp") 0).HostPort }}' $CONTAINER_NAME)

export ATLAS_LOCAL_URL="mongodb://127.0.0.1:$EXPOSED_PORT/test?directConnection=true"
echo "ATLAS_LOCAL_URL set to $ATLAS_LOCAL_URL"
34 changes: 18 additions & 16 deletions packages/compass-e2e-tests/tests/search-indexes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import {
init,
cleanup,
screenshotIfFailed,
MONGODB_TEST_SERVER_PORT,
DEFAULT_CONNECTION_STRING,
Selectors,
serverSatisfies,
skipForWeb,
TEST_COMPASS_WEB,
DEFAULT_CONNECTION_NAME,
connectionNameFromString,
} from '../helpers/compass';
import type { Compass } from '../helpers/compass';
import { expect } from 'chai';
Expand All @@ -22,7 +22,7 @@ type Connection = {
const connectionsWithNoSearchSupport: Connection[] = [
{
name: 'Local Connection',
connectionString: `mongodb://localhost:${MONGODB_TEST_SERVER_PORT}/test`,
connectionString: DEFAULT_CONNECTION_STRING,
},
{
name: 'Atlas Free Cluster',
Expand All @@ -31,10 +31,9 @@ const connectionsWithNoSearchSupport: Connection[] = [
];
const connectionsWithSearchSupport: Connection[] = [
{
name: 'Atlas Dedicated Cluster',
connectionString: process.env.E2E_TESTS_ATLAS_CS_WITH_SEARCH,
name: 'Atlas Local Dev',
connectionString: process.env.ATLAS_LOCAL_URL,
},
// todo: atlas local dev
];

const INDEX_DEFINITION = JSON.stringify({
Expand Down Expand Up @@ -136,13 +135,15 @@ async function verifyIndexDetails(
await browser.hover(indexRowSelector);
await browser.clickVisible(Selectors.searchIndexExpandButton(indexName));

const text = await browser
.$(Selectors.searchIndexDetails(indexName))
.getText();
expect(text.toLowerCase()).to.equal(details.toLowerCase());
await browser.waitUntil(async () => {
const text = await browser
.$(Selectors.searchIndexDetails(indexName))
.getText();
return text.toLowerCase() === details.toLowerCase();
});
}

describe.skip('Search Indexes', function () {
describe('Search Indexes', function () {
let compass: Compass;
let browser: CompassBrowser;
let mongoClient: MongoClient;
Expand Down Expand Up @@ -193,7 +194,7 @@ describe.skip('Search Indexes', function () {

await browser.connectWithConnectionString(currentConnectionString);
await browser.navigateToCollectionTab(
DEFAULT_CONNECTION_NAME,
connectionNameFromString(currentConnectionString),
DB_NAME,
collectionName,
'Indexes'
Expand Down Expand Up @@ -269,7 +270,6 @@ describe.skip('Search Indexes', function () {
Selectors.indexesSegmentedTab('search-indexes')
);
await createSearchIndex(browser, indexName, INDEX_DEFINITION);
await browser.waitForAnimations(Selectors.SearchIndexList);

// Verify it was added.
// As we added index definition with no fields and only
Expand All @@ -286,7 +286,6 @@ describe.skip('Search Indexes', function () {
Selectors.indexesSegmentedTab('search-indexes')
);
await createSearchIndex(browser, indexName, INDEX_DEFINITION);
await browser.waitForAnimations(Selectors.SearchIndexList);

// Verify it was added.
// As we added index definition with no fields and only
Expand All @@ -307,7 +306,11 @@ describe.skip('Search Indexes', function () {
// Verify its updating/updated.
// As we set the new definition to have no dynamic mappings
// with no fields, the index details should have '[empty]' value.
await verifyIndexDetails(browser, indexName, '[empty]');
await verifyIndexDetails(
browser,
indexName,
'No mappings in the index definition.'
);
});

it('runs a search aggregation with index name', async function () {
Expand All @@ -316,7 +319,6 @@ describe.skip('Search Indexes', function () {
Selectors.indexesSegmentedTab('search-indexes')
);
await createSearchIndex(browser, indexName, INDEX_DEFINITION);
await browser.waitForAnimations(Selectors.SearchIndexList);

const indexRowSelector = Selectors.searchIndexRow(indexName);
const indexRow = await browser.$(indexRowSelector);
Expand Down

0 comments on commit a6a5440

Please sign in to comment.