-
Notifications
You must be signed in to change notification settings - Fork 79
MONGOSH-383 - e2e repl tests #377
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,8 @@ import { | |
ALL_SERVER_VERSIONS, | ||
ALL_TOPOLOGIES | ||
} from './enums'; | ||
import { CliServiceProvider } from '../../service-provider-server'; | ||
import util from 'util'; | ||
|
||
describe('ReplicaSet', () => { | ||
describe('help', () => { | ||
|
@@ -49,14 +51,14 @@ describe('ReplicaSet', () => { | |
}); | ||
}); | ||
|
||
describe('commands', () => { | ||
describe('unit', () => { | ||
let mongo: Mongo; | ||
let serviceProvider: StubbedInstance<ServiceProvider>; | ||
let rs: ReplicaSet; | ||
let bus: StubbedInstance<EventEmitter>; | ||
let internalState: ShellInternalState; | ||
|
||
const findResolvesWith = (expectedResult) => { | ||
const findResolvesWith = (expectedResult): void => { | ||
const findCursor = stubInterface<ServiceProviderCursor>(); | ||
findCursor.next.resolves(expectedResult); | ||
serviceProvider.find.returns(findCursor); | ||
|
@@ -133,7 +135,7 @@ describe('ReplicaSet', () => { | |
expect(serviceProvider.runCommandWithCheck).to.have.been.calledWith( | ||
ADMIN_DB, | ||
{ | ||
replSetReconfig: 1 | ||
replSetGetConfig: 1 | ||
} | ||
); | ||
}); | ||
|
@@ -585,4 +587,151 @@ describe('ReplicaSet', () => { | |
}); | ||
}); | ||
}); | ||
|
||
xdescribe('integration', () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doesn't Should we rather use environment variables to control this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. eslint does complain, but its a warning not a error. We can do the env variable and everything but it seems overkill if we're just going to fix the problem with CI soon enough. |
||
const port0 = 27017; | ||
const host = '127.0.0.1'; | ||
const replId = 'rs0'; | ||
const connectionString = `mongodb://${host}:${port0}`; // startTestServer(); | ||
const cfg = { | ||
_id: replId, | ||
members: [ | ||
{ _id: 0, host: `${host}:${port0}`, priority: 1 }, | ||
{ _id: 1, host: `${host}:${port0 + 1}`, priority: 0 }, | ||
{ _id: 2, host: `${host}:${port0 + 2}`, priority: 0 } | ||
] | ||
}; | ||
let serviceProvider: CliServiceProvider; | ||
let internalState; | ||
let mongo; | ||
let rs; | ||
|
||
const delay = util.promisify(setTimeout); | ||
const ensureMaster = async(timeout): Promise<void> => { | ||
while (!(await rs.isMaster()).ismaster) { | ||
if (timeout > 8000) { | ||
return expect.fail(`Waited for ${host}:${port0} to become master, never happened`); | ||
} | ||
await delay(timeout); | ||
timeout *= 2; // try again but wait double | ||
} | ||
expect((await rs.conf()).members.length).to.equal(3); | ||
}; | ||
|
||
before(async() => { | ||
serviceProvider = await CliServiceProvider.connect(connectionString); | ||
internalState = new ShellInternalState(serviceProvider); | ||
mongo = internalState.currentDb.getMongo(); | ||
rs = new ReplicaSet(mongo); | ||
|
||
// check replset uninitialized | ||
try { | ||
await rs.status(); | ||
} catch (error) { | ||
// eslint-disable-next-line no-console | ||
console.log('WARNING: Initializing new replset'); | ||
expect(error.message).to.include('no replset config'); | ||
const result = await rs.initiate(cfg); | ||
expect(result.ok).to.equal(1); | ||
return expect(result.$clusterTime).to.not.be.undefined; | ||
} | ||
// eslint-disable-next-line no-console | ||
console.log('WARNING: Using existing replset'); | ||
}); | ||
|
||
beforeEach(async() => { | ||
await ensureMaster(1000); | ||
}); | ||
|
||
after(() => { | ||
return serviceProvider.close(true); | ||
}); | ||
|
||
describe('replica set info', () => { | ||
it('returns the status', async() => { | ||
const result = await rs.status(); | ||
expect(result.set).to.equal(replId); | ||
}); | ||
it('returns the config', async() => { | ||
const result = await rs.conf(); | ||
expect(result._id).to.equal(replId); | ||
}); | ||
it('is connected to master', async() => { | ||
const result = await rs.isMaster(); | ||
expect(result.ismaster).to.be.true; | ||
}); | ||
it('returns StatsResult for print secondary replication info', async() => { | ||
const result = await rs.printSecondaryReplicationInfo(); | ||
expect(result.type).to.equal('StatsResult'); | ||
}); | ||
it('returns StatsResult for print replication info', async() => { | ||
const result = await rs.printSecondaryReplicationInfo(); | ||
expect(result.type).to.equal('StatsResult'); | ||
}); | ||
it('returns data for db.getReplicationInfo', async() => { | ||
const result = await rs._mongo.getDB('any').getReplicationInfo(); | ||
expect(Object.keys(result)).to.include('logSizeMB'); | ||
}); | ||
}); | ||
describe('reconfig', () => { | ||
it('reconfig with one less secondary', async() => { | ||
const newcfg = { | ||
_id: replId, | ||
members: [ cfg.members[0], cfg.members[1] ] | ||
}; | ||
const version = (await rs.conf()).version; | ||
const result = await rs.reconfig(newcfg); | ||
expect(result.ok).to.equal(1); | ||
const status = await rs.conf(); | ||
expect(status.members.length).to.equal(2); | ||
expect(status.version).to.equal(version + 1); | ||
}); | ||
afterEach(async() => { | ||
await rs.reconfig(cfg); | ||
const status = await rs.conf(); | ||
expect(status.members.length).to.equal(3); | ||
}); | ||
}); | ||
|
||
describe('add member', () => { | ||
it('adds a regular member to the config', async() => { | ||
const version = (await rs.conf()).version; | ||
const result = await rs.add(`${host}:${port0 + 3}`); | ||
expect(result.ok).to.equal(1); | ||
const conf = await rs.conf(); | ||
expect(conf.members.length).to.equal(4); | ||
expect(conf.version).to.equal(version + 1); | ||
}); | ||
it('adds a arbiter member to the config', async() => { | ||
const version = (await rs.conf()).version; | ||
const result = await rs.addArb(`${host}:${port0 + 3}`); | ||
expect(result.ok).to.equal(1); | ||
const conf = await rs.conf(); | ||
expect(conf.members.length).to.equal(4); | ||
expect(conf.members[3].arbiterOnly).to.equal(true); | ||
expect(conf.version).to.equal(version + 1); | ||
}); | ||
afterEach(async() => { | ||
await rs.reconfig(cfg); | ||
const status = await rs.conf(); | ||
expect(status.members.length).to.equal(3); | ||
}); | ||
}); | ||
|
||
describe('remove member', () => { | ||
it('removes a member of the config', async() => { | ||
const version = (await rs.conf()).version; | ||
const result = await rs.remove(`${host}:${port0 + 2}`); | ||
expect(result.ok).to.equal(1); | ||
const conf = await rs.conf(); | ||
expect(conf.members.length).to.equal(2); | ||
expect(conf.version).to.equal(version + 1); | ||
}); | ||
afterEach(async() => { | ||
await rs.reconfig(cfg); | ||
const status = await rs.conf(); | ||
expect(status.members.length).to.equal(3); | ||
}); | ||
}); | ||
}); | ||
}); |
Uh oh!
There was an error while loading. Please reload this page.