Skip to content

Commit

Permalink
move unit to integration test to get correct maxWireVersion for opMsg
Browse files Browse the repository at this point in the history
  • Loading branch information
aditi-khare-mongoDB committed Sep 19, 2024
1 parent bcf1244 commit 3787250
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 51 deletions.
46 changes: 44 additions & 2 deletions test/integration/collection-management/collection.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import { expect } from 'chai';

import { Collection, type Db, type MongoClient, MongoServerError } from '../../mongodb';
import * as sinon from 'sinon';

import {
Collection,
CreateIndexesOperation,
type Db,
type MongoClient,
MongoServerError
} from '../../mongodb';
import { type FailPoint } from '../../tools/utils';
import { setupDatabase } from '../shared';

Expand Down Expand Up @@ -422,6 +429,41 @@ describe('Collection', function () {
});
});

describe('#createIndex', () => {
let client: MongoClient;
let db: Db;
let coll: Collection<{ a: string }>;
const ERROR_RESPONSE = {
ok: 0,
errmsg:
'WiredTigerIndex::insert: key too large to index, failing 1470 { : "56f37cb8e4b089e98d52ab0e", : "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa..." }',
code: 17280
};

beforeEach(async function () {
client = configuration.newClient({ w: 1 });
db = client.db(configuration.db);
coll = db.collection('test_coll');
await client.connect();
sinon.stub(CreateIndexesOperation.prototype, 'execute').callsFake(() => {
throw ERROR_RESPONSE;
});
});

afterEach(async function () {
await coll.drop();
await client.close();
sinon.restore();
});

it('should error when createIndex fails', async function () {
const e = await coll.createIndex({ a: 1 }).catch(e => e);
expect(e).to.have.property('ok', ERROR_RESPONSE.ok);
expect(e).to.have.property('errmsg', ERROR_RESPONSE.errmsg);
expect(e).to.have.property('code', ERROR_RESPONSE.code);
});
});

describe('countDocuments()', function () {
let client: MongoClient;
let collection: Collection<{ test: string }>;
Expand Down
49 changes: 0 additions & 49 deletions test/unit/collection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,55 +14,6 @@ describe('Collection', function () {
await cleanup();
});

context('#createIndex', () => {
it.only('should error when createIndex fails', function (done) {
const ERROR_RESPONSE = {
ok: 0,
errmsg:
'WiredTigerIndex::insert: key too large to index, failing 1470 { : "56f37cb8e4b089e98d52ab0e", : "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa..." }',
code: 17280
};

server.setMessageHandler(request => {
const doc = request.document;

if (isHello(doc)) {
return request.reply(Object.assign({}, HELLO));
}

if (doc.createIndexes) {
return request.reply(ERROR_RESPONSE);
}

if (doc.insert === 'system.indexes') {
return request.reply(ERROR_RESPONSE);
}
});

const client = new MongoClient(`mongodb://${server.uri()}`);

const close = e => client.close().then(() => done(e));

client
.connect()
.then(() => client.db('foo').collection('bar'))
.then(coll => coll.createIndex({ a: 1 }))
.then(
() => close('Expected createIndex to fail, but it succeeded'),
e => {
try {
expect(e).to.have.property('ok', ERROR_RESPONSE.ok);
expect(e).to.have.property('errmsg', ERROR_RESPONSE.errmsg);
expect(e).to.have.property('code', ERROR_RESPONSE.code);
close(null);
} catch (err) {
close(err);
}
}
);
});
});

context('#aggregate', () => {
// general test for aggregate function
function testAggregate(config, done) {
Expand Down

0 comments on commit 3787250

Please sign in to comment.