Skip to content

Commit 5d7c556

Browse files
authored
test: avoid unable to acquire lock errors on primary stepdown
NODE-2659
1 parent 5bd16e2 commit 5d7c556

File tree

4 files changed

+43
-11
lines changed

4 files changed

+43
-11
lines changed

test/functional/connections_stepdown.test.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,17 @@ describe('Connections survive primary step down', function() {
9191
.then(() => {
9292
return connectionCount(checkClient).then(initialConnectionCount => {
9393
return db
94-
.executeDbAdminCommand(
95-
{ replSetStepDown: 5, force: true },
96-
{ readPreference: 'primary' }
94+
.executeDbAdminCommand({ replSetFreeze: 0 }, { readPreference: 'secondary' })
95+
.then(result =>
96+
expect(result)
97+
.property('info')
98+
.to.equal('unfreezing')
99+
)
100+
.then(() =>
101+
db.executeDbAdminCommand(
102+
{ replSetStepDown: 30, force: true },
103+
{ readPreference: 'primary' }
104+
)
97105
)
98106
.then(() => cursor.next())
99107
.then(item => expect(item.a).to.equal(3))

test/functional/spec-runner/context.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,8 @@ class TestRunnerContext {
169169
expect(matchingEvents).to.have.lengthOf.at.least(count);
170170
}
171171

172-
runAdminCommand(command) {
173-
return this.sharedClient.db('admin').command(command);
172+
runAdminCommand(command, options) {
173+
return this.sharedClient.db('admin').command(command, options);
174174
}
175175

176176
// simulated thread helpers

test/spec/server-discovery-and-monitoring/integration/rediscover-quickly-after-step-down.json

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,27 @@
4545
"name": "recordPrimary",
4646
"object": "testRunner"
4747
},
48+
{
49+
"name": "runAdminCommand",
50+
"object": "testRunner",
51+
"command_name": "replSetFreeze",
52+
"arguments": {
53+
"command": {
54+
"replSetFreeze": 0
55+
},
56+
"readPreference": {
57+
"mode": "Secondary"
58+
}
59+
}
60+
},
4861
{
4962
"name": "runAdminCommand",
5063
"object": "testRunner",
5164
"command_name": "replSetStepDown",
5265
"arguments": {
5366
"command": {
54-
"replSetStepDown": 1,
55-
"secondaryCatchUpPeriodSecs": 1,
67+
"replSetStepDown": 30,
68+
"secondaryCatchUpPeriodSecs": 30,
5669
"force": false
5770
}
5871
}
@@ -61,7 +74,7 @@
6174
"name": "waitForPrimaryChange",
6275
"object": "testRunner",
6376
"arguments": {
64-
"timeoutMS": 5000
77+
"timeoutMS": 15000
6578
}
6679
},
6780
{

test/spec/server-discovery-and-monitoring/integration/rediscover-quickly-after-step-down.yml

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,30 @@ tests:
3131
- _id: 4
3232
- name: recordPrimary
3333
object: testRunner
34+
# Unfreeze a secondary with replSetFreeze:0 to ensure a speedy election.
35+
- name: runAdminCommand
36+
object: testRunner
37+
command_name: replSetFreeze
38+
arguments:
39+
command:
40+
replSetFreeze: 0
41+
readPreference:
42+
mode: Secondary
3443
# Run replSetStepDown on the meta client.
3544
- name: runAdminCommand
3645
object: testRunner
3746
command_name: replSetStepDown
3847
arguments:
3948
command:
40-
replSetStepDown: 1
41-
secondaryCatchUpPeriodSecs: 1
49+
replSetStepDown: 30
50+
secondaryCatchUpPeriodSecs: 30
4251
force: false
4352
- name: waitForPrimaryChange
4453
object: testRunner
4554
arguments:
46-
timeoutMS: 5000
55+
# We use a relatively large timeout here to workaround slow
56+
# elections on Windows, possibly caused by SERVER-48154.
57+
timeoutMS: 15000
4758
# Rediscover the new primary.
4859
- name: insertMany
4960
object: collection

0 commit comments

Comments
 (0)