Skip to content

Commit 2d730ac

Browse files
authored
test: check server warnings after each e2e test COMPASS-10017 (#7845)
1 parent c4931e1 commit 2d730ac

29 files changed

Lines changed: 686 additions & 375 deletions

packages/compass-e2e-tests/helpers/insert-data.ts renamed to packages/compass-e2e-tests/helpers/mongo-clients.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { MongoClient } from 'mongodb';
22
import type { Db, MongoServerError } from 'mongodb';
33
import { getDefaultConnectionStrings } from './test-runner-context';
44
import { redactConnectionString } from 'mongodb-connection-string-url';
5+
import { noServerWarningsCheckpoint } from './test-runner-global-fixtures';
56

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

90+
export const afterEach = () => {
91+
// Check for unexpected server warnings after each test
92+
noServerWarningsCheckpoint();
93+
};
94+
8995
export const mochaRootHooks: Mocha.RootHookObject = {
9096
beforeAll,
9197
beforeEach,
98+
afterEach,
9299
afterAll,
93100
};
94101

packages/compass-e2e-tests/helpers/test-runner-global-fixtures.ts

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@ import {
1414
} from './test-runner-context';
1515
import { E2E_WORKSPACE_PATH, LOG_PATH } from './test-runner-paths';
1616
import Debug from 'debug';
17-
import { startTestServer } from '@mongodb-js/compass-test-server';
17+
import {
18+
startTestServer,
19+
ServerLogsChecker,
20+
type LogEntry,
21+
type WarningFilter,
22+
} from '@mongodb-js/compass-test-server';
1823
import { MongoClient } from 'mongodb';
1924
import { isEnterprise } from 'mongodb-build-info';
2025
import {
@@ -23,6 +28,7 @@ import {
2328
rebuildNativeModules,
2429
removeUserDataDir,
2530
screenshotPathName,
31+
serverSatisfies,
2632
startBrowser,
2733
} from './compass';
2834
import { getConnectionTitle } from '@mongodb-js/connection-info';
@@ -52,6 +58,28 @@ const debug = Debug('compass-e2e-tests:mocha-global-fixtures');
5258

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

61+
export const serverLogsCheckers: ServerLogsChecker[] = [];
62+
63+
export function noServerWarningsCheckpoint() {
64+
for (const checker of serverLogsCheckers) {
65+
checker.noServerWarningsCheckpoint();
66+
}
67+
}
68+
69+
export function allowServerWarnings(...filters: WarningFilter[]): () => void {
70+
const unsubscribeFns: (() => void)[] = [];
71+
for (const filter of filters) {
72+
for (const checker of serverLogsCheckers) {
73+
unsubscribeFns.push(checker.allowWarning(filter));
74+
}
75+
}
76+
return () => {
77+
for (const fn of unsubscribeFns) {
78+
fn();
79+
}
80+
};
81+
}
82+
5583
async function createAtlasCloudResources() {
5684
assertTestingAtlasCloud(context);
5785

@@ -265,6 +293,7 @@ export async function mochaGlobalSetup(this: Mocha.Runner) {
265293
getConnectionTitle(connectionInfo)
266294
);
267295
const server = await startTestServer(connectionInfo.testServer);
296+
serverLogsCheckers.push(new ServerLogsChecker(server));
268297
cleanupFns.push(() => {
269298
debug(
270299
'Stopping server for connection %s',
@@ -315,6 +344,17 @@ export async function mochaGlobalSetup(this: Mocha.Runner) {
315344

316345
debug('Getting mongodb server info');
317346
await updateMongoDBServerInfo();
347+
if (serverSatisfies('< 8.2')) {
348+
for (const checker of serverLogsCheckers) {
349+
checker.allowWarning((l: LogEntry) => {
350+
// "Aggregate command executor error" with CommandNotSupported
351+
// This happens when Compass probes for search index support on older non-Atlas servers
352+
return (
353+
l.id === 23799 && l.attr?.error?.codeName === 'CommandNotSupported'
354+
);
355+
});
356+
}
357+
}
318358

319359
throwIfAborted();
320360

@@ -365,6 +405,13 @@ export async function mochaGlobalSetup(this: Mocha.Runner) {
365405

366406
export async function mochaGlobalTeardown() {
367407
debug('Cleaning up after the tests ...');
408+
409+
// Close server log checkers
410+
for (const checker of serverLogsCheckers) {
411+
checker.close();
412+
}
413+
serverLogsCheckers.length = 0;
414+
368415
await Promise.allSettled(
369416
cleanupFns.map((fn) => {
370417
// We get a mix of sync and non-sync functions here. Awaiting even the

packages/compass-e2e-tests/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
mochaGlobalSetup,
1111
mochaGlobalTeardown,
1212
} from './helpers/test-runner-global-fixtures';
13-
import { mochaRootHooks } from './helpers/insert-data';
13+
import { mochaRootHooks } from './helpers/mongo-clients';
1414
// @ts-expect-error no types for this package
1515
import logRunning from 'why-is-node-running';
1616

packages/compass-e2e-tests/tests/atlas-cloud/collection-ai-query.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
} from '../../helpers/compass';
1010
import type { Compass } from '../../helpers/compass';
1111
import * as Selectors from '../../helpers/selectors';
12-
import { createNumbersCollection } from '../../helpers/insert-data';
12+
import { createNumbersCollection } from '../../helpers/mongo-clients';
1313
import { isTestingAtlasCloud } from '../../helpers/test-runner-context';
1414
import { switchPipelineMode } from '../../helpers/commands/switch-pipeline-mode';
1515

packages/compass-e2e-tests/tests/atlas-cloud/global-writes.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
Selectors,
88
} from '../../helpers/compass';
99
import type { CompassBrowser } from '../../helpers/compass-browser';
10-
import { createGeospatialCollection } from '../../helpers/insert-data';
10+
import { createGeospatialCollection } from '../../helpers/mongo-clients';
1111
import {
1212
getDefaultConnectionNames,
1313
isTestingAtlasCloud,

packages/compass-e2e-tests/tests/atlas-cloud/rolling-indexes.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
Selectors,
77
} from '../../helpers/compass';
88
import type { CompassBrowser } from '../../helpers/compass-browser';
9-
import { createNumbersCollection } from '../../helpers/insert-data';
9+
import { createNumbersCollection } from '../../helpers/mongo-clients';
1010
import {
1111
getDefaultConnectionNames,
1212
isTestingAtlasCloud,

packages/compass-e2e-tests/tests/collection-aggregations-tab.test.ts

Lines changed: 74 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@ import * as Selectors from '../helpers/selectors';
1515
import {
1616
createNestedDocumentsCollection,
1717
createNumbersCollection,
18-
} from '../helpers/insert-data';
18+
} from '../helpers/mongo-clients';
1919
import { saveAggregationPipeline } from '../helpers/commands/save-aggregation-pipeline';
2020
import type { ChainablePromiseElement } from 'webdriverio';
2121
import { switchPipelineMode } from '../helpers/commands/switch-pipeline-mode';
2222
import { isTestingWeb } from '../helpers/test-runner-context';
23+
import { allowServerWarnings } from '../helpers/test-runner-global-fixtures';
24+
import type { LogEntry } from '@mongodb-js/compass-test-server';
2325

2426
const { expect } = chai;
2527

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

473475
describe('maxTimeMS', function () {
474476
let maxTimeMSBefore: any;
477+
let unsubscribeAllowWarnings: () => void;
478+
479+
before(function () {
480+
unsubscribeAllowWarnings = allowServerWarnings(
481+
8996503, // Allow "$function is deprecated" warning
482+
(l: LogEntry) => {
483+
// 23798 = "Plan executor error", 23799 = "Aggregate command executor error"
484+
return (
485+
l.id === 23799 &&
486+
['MaxTimeMSExpired', 'Interrupted'].includes(
487+
l.attr?.error?.codeName
488+
)
489+
);
490+
}
491+
);
492+
});
493+
494+
after(function () {
495+
unsubscribeAllowWarnings();
496+
});
475497

476498
beforeEach(async function () {
477499
maxTimeMSBefore = await browser.getFeature('maxTimeMS');
@@ -653,6 +675,21 @@ describe('Collection aggregations tab', function () {
653675
});
654676
});
655677

678+
let unsubscribeAllowWarnings: () => void;
679+
680+
before(function () {
681+
unsubscribeAllowWarnings = allowServerWarnings((l: LogEntry) => {
682+
return (
683+
l.id === 23799 &&
684+
['DocumentValidationFailure'].includes(l.attr?.error?.codeName)
685+
);
686+
});
687+
});
688+
689+
after(function () {
690+
unsubscribeAllowWarnings();
691+
});
692+
656693
it('Shows error info when inserting', async function () {
657694
await browser.selectStageOperator(0, '$out');
658695
await browser.setCodemirrorEditorValue(
@@ -951,31 +988,46 @@ describe('Collection aggregations tab', function () {
951988
});
952989

953990
it('supports cancelling long-running aggregations', async function () {
954-
const slowQuery = `{
955-
sleep: {
956-
$function: {
957-
body: function () {
958-
return sleep(10000) || true;
991+
const unsubscribeAllowWarnings = allowServerWarnings(
992+
8996503, // Allow "$function is deprecated" warning
993+
(l: LogEntry) => {
994+
return (
995+
l.id === 23799 && ['Interrupted'].includes(l.attr?.error?.codeName)
996+
);
997+
}
998+
);
999+
try {
1000+
const slowQuery = `{
1001+
sleep: {
1002+
$function: {
1003+
body: function () {
1004+
return sleep(10000) || true;
1005+
},
1006+
args: [],
1007+
lang: "js",
9591008
},
960-
args: [],
961-
lang: "js",
9621009
},
963-
},
964-
}`;
1010+
}`;
9651011

966-
// Set first stage to a very slow $addFields
967-
await browser.selectStageOperator(0, '$addFields');
968-
await browser.setCodemirrorEditorValue(Selectors.stageEditor(0), slowQuery);
969-
970-
// Run and wait for results
971-
await goToRunAggregation(browser);
1012+
// Set first stage to a very slow $addFields
1013+
await browser.selectStageOperator(0, '$addFields');
1014+
await browser.setCodemirrorEditorValue(
1015+
Selectors.stageEditor(0),
1016+
slowQuery
1017+
);
9721018

973-
// Cancel aggregation run
974-
await browser.clickVisible(Selectors.AggregationResultsCancelButton);
975-
// Wait for the empty results banner (this is our indicator that we didn't
976-
// load anything and dismissed "Loading" banner)
977-
const emptyResultsBanner = browser.$(Selectors.AggregationEmptyResults);
978-
await emptyResultsBanner.waitForDisplayed();
1019+
// Run and wait for results
1020+
await goToRunAggregation(browser);
1021+
1022+
// Cancel aggregation run
1023+
await browser.clickVisible(Selectors.AggregationResultsCancelButton);
1024+
// Wait for the empty results banner (this is our indicator that we didn't
1025+
// load anything and dismissed "Loading" banner)
1026+
const emptyResultsBanner = browser.$(Selectors.AggregationEmptyResults);
1027+
await emptyResultsBanner.waitForDisplayed();
1028+
} finally {
1029+
unsubscribeAllowWarnings();
1030+
}
9791031
});
9801032

9811033
it('handles errors in aggregations', async function () {

packages/compass-e2e-tests/tests/collection-ai-query.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
} from '../helpers/compass';
1111
import type { Compass } from '../helpers/compass';
1212
import * as Selectors from '../helpers/selectors';
13-
import { createNumbersCollection } from '../helpers/insert-data';
13+
import { createNumbersCollection } from '../helpers/mongo-clients';
1414
import { startMockAssistantServer } from '../helpers/assistant-service';
1515

1616
async function setup(

packages/compass-e2e-tests/tests/collection-bulk-delete.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
} from '../helpers/compass';
1414
import type { Compass } from '../helpers/compass';
1515
import * as Selectors from '../helpers/selectors';
16-
import { createNumbersCollection } from '../helpers/insert-data';
16+
import { createNumbersCollection } from '../helpers/mongo-clients';
1717
import { context } from '../helpers/test-runner-context';
1818

1919
describe('Bulk Delete', function () {

packages/compass-e2e-tests/tests/collection-bulk-update.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
} from '../helpers/compass';
1515
import type { Compass } from '../helpers/compass';
1616
import * as Selectors from '../helpers/selectors';
17-
import { createNumbersCollection } from '../helpers/insert-data';
17+
import { createNumbersCollection } from '../helpers/mongo-clients';
1818

1919
describe('Bulk Update', () => {
2020
let compass: Compass;

0 commit comments

Comments
 (0)