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-tests): add TestShell#eventually and refactor TestShell#executeLine and TestShell#waitForPrompt #2171

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion packages/e2e-tests/test/e2e-analytics.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ describe('e2e Analytics Node', function () {
);
expect(helloIsWritablePrimary).to.contain('true');
},
{ timeout: 20_000 }
{ timeout: 40_000 }
);
});

Expand Down
13 changes: 6 additions & 7 deletions packages/e2e-tests/test/e2e-auth.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { expect } from 'chai';
import type { Db, Document, MongoClientOptions } from 'mongodb';
import { MongoClient } from 'mongodb';
import { eventually } from '../../../testing/eventually';
import type { TestShell } from './test-shell';
import {
skipIfApiStrict,
Expand Down Expand Up @@ -298,7 +297,7 @@ describe('Auth e2e', function () {
it('dropAllUsers', async function () {
await shell.executeLine(`use ${dbName}`);
shell.writeInputLine('db.dropAllUsers()');
await eventually(() => {
await shell.eventually(() => {
try {
shell.assertContainsOutput('{ n: 2, ok: 1 }');
} catch {
Expand Down Expand Up @@ -508,7 +507,7 @@ describe('Auth e2e', function () {
it('dropAllRoles', async function () {
await shell.executeLine(`use ${dbName}`);
shell.writeInputLine('db.dropAllRoles()');
await eventually(() => {
await shell.eventually(() => {
try {
shell.assertContainsOutput('{ n: 2, ok: 1 }');
} catch {
Expand Down Expand Up @@ -737,7 +736,7 @@ describe('Auth e2e', function () {
it('throws if pwd is wrong', async function () {
await shell.executeLine(`use ${dbName}`);
shell.writeInputLine('db.auth("anna", "pwd2")');
await eventually(
await shell.eventually(
() => {
shell.assertContainsError('Authentication failed');
},
Expand All @@ -752,7 +751,7 @@ describe('Auth e2e', function () {
shell.writeInputLine(
'db.auth({ user: "anna", pwd: "pwd2", mechanism: "not a mechanism"})'
);
await eventually(
await shell.eventually(
() => {
expect(shell.output).to.match(
/MongoParseError: authMechanism one of .+, got not a mechanism/
Expand Down Expand Up @@ -1067,7 +1066,7 @@ describe('Auth e2e', function () {
'SCRAM-SHA-1',
],
});
await eventually(() => {
await shell.eventually(() => {
expect(shell.output).to.match(
/MongoServerError: Authentication failed|Unable to use SCRAM-SHA-1/
);
Expand All @@ -1088,7 +1087,7 @@ describe('Auth e2e', function () {
'SCRAM-SHA-256',
],
});
await eventually(() => {
await shell.eventually(() => {
expect(shell.output).to.match(
/MongoServerError: Authentication failed|Unable to use SCRAM-SHA-256/
);
Expand Down
21 changes: 13 additions & 8 deletions packages/e2e-tests/test/e2e-direct.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,17 @@ describe('e2e direct connection', function () {
`rs.initiate(${JSON.stringify(replSetConfig)})`
);
shell.assertContainsOutput('ok: 1');
await eventually(async () => {
await shell.executeLine('db.isMaster()');
shell.assertContainsOutput('ismaster: true');
shell.assertContainsOutput(`me: '${await rs0.hostport()}'`);
shell.assertContainsOutput(`setName: '${replSetId}'`);
});
await eventually(
async () => {
const output = await shell.executeLine('db.isMaster()');
expect(output).contains('ismaster: true');
expect(output).contains(`me: '${await rs0.hostport()}'`);
expect(output).contains(`setName: '${replSetId}'`);
},
{
timeout: 20_000,
}
);

await shell.executeLine('use admin');
await shell.executeLine(
Expand Down Expand Up @@ -204,7 +209,7 @@ describe('e2e direct connection', function () {
await shell.waitForPrompt();
shell.writeInput('db.testc');
await tabtab(shell);
await eventually(() => {
await shell.eventually(() => {
shell.assertContainsOutput('db.testcollection');
});
});
Expand Down Expand Up @@ -370,7 +375,7 @@ describe('e2e direct connection', function () {
await shell.waitForPrompt();
shell.writeInput('db.testc');
await tabtab(shell);
await eventually(() => {
await shell.eventually(() => {
shell.assertContainsOutput('db.testcollection');
});
});
Expand Down
21 changes: 10 additions & 11 deletions packages/e2e-tests/test/e2e-editor.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { expect } from 'chai';
import path from 'path';
import { promises as fs } from 'fs';
import { eventually } from '../../../testing/eventually';
import { TestShell } from './test-shell';
import { ensureTestShellAfterHook } from './test-shell-context';
import {
Expand Down Expand Up @@ -73,7 +72,7 @@ describe('external editor e2e', function () {

expect(result).to.include('"editor" has been changed');
shell.writeInputLine(shellOriginalInput);
await eventually(() => {
await shell.eventually(() => {
shell.assertContainsOutput(shellModifiedInput);
});
});
Expand All @@ -97,7 +96,7 @@ describe('external editor e2e', function () {

expect(result).to.include('"editor" has been changed');
shell.writeInputLine(shellOriginalInput);
await eventually(() => {
await shell.eventually(() => {
shell.assertContainsOutput(shellModifiedInput);
});
});
Expand All @@ -118,7 +117,7 @@ describe('external editor e2e', function () {

expect(result).to.include('"editor" has been changed');
shell.writeInputLine(shellOriginalInput);
await eventually(() => {
await shell.eventually(() => {
shell.assertContainsOutput(shellModifiedInput);
});
});
Expand All @@ -145,7 +144,7 @@ describe('external editor e2e', function () {

expect(result).to.include('"editor" has been changed');
shell.writeInputLine(shellOriginalInput);
await eventually(() => {
await shell.eventually(() => {
shell.assertContainsOutput(shellModifiedInput);
});
});
Expand All @@ -163,7 +162,7 @@ describe('external editor e2e', function () {

expect(result).to.include('"editor" has been changed');
shell.writeInputLine(shellOriginalInput);
await eventually(() => {
await shell.eventually(() => {
shell.assertContainsError('failed with an exit code 1');
});
});
Expand All @@ -182,7 +181,7 @@ describe('external editor e2e', function () {

expect(result).to.include('"editor" has been changed');
shell.writeInputLine('edit');
await eventually(() => {
await shell.eventually(() => {
shell.assertContainsOutput(output);
});
});
Expand Down Expand Up @@ -216,7 +215,7 @@ describe('external editor e2e', function () {
"const name = 'I want to test a sequence of writeInputLine'"
);
shell.writeInputLine('edit name');
await eventually(() => {
await shell.eventually(() => {
shell.assertContainsOutput(shellModifiedInput);
});
});
Expand Down Expand Up @@ -254,7 +253,7 @@ describe('external editor e2e', function () {

expect(result).to.include('"editor" has been changed');
shell.writeInputLine(shellOriginalInput);
await eventually(() => {
await shell.eventually(() => {
shell.assertContainsOutput(shellModifiedInput);
});
});
Expand All @@ -279,7 +278,7 @@ describe('external editor e2e', function () {

expect(result).to.include('"editor" has been changed');
shell.writeInputLine(shellOriginalInput);
await eventually(() => {
await shell.eventually(() => {
shell.assertContainsOutput(shellModifiedInput);
});
});
Expand All @@ -303,7 +302,7 @@ describe('external editor e2e', function () {

expect(result).to.include('"editor" has been changed');
shell.writeInputLine(shellOriginalInput);
await eventually(() => {
await shell.eventually(() => {
shell.assertContainsOutput(shellModifiedInput);
});
});
Expand Down
4 changes: 2 additions & 2 deletions packages/e2e-tests/test/e2e-snippet.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe('snippet integration tests', function () {

it('allows managing snippets', async function () {
shell.writeInputLine('snippet install analyze-schema');
await eventually(
await shell.eventually(
() => {
shell.assertContainsOutput(
'Installed new snippets analyze-schema. Do you want to load them now?'
Expand Down Expand Up @@ -77,7 +77,7 @@ describe('snippet integration tests', function () {
return this.skip(); // https://jira.mongodb.org/browse/MONGOSH-746
}
shell.writeInput('snippet insta\t');
await eventually(() => {
await shell.eventually(() => {
shell.assertContainsOutput('snippet install');
});
});
Expand Down
Loading
Loading