Skip to content

Commit 40a4847

Browse files
committed
test: exclude arbiter
1 parent 4193f7d commit 40a4847

File tree

1 file changed

+56
-20
lines changed

1 file changed

+56
-20
lines changed

Diff for: test/integration/server-selection/readpreference.test.ts

+56-20
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,8 @@ describe('ReadPreference', function () {
463463
it('should attach a read preference of primaryPreferred to the read command for replicaset', {
464464
metadata: { requires: { topology: 'replicaset', mongodb: '>=3.6' } },
465465
test: async function () {
466+
let checkedPrimary = false;
467+
466468
for (const server of this.configuration.options.hostAddresses) {
467469
const { host, port } = server.toHostPort();
468470
const client = this.configuration.newClient(
@@ -482,23 +484,39 @@ describe('ReadPreference', function () {
482484
events.push(event);
483485
}
484486
});
485-
let serverError;
487+
let serverStatus;
488+
486489
try {
487-
await client.db('test').collection('test').findOne({ a: 1 });
488-
} catch (error) {
489-
serverError = error;
490+
const admin = client.db().admin();
491+
serverStatus = await admin.serverStatus();
492+
} catch (serverStatusError) {
493+
expect(serverStatusError).to.not.exist;
490494
}
491495

492-
expect(serverError).to.not.exist;
493-
expect(events[0]).to.containSubset({
494-
commandName: 'find',
495-
command: {
496-
$readPreference: { mode: 'primaryPreferred' }
496+
if (serverStatus.repl.ismaster) {
497+
let serverError;
498+
499+
try {
500+
await client.db('test').collection('test').findOne({ a: 1 });
501+
} catch (error) {
502+
serverError = error;
497503
}
498-
});
504+
505+
expect(serverError).to.not.exist;
506+
expect(events[0]).to.containSubset({
507+
commandName: 'find',
508+
command: {
509+
$readPreference: { mode: 'primaryPreferred' }
510+
}
511+
});
512+
513+
checkedPrimary = true;
514+
}
499515

500516
await client.close();
501517
}
518+
519+
expect(checkedPrimary).to.be.equal(true);
502520
}
503521
});
504522

@@ -550,6 +568,8 @@ describe('ReadPreference', function () {
550568
it('should attach a read preference of secondary to the read command for replicaset', {
551569
metadata: { requires: { topology: 'replicaset', mongodb: '>=3.6' } },
552570
test: async function () {
571+
let checkedSecondary = false;
572+
553573
for (const server of this.configuration.options.hostAddresses) {
554574
const { host, port } = server.toHostPort();
555575
const client = this.configuration.newClient(
@@ -569,23 +589,39 @@ describe('ReadPreference', function () {
569589
events.push(event);
570590
}
571591
});
572-
let serverError;
592+
let serverStatus;
593+
573594
try {
574-
await client.db('test').collection('test').findOne({ a: 1 });
575-
} catch (error) {
576-
serverError = error;
595+
const admin = client.db().admin();
596+
serverStatus = await admin.serverStatus();
597+
} catch (serverStatusError) {
598+
expect(serverStatusError).to.not.exist;
577599
}
578600

579-
expect(serverError).to.not.exist;
580-
expect(events[0]).to.containSubset({
581-
commandName: 'find',
582-
command: {
583-
$readPreference: { mode: 'secondary' }
601+
if (serverStatus.repl.secondary) {
602+
let serverError;
603+
604+
try {
605+
await client.db('test').collection('test').findOne({ a: 1 });
606+
} catch (error) {
607+
serverError = error;
584608
}
585-
});
609+
610+
expect(serverError).to.not.exist;
611+
expect(events[0]).to.containSubset({
612+
commandName: 'find',
613+
command: {
614+
$readPreference: { mode: 'secondary' }
615+
}
616+
});
617+
618+
checkedSecondary = true;
619+
}
586620

587621
await client.close();
588622
}
623+
624+
expect(checkedSecondary).to.be.equal(true);
589625
}
590626
});
591627

0 commit comments

Comments
 (0)