Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { MongoClient } from 'mongodb';
import type { Db, MongoServerError } from 'mongodb';
import { getDefaultConnectionStrings } from './test-runner-context';
import { redactConnectionString } from 'mongodb-connection-string-url';
import { noServerWarningsCheckpoint } from './test-runner-global-fixtures';

// This is a list of all the known database names that get created by tests so
// that we can know what to drop when we clean up before every test. If a new
Expand Down Expand Up @@ -86,9 +87,15 @@ export const beforeEach = async () => {
await Promise.all(promises);
};

export const afterEach = () => {
// Check for unexpected server warnings after each test
noServerWarningsCheckpoint();
};

export const mochaRootHooks: Mocha.RootHookObject = {
beforeAll,
beforeEach,
afterEach,
afterAll,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ import {
} from './test-runner-context';
import { E2E_WORKSPACE_PATH, LOG_PATH } from './test-runner-paths';
import Debug from 'debug';
import { startTestServer } from '@mongodb-js/compass-test-server';
import {
startTestServer,
ServerLogsChecker,
type LogEntry,
} from '@mongodb-js/compass-test-server';
import { MongoClient } from 'mongodb';
import { isEnterprise } from 'mongodb-build-info';
import {
Expand All @@ -23,6 +27,7 @@ import {
rebuildNativeModules,
removeUserDataDir,
screenshotPathName,
serverSatisfies,
startBrowser,
} from './compass';
import { getConnectionTitle } from '@mongodb-js/connection-info';
Expand Down Expand Up @@ -51,6 +56,30 @@ const debug = Debug('compass-e2e-tests:mocha-global-fixtures');

const cleanupFns: (() => Promise<void> | void)[] = [];

export const serverLogsCheckers: ServerLogsChecker[] = [];

export function noServerWarningsCheckpoint() {
for (const checker of serverLogsCheckers) {
checker.noServerWarningsCheckpoint();
}
}

type WarningFilter = number | ((entry: LogEntry) => boolean);

export function allowServerWarnings(...filters: WarningFilter[]): () => void {
const unsubscribeFns: (() => void)[] = [];
for (const filter of filters) {
for (const checker of serverLogsCheckers) {
unsubscribeFns.push(checker.allowWarning(filter));
}
}
return () => {
for (const fn of unsubscribeFns) {
fn();
}
};
}

async function createAtlasCloudResources() {
assertTestingAtlasCloud(context);

Expand Down Expand Up @@ -264,6 +293,7 @@ export async function mochaGlobalSetup(this: Mocha.Runner) {
getConnectionTitle(connectionInfo)
);
const server = await startTestServer(connectionInfo.testServer);
serverLogsCheckers.push(new ServerLogsChecker(server));
cleanupFns.push(() => {
debug(
'Stopping server for connection %s',
Expand Down Expand Up @@ -314,6 +344,17 @@ export async function mochaGlobalSetup(this: Mocha.Runner) {

debug('Getting mongodb server info');
await updateMongoDBServerInfo();
if (serverSatisfies('< 8.0', true)) {
for (const checker of serverLogsCheckers) {
checker.allowWarning((l: LogEntry) => {
// "Aggregate command executor error" with CommandNotSupported
// This happens when Compass probes for search index support on older non-Atlas servers
return (
l.id === 23799 && l.attr?.error?.codeName === 'CommandNotSupported'
);
});
}
}

throwIfAborted();

Expand Down Expand Up @@ -364,6 +405,13 @@ export async function mochaGlobalSetup(this: Mocha.Runner) {

export async function mochaGlobalTeardown() {
debug('Cleaning up after the tests ...');

// Close server log checkers
for (const checker of serverLogsCheckers) {
checker.close();
}
serverLogsCheckers.length = 0;

await Promise.allSettled(
cleanupFns.map((fn) => {
// We get a mix of sync and non-sync functions here. Awaiting even the
Expand Down
2 changes: 1 addition & 1 deletion packages/compass-e2e-tests/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
mochaGlobalSetup,
mochaGlobalTeardown,
} from './helpers/test-runner-global-fixtures';
import { mochaRootHooks } from './helpers/insert-data';
import { mochaRootHooks } from './helpers/mongo-clients';
// @ts-expect-error no types for this package
import logRunning from 'why-is-node-running';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from '../../helpers/compass';
import type { Compass } from '../../helpers/compass';
import * as Selectors from '../../helpers/selectors';
import { createNumbersCollection } from '../../helpers/insert-data';
import { createNumbersCollection } from '../../helpers/mongo-clients';
import { isTestingAtlasCloud } from '../../helpers/test-runner-context';
import { switchPipelineMode } from '../../helpers/commands/switch-pipeline-mode';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
Selectors,
} from '../../helpers/compass';
import type { CompassBrowser } from '../../helpers/compass-browser';
import { createGeospatialCollection } from '../../helpers/insert-data';
import { createGeospatialCollection } from '../../helpers/mongo-clients';
import {
getDefaultConnectionNames,
isTestingAtlasCloud,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
Selectors,
} from '../../helpers/compass';
import type { CompassBrowser } from '../../helpers/compass-browser';
import { createNumbersCollection } from '../../helpers/insert-data';
import { createNumbersCollection } from '../../helpers/mongo-clients';
import {
getDefaultConnectionNames,
isTestingAtlasCloud,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ import * as Selectors from '../helpers/selectors';
import {
createNestedDocumentsCollection,
createNumbersCollection,
} from '../helpers/insert-data';
} from '../helpers/mongo-clients';
import { saveAggregationPipeline } from '../helpers/commands/save-aggregation-pipeline';
import type { ChainablePromiseElement } from 'webdriverio';
import { switchPipelineMode } from '../helpers/commands/switch-pipeline-mode';
import { isTestingWeb } from '../helpers/test-runner-context';
import { allowServerWarnings } from '../helpers/test-runner-global-fixtures';
import type { LogEntry } from '@mongodb-js/compass-test-server';

const { expect } = chai;

Expand Down Expand Up @@ -472,6 +474,26 @@ describe('Collection aggregations tab', function () {

describe('maxTimeMS', function () {
let maxTimeMSBefore: any;
let unsubscribeAllowWarnings: () => void;

before(function () {
unsubscribeAllowWarnings = allowServerWarnings(
8996503, // Allow "$function is deprecated" warning
(l: LogEntry) => {
// 23798 = "Plan executor error", 23799 = "Aggregate command executor error"
return (
l.id === 23799 &&
['MaxTimeMSExpired', 'Interrupted'].includes(
l.attr?.error?.codeName
)
);
}
);
});

after(function () {
unsubscribeAllowWarnings();
});

beforeEach(async function () {
maxTimeMSBefore = await browser.getFeature('maxTimeMS');
Expand Down Expand Up @@ -653,6 +675,21 @@ describe('Collection aggregations tab', function () {
});
});

let unsubscribeAllowWarnings: () => void;

before(function () {
unsubscribeAllowWarnings = allowServerWarnings((l: LogEntry) => {
return (
l.id === 23799 &&
['DocumentValidationFailure'].includes(l.attr?.error?.codeName)
);
});
});

after(function () {
unsubscribeAllowWarnings();
});

it('Shows error info when inserting', async function () {
await browser.selectStageOperator(0, '$out');
await browser.setCodemirrorEditorValue(
Expand Down Expand Up @@ -951,6 +988,14 @@ describe('Collection aggregations tab', function () {
});

it('supports cancelling long-running aggregations', async function () {
const unsubscribeAllowWarnings = allowServerWarnings(
8996503, // Allow "$function is deprecated" warning
(l: LogEntry) => {
return (
l.id === 23799 && ['Interrupted'].includes(l.attr?.error?.codeName)
);
}
);
const slowQuery = `{
sleep: {
$function: {
Expand All @@ -976,6 +1021,8 @@ describe('Collection aggregations tab', function () {
// load anything and dismissed "Loading" banner)
const emptyResultsBanner = browser.$(Selectors.AggregationEmptyResults);
await emptyResultsBanner.waitForDisplayed();

unsubscribeAllowWarnings();
});

it('handles errors in aggregations', async function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
} from '../helpers/compass';
import type { Compass } from '../helpers/compass';
import * as Selectors from '../helpers/selectors';
import { createNumbersCollection } from '../helpers/insert-data';
import { createNumbersCollection } from '../helpers/mongo-clients';
import { startMockAssistantServer } from '../helpers/assistant-service';

async function setup(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
} from '../helpers/compass';
import type { Compass } from '../helpers/compass';
import * as Selectors from '../helpers/selectors';
import { createNumbersCollection } from '../helpers/insert-data';
import { createNumbersCollection } from '../helpers/mongo-clients';
import { context } from '../helpers/test-runner-context';

describe('Bulk Delete', function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
} from '../helpers/compass';
import type { Compass } from '../helpers/compass';
import * as Selectors from '../helpers/selectors';
import { createNumbersCollection } from '../helpers/insert-data';
import { createNumbersCollection } from '../helpers/mongo-clients';

describe('Bulk Update', () => {
let compass: Compass;
Expand Down
Loading
Loading