From 6bf41970b9bef6207e7443b3b10e80032b08951e Mon Sep 17 00:00:00 2001 From: Neal Beeken Date: Tue, 15 Mar 2022 16:35:31 -0400 Subject: [PATCH 1/7] sync: spec tests, has failures --- .../rs/electionId_precedence_setVersion.json | 92 +++++++++++ .../rs/electionId_precedence_setVersion.yml | 62 ++++++++ .../rs/null_election_id.json | 30 ++-- .../rs/null_election_id.yml | 30 ++-- .../rs/set_version_can_rollback.json | 149 ++++++++++++++++++ .../rs/set_version_can_rollback.yml | 101 ++++++++++++ ...tversion_equal_max_without_electionid.json | 84 ++++++++++ ...etversion_equal_max_without_electionid.yml | 78 +++++++++ ...on_greaterthan_max_without_electionid.json | 84 ++++++++++ ...ion_greaterthan_max_without_electionid.yml | 79 ++++++++++ .../rs/setversion_without_electionid.json | 12 +- .../rs/setversion_without_electionid.yml | 15 +- .../rs/use_setversion_without_electionid.json | 32 ++-- .../rs/use_setversion_without_electionid.yml | 38 ++--- 14 files changed, 815 insertions(+), 71 deletions(-) create mode 100644 test/spec/server-discovery-and-monitoring/rs/electionId_precedence_setVersion.json create mode 100644 test/spec/server-discovery-and-monitoring/rs/electionId_precedence_setVersion.yml create mode 100644 test/spec/server-discovery-and-monitoring/rs/set_version_can_rollback.json create mode 100644 test/spec/server-discovery-and-monitoring/rs/set_version_can_rollback.yml create mode 100644 test/spec/server-discovery-and-monitoring/rs/setversion_equal_max_without_electionid.json create mode 100644 test/spec/server-discovery-and-monitoring/rs/setversion_equal_max_without_electionid.yml create mode 100644 test/spec/server-discovery-and-monitoring/rs/setversion_greaterthan_max_without_electionid.json create mode 100644 test/spec/server-discovery-and-monitoring/rs/setversion_greaterthan_max_without_electionid.yml diff --git a/test/spec/server-discovery-and-monitoring/rs/electionId_precedence_setVersion.json b/test/spec/server-discovery-and-monitoring/rs/electionId_precedence_setVersion.json new file mode 100644 index 0000000000..a7b49e2b97 --- /dev/null +++ b/test/spec/server-discovery-and-monitoring/rs/electionId_precedence_setVersion.json @@ -0,0 +1,92 @@ +{ + "description": "ElectionId is considered higher precedence than setVersion", + "uri": "mongodb://a/?replicaSet=rs", + "phases": [ + { + "responses": [ + [ + "a:27017", + { + "ok": 1, + "helloOk": true, + "isWritablePrimary": true, + "hosts": [ + "a:27017", + "b:27017" + ], + "setName": "rs", + "setVersion": 1, + "electionId": { + "$oid": "000000000000000000000001" + }, + "minWireVersion": 0, + "maxWireVersion": 6 + } + ], + [ + "b:27017", + { + "ok": 1, + "helloOk": true, + "isWritablePrimary": true, + "hosts": [ + "a:27017", + "b:27017" + ], + "setName": "rs", + "setVersion": 2, + "electionId": { + "$oid": "000000000000000000000001" + }, + "minWireVersion": 0, + "maxWireVersion": 6 + } + ], + [ + "a:27017", + { + "ok": 1, + "helloOk": true, + "isWritablePrimary": true, + "hosts": [ + "a:27017", + "b:27017" + ], + "setName": "rs", + "setVersion": 1, + "electionId": { + "$oid": "000000000000000000000002" + }, + "minWireVersion": 0, + "maxWireVersion": 6 + } + ] + ], + "outcome": { + "servers": { + "a:27017": { + "type": "RSPrimary", + "setName": "rs", + "setVersion": 1, + "electionId": { + "$oid": "000000000000000000000002" + } + }, + "b:27017": { + "type": "Unknown", + "setName": null, + "setVersion": null, + "electionId": null + } + }, + "topologyType": "ReplicaSetWithPrimary", + "logicalSessionTimeoutMinutes": null, + "setName": "rs", + "maxSetVersion": 1, + "maxElectionId": { + "$oid": "000000000000000000000002" + } + } + } + ] +} diff --git a/test/spec/server-discovery-and-monitoring/rs/electionId_precedence_setVersion.yml b/test/spec/server-discovery-and-monitoring/rs/electionId_precedence_setVersion.yml new file mode 100644 index 0000000000..e552e984c2 --- /dev/null +++ b/test/spec/server-discovery-and-monitoring/rs/electionId_precedence_setVersion.yml @@ -0,0 +1,62 @@ +description: ElectionId is considered higher precedence than setVersion +uri: "mongodb://a/?replicaSet=rs" +phases: + - responses: + - - "a:27017" + - ok: 1 + helloOk: true + isWritablePrimary: true + hosts: + - "a:27017" + - "b:27017" + setName: rs + setVersion: 1 + electionId: + $oid: "000000000000000000000001" + minWireVersion: 0 + maxWireVersion: 6 + - - "b:27017" + - ok: 1 + helloOk: true + isWritablePrimary: true + hosts: + - "a:27017" + - "b:27017" + setName: rs + setVersion: 2 # Even though "B" reports the newer setVersion, "A" will report the newer electionId which should allow it to remain the primary + electionId: + $oid: "000000000000000000000001" + minWireVersion: 0 + maxWireVersion: 6 + - - "a:27017" + - ok: 1 + helloOk: true + isWritablePrimary: true + hosts: + - "a:27017" + - "b:27017" + setName: rs + setVersion: 1 + electionId: + $oid: "000000000000000000000002" + minWireVersion: 0 + maxWireVersion: 6 + outcome: + servers: + "a:27017": + type: RSPrimary + setName: rs + setVersion: 1 + electionId: + $oid: "000000000000000000000002" + "b:27017": + type: Unknown + setName: null + setVersion: null + electionId: null + topologyType: ReplicaSetWithPrimary + logicalSessionTimeoutMinutes: null + setName: rs + maxSetVersion: 1 + maxElectionId: + $oid: "000000000000000000000002" diff --git a/test/spec/server-discovery-and-monitoring/rs/null_election_id.json b/test/spec/server-discovery-and-monitoring/rs/null_election_id.json index 62120e8448..8eb519595a 100644 --- a/test/spec/server-discovery-and-monitoring/rs/null_election_id.json +++ b/test/spec/server-discovery-and-monitoring/rs/null_election_id.json @@ -123,16 +123,19 @@ "outcome": { "servers": { "a:27017": { - "type": "RSPrimary", - "setName": "rs", - "setVersion": 1, - "electionId": null - }, - "b:27017": { "type": "Unknown", "setName": null, + "setVersion": null, "electionId": null }, + "b:27017": { + "type": "RSPrimary", + "setName": "rs", + "setVersion": 1, + "electionId": { + "$oid": "000000000000000000000002" + } + }, "c:27017": { "type": "Unknown", "setName": null, @@ -174,16 +177,19 @@ "outcome": { "servers": { "a:27017": { - "type": "RSPrimary", - "setName": "rs", - "setVersion": 1, - "electionId": null - }, - "b:27017": { "type": "Unknown", "setName": null, + "setVersion": null, "electionId": null }, + "b:27017": { + "type": "RSPrimary", + "setName": "rs", + "setVersion": 1, + "electionId": { + "$oid": "000000000000000000000002" + } + }, "c:27017": { "type": "Unknown", "setName": null, diff --git a/test/spec/server-discovery-and-monitoring/rs/null_election_id.yml b/test/spec/server-discovery-and-monitoring/rs/null_election_id.yml index 7de496cd79..9377285e43 100644 --- a/test/spec/server-discovery-and-monitoring/rs/null_election_id.yml +++ b/test/spec/server-discovery-and-monitoring/rs/null_election_id.yml @@ -88,7 +88,7 @@ phases: [ } }, - # A still claims to be primary, no electionId, we have to trust it. + # A still claims to be primary, no electionId, we don't trust it. { responses: [ ["a:27017", { @@ -104,17 +104,19 @@ phases: [ ], outcome: { servers: { + # A ignored for missing electionId "a:27017": { - type: "RSPrimary", - setName: "rs", - setVersion: 1, - electionId: - }, - "b:27017": { type: "Unknown", setName: , + setVersion: , electionId: }, + "b:27017": { + type: "RSPrimary", + setName: "rs", + setVersion: 1, + electionId: { "$oid": "000000000000000000000002" } + }, "c:27017": { type: "Unknown", setName: , @@ -147,18 +149,18 @@ phases: [ ], outcome: { servers: { - # Still primary. "a:27017": { - type: "RSPrimary", - setName: "rs", - setVersion: 1, - electionId: - }, - "b:27017": { type: "Unknown", setName: , + setVersion: , electionId: }, + "b:27017": { + type: "RSPrimary", + setName: "rs", + setVersion: 1, + electionId: { "$oid": "000000000000000000000002" } + }, "c:27017": { type: "Unknown", setName: , diff --git a/test/spec/server-discovery-and-monitoring/rs/set_version_can_rollback.json b/test/spec/server-discovery-and-monitoring/rs/set_version_can_rollback.json new file mode 100644 index 0000000000..28ecbeefca --- /dev/null +++ b/test/spec/server-discovery-and-monitoring/rs/set_version_can_rollback.json @@ -0,0 +1,149 @@ +{ + "description": "Set version rolls back after new primary with higher election Id", + "uri": "mongodb://a/?replicaSet=rs", + "phases": [ + { + "responses": [ + [ + "a:27017", + { + "ok": 1, + "hello": true, + "isWritablePrimary": true, + "hosts": [ + "a:27017", + "b:27017" + ], + "setName": "rs", + "setVersion": 2, + "electionId": { + "$oid": "000000000000000000000001" + }, + "minWireVersion": 0, + "maxWireVersion": 6 + } + ] + ], + "outcome": { + "servers": { + "a:27017": { + "type": "RSPrimary", + "setName": "rs", + "setVersion": 2, + "electionId": { + "$oid": "000000000000000000000001" + } + }, + "b:27017": { + "type": "Unknown", + "setName": null, + "electionId": null + } + }, + "topologyType": "ReplicaSetWithPrimary", + "logicalSessionTimeoutMinutes": null, + "setName": "rs", + "maxSetVersion": 2, + "maxElectionId": { + "$oid": "000000000000000000000001" + } + } + }, + { + "_comment": "Response from new primary with newer election Id", + "responses": [ + [ + "b:27017", + { + "ok": 1, + "hello": true, + "isWritablePrimary": true, + "hosts": [ + "a:27017", + "b:27017" + ], + "setName": "rs", + "setVersion": 1, + "electionId": { + "$oid": "000000000000000000000002" + }, + "minWireVersion": 0, + "maxWireVersion": 6 + } + ] + ], + "outcome": { + "servers": { + "a:27017": { + "type": "Unknown", + "setName": null, + "electionId": null + }, + "b:27017": { + "type": "RSPrimary", + "setName": "rs", + "setVersion": 1, + "electionId": { + "$oid": "000000000000000000000002" + } + } + }, + "topologyType": "ReplicaSetWithPrimary", + "logicalSessionTimeoutMinutes": null, + "setName": "rs", + "maxSetVersion": 1, + "maxElectionId": { + "$oid": "000000000000000000000002" + } + } + }, + { + "_comment": "Response from stale primary", + "responses": [ + [ + "a:27017", + { + "ok": 1, + "hello": true, + "isWritablePrimary": true, + "hosts": [ + "a:27017", + "b:27017" + ], + "setName": "rs", + "setVersion": 2, + "electionId": { + "$oid": "000000000000000000000001" + }, + "minWireVersion": 0, + "maxWireVersion": 6 + } + ] + ], + "outcome": { + "servers": { + "a:27017": { + "type": "Unknown", + "setName": null, + "electionId": null + }, + "b:27017": { + "type": "RSPrimary", + "setName": "rs", + "setVersion": 1, + "electionId": { + "$oid": "000000000000000000000002" + } + } + }, + "topologyType": "ReplicaSetWithPrimary", + "logicalSessionTimeoutMinutes": null, + "setName": "rs", + "maxSetVersion": 1, + "maxElectionId": { + "$oid": "000000000000000000000002" + } + } + } + ] +} diff --git a/test/spec/server-discovery-and-monitoring/rs/set_version_can_rollback.yml b/test/spec/server-discovery-and-monitoring/rs/set_version_can_rollback.yml new file mode 100644 index 0000000000..ef91a074a6 --- /dev/null +++ b/test/spec/server-discovery-and-monitoring/rs/set_version_can_rollback.yml @@ -0,0 +1,101 @@ +description: Set version rolls back after new primary with higher election Id +uri: mongodb://a/?replicaSet=rs +phases: + - responses: + - - a:27017 + - ok: 1 + hello: true + isWritablePrimary: true + hosts: + - a:27017 + - b:27017 + setName: rs + setVersion: 2 + electionId: + $oid: '000000000000000000000001' + minWireVersion: 0 + maxWireVersion: 6 + outcome: + servers: + a:27017: + type: RSPrimary + setName: rs + setVersion: 2 + electionId: + $oid: '000000000000000000000001' + b:27017: + type: Unknown + setName: null + electionId: null + topologyType: ReplicaSetWithPrimary + logicalSessionTimeoutMinutes: null + setName: rs + maxSetVersion: 2 + maxElectionId: + $oid: '000000000000000000000001' + - _comment: Response from new primary with newer election Id + responses: + - - b:27017 + - ok: 1 + hello: true + isWritablePrimary: true + hosts: + - a:27017 + - b:27017 + setName: rs + setVersion: 1 + electionId: + $oid: '000000000000000000000002' + minWireVersion: 0 + maxWireVersion: 6 + outcome: + servers: + a:27017: + type: Unknown + setName: null + electionId: null + b:27017: + type: RSPrimary + setName: rs + setVersion: 1 + electionId: + $oid: '000000000000000000000002' + topologyType: ReplicaSetWithPrimary + logicalSessionTimeoutMinutes: null + setName: rs + maxSetVersion: 1 + maxElectionId: + $oid: '000000000000000000000002' + - _comment: Response from stale primary + responses: + - - a:27017 + - ok: 1 + hello: true + isWritablePrimary: true + hosts: + - a:27017 + - b:27017 + setName: rs + setVersion: 2 + electionId: + $oid: '000000000000000000000001' + minWireVersion: 0 + maxWireVersion: 6 + outcome: + servers: + a:27017: + type: Unknown + setName: null + electionId: null + b:27017: + type: RSPrimary + setName: rs + setVersion: 1 + electionId: + $oid: '000000000000000000000002' + topologyType: ReplicaSetWithPrimary + logicalSessionTimeoutMinutes: null + setName: rs + maxSetVersion: 1 + maxElectionId: + $oid: '000000000000000000000002' diff --git a/test/spec/server-discovery-and-monitoring/rs/setversion_equal_max_without_electionid.json b/test/spec/server-discovery-and-monitoring/rs/setversion_equal_max_without_electionid.json new file mode 100644 index 0000000000..91e84d4fa0 --- /dev/null +++ b/test/spec/server-discovery-and-monitoring/rs/setversion_equal_max_without_electionid.json @@ -0,0 +1,84 @@ +{ + "description": "setVersion version that is equal is treated the same as greater than if there is no electionId", + "uri": "mongodb://a/?replicaSet=rs", + "phases": [ + { + "responses": [ + [ + "a:27017", + { + "ok": 1, + "helloOk": true, + "isWritablePrimary": true, + "hosts": [ + "a:27017", + "b:27017" + ], + "setName": "rs", + "setVersion": 1, + "minWireVersion": 0, + "maxWireVersion": 6 + } + ] + ], + "outcome": { + "servers": { + "a:27017": { + "type": "RSPrimary", + "setName": "rs", + "setVersion": 1, + "electionId": null + }, + "b:27017": { + "type": "Unknown", + "setName": null, + "electionId": null + } + }, + "topologyType": "ReplicaSetWithPrimary", + "logicalSessionTimeoutMinutes": null, + "setName": "rs", + "maxSetVersion": 1 + } + }, + { + "responses": [ + [ + "b:27017", + { + "ok": 1, + "helloOk": true, + "isWritablePrimary": true, + "hosts": [ + "a:27017", + "b:27017" + ], + "setName": "rs", + "setVersion": 1, + "minWireVersion": 0, + "maxWireVersion": 6 + } + ] + ], + "outcome": { + "servers": { + "a:27017": { + "type": "Unknown", + "setName": null, + "electionId": null + }, + "b:27017": { + "type": "RSPrimary", + "setName": "rs", + "setVersion": 1, + "electionId": null + } + }, + "topologyType": "ReplicaSetWithPrimary", + "logicalSessionTimeoutMinutes": null, + "setName": "rs", + "maxSetVersion": 1 + } + } + ] +} diff --git a/test/spec/server-discovery-and-monitoring/rs/setversion_equal_max_without_electionid.yml b/test/spec/server-discovery-and-monitoring/rs/setversion_equal_max_without_electionid.yml new file mode 100644 index 0000000000..cdce70f030 --- /dev/null +++ b/test/spec/server-discovery-and-monitoring/rs/setversion_equal_max_without_electionid.yml @@ -0,0 +1,78 @@ +description: "setVersion version that is equal is treated the same as greater than if there is no electionId" + +uri: "mongodb://a/?replicaSet=rs" + +phases: [ + + # Primary A is discovered and tells us about B. + { + responses: [ + ["a:27017", { + ok: 1, + helloOk: true, + isWritablePrimary: true, + hosts: ["a:27017", "b:27017"], + setName: "rs", + setVersion: 1, + minWireVersion: 0, + maxWireVersion: 6 + }] + ], + + outcome: { + servers: { + "a:27017": { + type: "RSPrimary", + setName: "rs", + setVersion: 1, + electionId: + }, + "b:27017": { + type: "Unknown", + setName: , + electionId: + } + }, + topologyType: "ReplicaSetWithPrimary", + logicalSessionTimeoutMinutes: null, + setName: "rs", + maxSetVersion: 1, + } + }, + + # B is elected, its setVersion is older so it is stale + { + responses: [ + ["b:27017", { + ok: 1, + helloOk: true, + isWritablePrimary: true, + hosts: ["a:27017", "b:27017"], + setName: "rs", + setVersion: 1, + minWireVersion: 0, + maxWireVersion: 6 + }] + ], + + outcome: { + servers: { + "a:27017": { + type: "Unknown", + setName: , + electionId: + }, + "b:27017": { + type: "RSPrimary", + setName: "rs", + setVersion: 1, + electionId: + } + }, + topologyType: "ReplicaSetWithPrimary", + logicalSessionTimeoutMinutes: null, + setName: "rs", + maxSetVersion: 1, # Max is still 1, there wasn't an actual larger setVersion seen + } + } +] diff --git a/test/spec/server-discovery-and-monitoring/rs/setversion_greaterthan_max_without_electionid.json b/test/spec/server-discovery-and-monitoring/rs/setversion_greaterthan_max_without_electionid.json new file mode 100644 index 0000000000..b15fd5c1a7 --- /dev/null +++ b/test/spec/server-discovery-and-monitoring/rs/setversion_greaterthan_max_without_electionid.json @@ -0,0 +1,84 @@ +{ + "description": "setVersion that is greater than maxSetVersion is used if there is no electionId", + "uri": "mongodb://a/?replicaSet=rs", + "phases": [ + { + "responses": [ + [ + "a:27017", + { + "ok": 1, + "helloOk": true, + "isWritablePrimary": true, + "hosts": [ + "a:27017", + "b:27017" + ], + "setName": "rs", + "setVersion": 1, + "minWireVersion": 0, + "maxWireVersion": 6 + } + ] + ], + "outcome": { + "servers": { + "a:27017": { + "type": "RSPrimary", + "setName": "rs", + "setVersion": 1, + "electionId": null + }, + "b:27017": { + "type": "Unknown", + "setName": null, + "electionId": null + } + }, + "topologyType": "ReplicaSetWithPrimary", + "logicalSessionTimeoutMinutes": null, + "setName": "rs", + "maxSetVersion": 1 + } + }, + { + "responses": [ + [ + "b:27017", + { + "ok": 1, + "helloOk": true, + "isWritablePrimary": true, + "hosts": [ + "a:27017", + "b:27017" + ], + "setName": "rs", + "setVersion": 2, + "minWireVersion": 0, + "maxWireVersion": 6 + } + ] + ], + "outcome": { + "servers": { + "a:27017": { + "type": "Unknown", + "setName": null, + "electionId": null + }, + "b:27017": { + "type": "RSPrimary", + "setName": "rs", + "setVersion": 2, + "electionId": null + } + }, + "topologyType": "ReplicaSetWithPrimary", + "logicalSessionTimeoutMinutes": null, + "setName": "rs", + "maxSetVersion": 2 + } + } + ] +} diff --git a/test/spec/server-discovery-and-monitoring/rs/setversion_greaterthan_max_without_electionid.yml b/test/spec/server-discovery-and-monitoring/rs/setversion_greaterthan_max_without_electionid.yml new file mode 100644 index 0000000000..34150c4422 --- /dev/null +++ b/test/spec/server-discovery-and-monitoring/rs/setversion_greaterthan_max_without_electionid.yml @@ -0,0 +1,79 @@ +description: "setVersion that is greater than maxSetVersion is used if there is no electionId" + +uri: "mongodb://a/?replicaSet=rs" + +phases: [ + + # Primary A is discovered and tells us about B. + { + responses: [ + ["a:27017", { + ok: 1, + helloOk: true, + isWritablePrimary: true, + hosts: ["a:27017", "b:27017"], + setName: "rs", + setVersion: 1, + minWireVersion: 0, + maxWireVersion: 6 + }] + ], + + outcome: { + servers: { + "a:27017": { + type: "RSPrimary", + setName: "rs", + setVersion: 1, + electionId: + }, + "b:27017": { + type: "Unknown", + setName: , + electionId: + } + }, + topologyType: "ReplicaSetWithPrimary", + logicalSessionTimeoutMinutes: null, + setName: "rs", + maxSetVersion: 1, + } + }, + + # B is elected, its setVersion is greater than our current maxSetVersion + # B is primary, A is marked Unknown + { + responses: [ + ["b:27017", { + ok: 1, + helloOk: true, + isWritablePrimary: true, + hosts: ["a:27017", "b:27017"], + setName: "rs", + setVersion: 2, + minWireVersion: 0, + maxWireVersion: 6 + }] + ], + + outcome: { + servers: { + "a:27017": { + type: "Unknown", + setName: , + electionId: + }, + "b:27017": { + type: "RSPrimary", + setName: "rs", + setVersion: 2, + electionId: + }, + }, + topologyType: "ReplicaSetWithPrimary", + logicalSessionTimeoutMinutes: null, + setName: "rs", + maxSetVersion: 2, + } + } +] diff --git a/test/spec/server-discovery-and-monitoring/rs/setversion_without_electionid.json b/test/spec/server-discovery-and-monitoring/rs/setversion_without_electionid.json index 2f68287f1d..f59c162ae1 100644 --- a/test/spec/server-discovery-and-monitoring/rs/setversion_without_electionid.json +++ b/test/spec/server-discovery-and-monitoring/rs/setversion_without_electionid.json @@ -1,5 +1,5 @@ { - "description": "setVersion is ignored if there is no electionId", + "description": "setVersion that is less than maxSetVersion is ignored if there is no electionId", "uri": "mongodb://a/?replicaSet=rs", "phases": [ { @@ -63,14 +63,14 @@ "outcome": { "servers": { "a:27017": { - "type": "Unknown", - "setName": null, + "type": "RSPrimary", + "setName": "rs", + "setVersion": 2, "electionId": null }, "b:27017": { - "type": "RSPrimary", - "setName": "rs", - "setVersion": 1, + "type": "Unknown", + "setName": null, "electionId": null } }, diff --git a/test/spec/server-discovery-and-monitoring/rs/setversion_without_electionid.yml b/test/spec/server-discovery-and-monitoring/rs/setversion_without_electionid.yml index 55c841f24b..ea8f28c238 100644 --- a/test/spec/server-discovery-and-monitoring/rs/setversion_without_electionid.yml +++ b/test/spec/server-discovery-and-monitoring/rs/setversion_without_electionid.yml @@ -1,4 +1,4 @@ -description: "setVersion is ignored if there is no electionId" +description: "setVersion that is less than maxSetVersion is ignored if there is no electionId" uri: "mongodb://a/?replicaSet=rs" @@ -40,8 +40,7 @@ phases: [ } }, - # B is elected, its setVersion is older but we believe it anyway, because - # setVersion is only used in conjunction with electionId. + # B is elected, its setVersion is older so it is stale { responses: [ ["b:27017", { @@ -59,14 +58,14 @@ phases: [ outcome: { servers: { "a:27017": { - type: "Unknown", - setName: , + type: "RSPrimary", + setName: "rs", + setVersion: 2 , electionId: }, "b:27017": { - type: "RSPrimary", - setName: "rs", - setVersion: 1, + type: "Unknown", + setName: , electionId: } }, diff --git a/test/spec/server-discovery-and-monitoring/rs/use_setversion_without_electionid.json b/test/spec/server-discovery-and-monitoring/rs/use_setversion_without_electionid.json index 421ff57c8d..6dd753d5d8 100644 --- a/test/spec/server-discovery-and-monitoring/rs/use_setversion_without_electionid.json +++ b/test/spec/server-discovery-and-monitoring/rs/use_setversion_without_electionid.json @@ -71,20 +71,23 @@ "outcome": { "servers": { "a:27017": { + "type": "RSPrimary", + "setName": "rs", + "setVersion": 1, + "electionId": { + "$oid": "000000000000000000000001" + } + }, + "b:27017": { "type": "Unknown", "setName": null, "electionId": null - }, - "b:27017": { - "type": "RSPrimary", - "setName": "rs", - "setVersion": 2 } }, "topologyType": "ReplicaSetWithPrimary", "logicalSessionTimeoutMinutes": null, "setName": "rs", - "maxSetVersion": 2, + "maxSetVersion": 1, "maxElectionId": { "$oid": "000000000000000000000001" } @@ -115,22 +118,25 @@ "outcome": { "servers": { "a:27017": { + "type": "RSPrimary", + "setName": "rs", + "setVersion": 1, + "electionId": { + "$oid": "000000000000000000000002" + } + }, + "b:27017": { "type": "Unknown", "setName": null, "electionId": null - }, - "b:27017": { - "type": "RSPrimary", - "setName": "rs", - "setVersion": 2 } }, "topologyType": "ReplicaSetWithPrimary", "logicalSessionTimeoutMinutes": null, "setName": "rs", - "maxSetVersion": 2, + "maxSetVersion": 1, "maxElectionId": { - "$oid": "000000000000000000000001" + "$oid": "000000000000000000000002" } } } diff --git a/test/spec/server-discovery-and-monitoring/rs/use_setversion_without_electionid.yml b/test/spec/server-discovery-and-monitoring/rs/use_setversion_without_electionid.yml index 300f9d9304..669ec20d43 100644 --- a/test/spec/server-discovery-and-monitoring/rs/use_setversion_without_electionid.yml +++ b/test/spec/server-discovery-and-monitoring/rs/use_setversion_without_electionid.yml @@ -4,7 +4,7 @@ uri: "mongodb://a/?replicaSet=rs" phases: [ - # Primary A has setVersion and electionId, tells us about B. + # Primary A has electionId and setVersion, tells us about B. { responses: [ ["a:27017", { @@ -42,7 +42,7 @@ phases: [ } }, - # Reconfig the set and elect B, it has a new setVersion but no electionId. + # Reconfig, B reports as primary, B is missing the electionId but reports setVersion { responses: [ ["b:27017", { @@ -59,27 +59,28 @@ phases: [ outcome: { servers: { - "a:27017": { + "a:27017": { + type: "RSPrimary", + setName: "rs", + setVersion: 1, + electionId: { "$oid": "000000000000000000000001" } + }, + "b:27017": { type: "Unknown", setName: , electionId: - }, - "b:27017": { - type: "RSPrimary", - setName: "rs", - setVersion: 2 } }, topologyType: "ReplicaSetWithPrimary", logicalSessionTimeoutMinutes: null, setName: "rs", - maxSetVersion: 2, + maxSetVersion: 1, maxElectionId: {"$oid": "000000000000000000000001"}, } }, - # Delayed response from A, reporting its reelection. Its setVersion shows - # the election preceded B's so we ignore it. + # A reports as primary, A has been reelection (electionId greater than our recorded maxElectionId). + # A's setVersion is less than our maxSetVersion, but electionId takes precedence so B's primary claim is ignored { responses: [ ["a:27017", { @@ -97,21 +98,22 @@ phases: [ outcome: { servers: { "a:27017": { + type: "RSPrimary", + setName: "rs", + setVersion: 1, + electionId: {"$oid": "000000000000000000000002"} + }, + "b:27017":{ type: "Unknown", setName: , electionId: - }, - "b:27017": { - type: "RSPrimary", - setName: "rs", - setVersion: 2 } }, topologyType: "ReplicaSetWithPrimary", logicalSessionTimeoutMinutes: null, setName: "rs", - maxSetVersion: 2, - maxElectionId: {"$oid": "000000000000000000000001"}, + maxSetVersion: 1, + maxElectionId: {"$oid": "000000000000000000000002"}, } } ] From 088f3f0cb6c85407ad37efb765f2622eb19aabc5 Mon Sep 17 00:00:00 2001 From: Neal Beeken Date: Tue, 15 Mar 2022 16:40:33 -0400 Subject: [PATCH 2/7] driver changes, passes tests --- src/sdam/topology_description.ts | 39 ++++++++++++++++---------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/src/sdam/topology_description.ts b/src/sdam/topology_description.ts index 972680afdd..2c0975fd4a 100644 --- a/src/sdam/topology_description.ts +++ b/src/sdam/topology_description.ts @@ -373,31 +373,30 @@ function updateRsFromPrimary( return [checkHasPrimary(serverDescriptions), setName, maxSetVersion, maxElectionId]; } - const electionId = serverDescription.electionId ? serverDescription.electionId : null; - if (serverDescription.setVersion && electionId) { - if (maxSetVersion && maxElectionId) { - if ( - maxSetVersion > serverDescription.setVersion || - compareObjectId(maxElectionId, electionId) > 0 - ) { - // this primary is stale, we must remove it - serverDescriptions.set( - serverDescription.address, - new ServerDescription(serverDescription.address) - ); - - return [checkHasPrimary(serverDescriptions), setName, maxSetVersion, maxElectionId]; - } - } + const electionIdComparison = compareObjectId(maxElectionId, serverDescription.electionId); + const maxElectionIdIsEqual = electionIdComparison === 0; + const maxElectionIdIsLess = electionIdComparison === -1; - maxElectionId = serverDescription.electionId; - } + const setVersionComparison = compareNumber(maxSetVersion, serverDescription.setVersion); + const maxSetVersionIsLess = setVersionComparison === -1; + const maxSetVersionIsEqual = setVersionComparison === 0; if ( - serverDescription.setVersion != null && - (maxSetVersion == null || serverDescription.setVersion > maxSetVersion) + maxElectionIdIsLess || + (maxElectionIdIsEqual && (maxSetVersionIsLess || maxSetVersionIsEqual)) ) { + // We've seen a higher ElectionId! Update both! + // Or the electionId is the same but the setVersion increased + maxElectionId = serverDescription.electionId; maxSetVersion = serverDescription.setVersion; + } else { + // this primary is stale, we must remove it + serverDescriptions.set( + serverDescription.address, + new ServerDescription(serverDescription.address) + ); + + return [checkHasPrimary(serverDescriptions), setName, maxSetVersion, maxElectionId]; } // We've heard from the primary. Is it the same primary as before? From 31c542aaa31a11d24050808a27476050ce25d3b6 Mon Sep 17 00:00:00 2001 From: Neal Beeken Date: Mon, 28 Mar 2022 13:27:31 -0400 Subject: [PATCH 3/7] fixup boolean logic --- src/sdam/topology_description.ts | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/sdam/topology_description.ts b/src/sdam/topology_description.ts index 2c0975fd4a..40673ab1b2 100644 --- a/src/sdam/topology_description.ts +++ b/src/sdam/topology_description.ts @@ -376,21 +376,17 @@ function updateRsFromPrimary( const electionIdComparison = compareObjectId(maxElectionId, serverDescription.electionId); const maxElectionIdIsEqual = electionIdComparison === 0; const maxElectionIdIsLess = electionIdComparison === -1; + const maxSetVersionIsLessOrEqual = (maxSetVersion ?? -1) <= (serverDescription.setVersion ?? -1); - const setVersionComparison = compareNumber(maxSetVersion, serverDescription.setVersion); - const maxSetVersionIsLess = setVersionComparison === -1; - const maxSetVersionIsEqual = setVersionComparison === 0; - - if ( - maxElectionIdIsLess || - (maxElectionIdIsEqual && (maxSetVersionIsLess || maxSetVersionIsEqual)) - ) { - // We've seen a higher ElectionId! Update both! - // Or the electionId is the same but the setVersion increased + if (maxElectionIdIsLess || (maxElectionIdIsEqual && maxSetVersionIsLessOrEqual)) { + // The reported electionId was greater + // or the electionId was equal and reported setVersion was greater + // Always update both values, they are a tuple maxElectionId = serverDescription.electionId; maxSetVersion = serverDescription.setVersion; } else { - // this primary is stale, we must remove it + // Stale primary + // replace serverDescription with a default ServerDescription of type "Unknown" serverDescriptions.set( serverDescription.address, new ServerDescription(serverDescription.address) From 3bb7c70d8e702d325a6a06ab7c9ddfe1da691c81 Mon Sep 17 00:00:00 2001 From: Neal Beeken Date: Fri, 12 Aug 2022 15:35:24 -0400 Subject: [PATCH 4/7] fix: ts --- src/utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils.ts b/src/utils.ts index f3349b6eca..ccbe87d0cc 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1300,7 +1300,7 @@ export function getMongoDBClientEncryption(): { * - `-1 = oid1 is less than oid2` * - `+0 = oid1 is equal oid2` */ -export function compareObjectId(oid1?: ObjectId, oid2?: ObjectId): 0 | 1 | -1 { +export function compareObjectId(oid1?: ObjectId | null, oid2?: ObjectId | null): 0 | 1 | -1 { if (oid1 == null && oid2 == null) { return 0; } From d30533981a1efc7d0e8ceac6dc55cfd09cf75dc1 Mon Sep 17 00:00:00 2001 From: Neal Beeken Date: Thu, 29 Sep 2022 15:49:10 -0400 Subject: [PATCH 5/7] test: add server version filtering --- src/sdam/topology_description.ts | 66 ++++-- .../rs/electionId_precedence_setVersion.json | 6 +- .../rs/electionId_precedence_setVersion.yml | 6 +- .../rs/null_election_id-pre-6.0.json | 203 ++++++++++++++++++ .../rs/null_election_id-pre-6.0.yml | 175 +++++++++++++++ .../rs/null_election_id.json | 8 +- .../rs/null_election_id.yml | 8 +- .../rs/pre-6.0-null_election_id.json | 203 ++++++++++++++++++ .../rs/pre-6.0-null_election_id.yml | 175 +++++++++++++++ .../rs/pre-6.0-secondary_ignore_ok_0.json | 83 +++++++ .../rs/pre-6.0-secondary_ignore_ok_0.yml | 87 ++++++++ ...pre-6.0-setversion_without_electionid.json | 84 ++++++++ .../pre-6.0-setversion_without_electionid.yml | 79 +++++++ ...6.0-use_setversion_without_electionid.json | 138 ++++++++++++ ...-6.0-use_setversion_without_electionid.yml | 117 ++++++++++ .../rs/secondary_ignore_ok_0-pre-6.0.json | 83 +++++++ .../rs/secondary_ignore_ok_0-pre-6.0.yml | 87 ++++++++ .../rs/set_version_can_rollback.json | 14 +- .../rs/set_version_can_rollback.yml | 16 +- ...tversion_equal_max_without_electionid.json | 4 +- ...etversion_equal_max_without_electionid.yml | 4 +- ...on_greaterthan_max_without_electionid.json | 4 +- ...ion_greaterthan_max_without_electionid.yml | 4 +- ...setversion_without_electionid-pre-6.0.json | 84 ++++++++ .../setversion_without_electionid-pre-6.0.yml | 79 +++++++ .../rs/setversion_without_electionid.json | 4 +- .../rs/setversion_without_electionid.yml | 4 +- ...setversion_without_electionid-pre-6.0.json | 138 ++++++++++++ ..._setversion_without_electionid-pre-6.0.yml | 117 ++++++++++ .../rs/use_setversion_without_electionid.json | 6 +- .../rs/use_setversion_without_electionid.yml | 6 +- 31 files changed, 2026 insertions(+), 66 deletions(-) create mode 100644 test/spec/server-discovery-and-monitoring/rs/null_election_id-pre-6.0.json create mode 100644 test/spec/server-discovery-and-monitoring/rs/null_election_id-pre-6.0.yml create mode 100644 test/spec/server-discovery-and-monitoring/rs/pre-6.0-null_election_id.json create mode 100644 test/spec/server-discovery-and-monitoring/rs/pre-6.0-null_election_id.yml create mode 100644 test/spec/server-discovery-and-monitoring/rs/pre-6.0-secondary_ignore_ok_0.json create mode 100644 test/spec/server-discovery-and-monitoring/rs/pre-6.0-secondary_ignore_ok_0.yml create mode 100644 test/spec/server-discovery-and-monitoring/rs/pre-6.0-setversion_without_electionid.json create mode 100644 test/spec/server-discovery-and-monitoring/rs/pre-6.0-setversion_without_electionid.yml create mode 100644 test/spec/server-discovery-and-monitoring/rs/pre-6.0-use_setversion_without_electionid.json create mode 100644 test/spec/server-discovery-and-monitoring/rs/pre-6.0-use_setversion_without_electionid.yml create mode 100644 test/spec/server-discovery-and-monitoring/rs/secondary_ignore_ok_0-pre-6.0.json create mode 100644 test/spec/server-discovery-and-monitoring/rs/secondary_ignore_ok_0-pre-6.0.yml create mode 100644 test/spec/server-discovery-and-monitoring/rs/setversion_without_electionid-pre-6.0.json create mode 100644 test/spec/server-discovery-and-monitoring/rs/setversion_without_electionid-pre-6.0.yml create mode 100644 test/spec/server-discovery-and-monitoring/rs/use_setversion_without_electionid-pre-6.0.json create mode 100644 test/spec/server-discovery-and-monitoring/rs/use_setversion_without_electionid-pre-6.0.yml diff --git a/src/sdam/topology_description.ts b/src/sdam/topology_description.ts index 40673ab1b2..d35a9ad6e6 100644 --- a/src/sdam/topology_description.ts +++ b/src/sdam/topology_description.ts @@ -373,26 +373,56 @@ function updateRsFromPrimary( return [checkHasPrimary(serverDescriptions), setName, maxSetVersion, maxElectionId]; } - const electionIdComparison = compareObjectId(maxElectionId, serverDescription.electionId); - const maxElectionIdIsEqual = electionIdComparison === 0; - const maxElectionIdIsLess = electionIdComparison === -1; - const maxSetVersionIsLessOrEqual = (maxSetVersion ?? -1) <= (serverDescription.setVersion ?? -1); - - if (maxElectionIdIsLess || (maxElectionIdIsEqual && maxSetVersionIsLessOrEqual)) { - // The reported electionId was greater - // or the electionId was equal and reported setVersion was greater - // Always update both values, they are a tuple - maxElectionId = serverDescription.electionId; - maxSetVersion = serverDescription.setVersion; + if (serverDescription.maxWireVersion >= 17) { + const electionIdComparison = compareObjectId(maxElectionId, serverDescription.electionId); + const maxElectionIdIsEqual = electionIdComparison === 0; + const maxElectionIdIsLess = electionIdComparison === -1; + const maxSetVersionIsLessOrEqual = + (maxSetVersion ?? -1) <= (serverDescription.setVersion ?? -1); + + if (maxElectionIdIsLess || (maxElectionIdIsEqual && maxSetVersionIsLessOrEqual)) { + // The reported electionId was greater + // or the electionId was equal and reported setVersion was greater + // Always update both values, they are a tuple + maxElectionId = serverDescription.electionId; + maxSetVersion = serverDescription.setVersion; + } else { + // Stale primary + // replace serverDescription with a default ServerDescription of type "Unknown" + serverDescriptions.set( + serverDescription.address, + new ServerDescription(serverDescription.address) + ); + + return [checkHasPrimary(serverDescriptions), setName, maxSetVersion, maxElectionId]; + } } else { - // Stale primary - // replace serverDescription with a default ServerDescription of type "Unknown" - serverDescriptions.set( - serverDescription.address, - new ServerDescription(serverDescription.address) - ); + const electionId = serverDescription.electionId ? serverDescription.electionId : null; + if (serverDescription.setVersion && electionId) { + if (maxSetVersion && maxElectionId) { + if ( + maxSetVersion > serverDescription.setVersion || + compareObjectId(maxElectionId, electionId) > 0 + ) { + // this primary is stale, we must remove it + serverDescriptions.set( + serverDescription.address, + new ServerDescription(serverDescription.address) + ); + + return [checkHasPrimary(serverDescriptions), setName, maxSetVersion, maxElectionId]; + } + } - return [checkHasPrimary(serverDescriptions), setName, maxSetVersion, maxElectionId]; + maxElectionId = serverDescription.electionId; + } + + if ( + serverDescription.setVersion != null && + (maxSetVersion == null || serverDescription.setVersion > maxSetVersion) + ) { + maxSetVersion = serverDescription.setVersion; + } } // We've heard from the primary. Is it the same primary as before? diff --git a/test/spec/server-discovery-and-monitoring/rs/electionId_precedence_setVersion.json b/test/spec/server-discovery-and-monitoring/rs/electionId_precedence_setVersion.json index a7b49e2b97..2fcea2bf66 100644 --- a/test/spec/server-discovery-and-monitoring/rs/electionId_precedence_setVersion.json +++ b/test/spec/server-discovery-and-monitoring/rs/electionId_precedence_setVersion.json @@ -20,7 +20,7 @@ "$oid": "000000000000000000000001" }, "minWireVersion": 0, - "maxWireVersion": 6 + "maxWireVersion": 17 } ], [ @@ -39,7 +39,7 @@ "$oid": "000000000000000000000001" }, "minWireVersion": 0, - "maxWireVersion": 6 + "maxWireVersion": 17 } ], [ @@ -58,7 +58,7 @@ "$oid": "000000000000000000000002" }, "minWireVersion": 0, - "maxWireVersion": 6 + "maxWireVersion": 17 } ] ], diff --git a/test/spec/server-discovery-and-monitoring/rs/electionId_precedence_setVersion.yml b/test/spec/server-discovery-and-monitoring/rs/electionId_precedence_setVersion.yml index e552e984c2..4b9563fcfd 100644 --- a/test/spec/server-discovery-and-monitoring/rs/electionId_precedence_setVersion.yml +++ b/test/spec/server-discovery-and-monitoring/rs/electionId_precedence_setVersion.yml @@ -14,7 +14,7 @@ phases: electionId: $oid: "000000000000000000000001" minWireVersion: 0 - maxWireVersion: 6 + maxWireVersion: 17 - - "b:27017" - ok: 1 helloOk: true @@ -27,7 +27,7 @@ phases: electionId: $oid: "000000000000000000000001" minWireVersion: 0 - maxWireVersion: 6 + maxWireVersion: 17 - - "a:27017" - ok: 1 helloOk: true @@ -40,7 +40,7 @@ phases: electionId: $oid: "000000000000000000000002" minWireVersion: 0 - maxWireVersion: 6 + maxWireVersion: 17 outcome: servers: "a:27017": diff --git a/test/spec/server-discovery-and-monitoring/rs/null_election_id-pre-6.0.json b/test/spec/server-discovery-and-monitoring/rs/null_election_id-pre-6.0.json new file mode 100644 index 0000000000..f1fa2e252e --- /dev/null +++ b/test/spec/server-discovery-and-monitoring/rs/null_election_id-pre-6.0.json @@ -0,0 +1,203 @@ +{ + "description": "Pre 6.0 Primaries with and without electionIds", + "uri": "mongodb://a/?replicaSet=rs", + "phases": [ + { + "responses": [ + [ + "a:27017", + { + "ok": 1, + "helloOk": true, + "isWritablePrimary": true, + "hosts": [ + "a:27017", + "b:27017", + "c:27017" + ], + "setVersion": 1, + "setName": "rs", + "minWireVersion": 0, + "maxWireVersion": 6 + } + ] + ], + "outcome": { + "servers": { + "a:27017": { + "type": "RSPrimary", + "setName": "rs", + "setVersion": 1, + "electionId": null + }, + "b:27017": { + "type": "Unknown", + "setName": null, + "electionId": null + }, + "c:27017": { + "type": "Unknown", + "setName": null, + "electionId": null + } + }, + "topologyType": "ReplicaSetWithPrimary", + "logicalSessionTimeoutMinutes": null, + "setName": "rs", + "maxSetVersion": 1 + } + }, + { + "responses": [ + [ + "b:27017", + { + "ok": 1, + "helloOk": true, + "isWritablePrimary": true, + "hosts": [ + "a:27017", + "b:27017", + "c:27017" + ], + "setName": "rs", + "setVersion": 1, + "electionId": { + "$oid": "000000000000000000000002" + }, + "minWireVersion": 0, + "maxWireVersion": 6 + } + ] + ], + "outcome": { + "servers": { + "a:27017": { + "type": "Unknown", + "setName": null, + "electionId": null + }, + "b:27017": { + "type": "RSPrimary", + "setName": "rs", + "setVersion": 1, + "electionId": { + "$oid": "000000000000000000000002" + } + }, + "c:27017": { + "type": "Unknown", + "setName": null, + "electionId": null + } + }, + "topologyType": "ReplicaSetWithPrimary", + "logicalSessionTimeoutMinutes": null, + "setName": "rs", + "maxSetVersion": 1, + "maxElectionId": { + "$oid": "000000000000000000000002" + } + } + }, + { + "responses": [ + [ + "a:27017", + { + "ok": 1, + "helloOk": true, + "isWritablePrimary": true, + "hosts": [ + "a:27017", + "b:27017", + "c:27017" + ], + "setVersion": 1, + "setName": "rs", + "minWireVersion": 0, + "maxWireVersion": 6 + } + ] + ], + "outcome": { + "servers": { + "a:27017": { + "type": "RSPrimary", + "setName": "rs", + "setVersion": 1, + "electionId": null + }, + "b:27017": { + "type": "Unknown", + "setName": null, + "electionId": null + }, + "c:27017": { + "type": "Unknown", + "setName": null, + "electionId": null + } + }, + "topologyType": "ReplicaSetWithPrimary", + "logicalSessionTimeoutMinutes": null, + "setName": "rs", + "maxSetVersion": 1, + "maxElectionId": { + "$oid": "000000000000000000000002" + } + } + }, + { + "responses": [ + [ + "c:27017", + { + "ok": 1, + "helloOk": true, + "isWritablePrimary": true, + "hosts": [ + "a:27017", + "b:27017", + "c:27017" + ], + "setName": "rs", + "setVersion": 1, + "electionId": { + "$oid": "000000000000000000000001" + }, + "minWireVersion": 0, + "maxWireVersion": 6 + } + ] + ], + "outcome": { + "servers": { + "a:27017": { + "type": "RSPrimary", + "setName": "rs", + "setVersion": 1, + "electionId": null + }, + "b:27017": { + "type": "Unknown", + "setName": null, + "electionId": null + }, + "c:27017": { + "type": "Unknown", + "setName": null, + "electionId": null + } + }, + "topologyType": "ReplicaSetWithPrimary", + "logicalSessionTimeoutMinutes": null, + "setName": "rs", + "maxSetVersion": 1, + "maxElectionId": { + "$oid": "000000000000000000000002" + } + } + } + ] +} diff --git a/test/spec/server-discovery-and-monitoring/rs/null_election_id-pre-6.0.yml b/test/spec/server-discovery-and-monitoring/rs/null_election_id-pre-6.0.yml new file mode 100644 index 0000000000..7e9bd55021 --- /dev/null +++ b/test/spec/server-discovery-and-monitoring/rs/null_election_id-pre-6.0.yml @@ -0,0 +1,175 @@ +description: "Pre 6.0 Primaries with and without electionIds" + +uri: "mongodb://a/?replicaSet=rs" + +phases: [ + + # Primary A has no electionId. + { + responses: [ + ["a:27017", { + ok: 1, + helloOk: true, + isWritablePrimary: true, + hosts: ["a:27017", "b:27017", "c:27017"], + setVersion: 1, + setName: "rs", + minWireVersion: 0, + maxWireVersion: 6 + }] + ], + + outcome: { + servers: { + "a:27017": { + type: "RSPrimary", + setName: "rs", + setVersion: 1, + electionId: + }, + "b:27017": { + type: "Unknown", + setName: , + electionId: + }, + "c:27017": { + type: "Unknown", + setName: , + electionId: + } + }, + topologyType: "ReplicaSetWithPrimary", + logicalSessionTimeoutMinutes: null, + setName: "rs", + maxSetVersion: 1, + } + }, + + # B is elected, it has an electionId. + { + responses: [ + ["b:27017", { + ok: 1, + helloOk: true, + isWritablePrimary: true, + hosts: ["a:27017", "b:27017", "c:27017"], + setName: "rs", + setVersion: 1, + electionId: {"$oid": "000000000000000000000002"}, + minWireVersion: 0, + maxWireVersion: 6 + }] + ], + + outcome: { + servers: { + "a:27017": { + type: "Unknown", + setName: , + electionId: + }, + "b:27017": { + type: "RSPrimary", + setName: "rs", + setVersion: 1, + electionId: {"$oid": "000000000000000000000002"} + }, + "c:27017": { + type: "Unknown", + setName: , + electionId: + } + }, + topologyType: "ReplicaSetWithPrimary", + logicalSessionTimeoutMinutes: null, + setName: "rs", + maxSetVersion: 1, + maxElectionId: {"$oid": "000000000000000000000002"}, + } + }, + + # A still claims to be primary, no electionId, we have to trust it. + { + responses: [ + ["a:27017", { + ok: 1, + helloOk: true, + isWritablePrimary: true, + hosts: ["a:27017", "b:27017", "c:27017"], + setVersion: 1, + setName: "rs", + minWireVersion: 0, + maxWireVersion: 6 + }] + ], + outcome: { + servers: { + "a:27017": { + type: "RSPrimary", + setName: "rs", + setVersion: 1, + electionId: + }, + "b:27017": { + type: "Unknown", + setName: , + electionId: + }, + "c:27017": { + type: "Unknown", + setName: , + electionId: + } + }, + topologyType: "ReplicaSetWithPrimary", + logicalSessionTimeoutMinutes: null, + setName: "rs", + maxSetVersion: 1, + maxElectionId: {"$oid": "000000000000000000000002"}, + } + }, + + # But we remember B's electionId, so when we finally hear from C + # claiming it is primary, we ignore it due to its outdated electionId + { + responses: [ + ["c:27017", { + ok: 1, + helloOk: true, + isWritablePrimary: true, + hosts: ["a:27017", "b:27017", "c:27017"], + setName: "rs", + setVersion: 1, + electionId: {"$oid": "000000000000000000000001"}, + minWireVersion: 0, + maxWireVersion: 6 + }] + ], + outcome: { + servers: { + # Still primary. + "a:27017": { + type: "RSPrimary", + setName: "rs", + setVersion: 1, + electionId: + }, + "b:27017": { + type: "Unknown", + setName: , + electionId: + }, + "c:27017": { + type: "Unknown", + setName: , + electionId: + } + }, + topologyType: "ReplicaSetWithPrimary", + logicalSessionTimeoutMinutes: null, + setName: "rs", + maxSetVersion: 1, + maxElectionId: {"$oid": "000000000000000000000002"}, + } + } +] diff --git a/test/spec/server-discovery-and-monitoring/rs/null_election_id.json b/test/spec/server-discovery-and-monitoring/rs/null_election_id.json index 8eb519595a..8a99a78475 100644 --- a/test/spec/server-discovery-and-monitoring/rs/null_election_id.json +++ b/test/spec/server-discovery-and-monitoring/rs/null_election_id.json @@ -18,7 +18,7 @@ "setVersion": 1, "setName": "rs", "minWireVersion": 0, - "maxWireVersion": 6 + "maxWireVersion": 17 } ] ], @@ -66,7 +66,7 @@ "$oid": "000000000000000000000002" }, "minWireVersion": 0, - "maxWireVersion": 6 + "maxWireVersion": 17 } ] ], @@ -116,7 +116,7 @@ "setVersion": 1, "setName": "rs", "minWireVersion": 0, - "maxWireVersion": 6 + "maxWireVersion": 17 } ] ], @@ -170,7 +170,7 @@ "$oid": "000000000000000000000001" }, "minWireVersion": 0, - "maxWireVersion": 6 + "maxWireVersion": 17 } ] ], diff --git a/test/spec/server-discovery-and-monitoring/rs/null_election_id.yml b/test/spec/server-discovery-and-monitoring/rs/null_election_id.yml index 9377285e43..54c1af272a 100644 --- a/test/spec/server-discovery-and-monitoring/rs/null_election_id.yml +++ b/test/spec/server-discovery-and-monitoring/rs/null_election_id.yml @@ -15,7 +15,7 @@ phases: [ setVersion: 1, setName: "rs", minWireVersion: 0, - maxWireVersion: 6 + maxWireVersion: 17 }] ], @@ -57,7 +57,7 @@ phases: [ setVersion: 1, electionId: {"$oid": "000000000000000000000002"}, minWireVersion: 0, - maxWireVersion: 6 + maxWireVersion: 17 }] ], @@ -99,7 +99,7 @@ phases: [ setVersion: 1, setName: "rs", minWireVersion: 0, - maxWireVersion: 6 + maxWireVersion: 17 }] ], outcome: { @@ -144,7 +144,7 @@ phases: [ setVersion: 1, electionId: {"$oid": "000000000000000000000001"}, minWireVersion: 0, - maxWireVersion: 6 + maxWireVersion: 17 }] ], outcome: { diff --git a/test/spec/server-discovery-and-monitoring/rs/pre-6.0-null_election_id.json b/test/spec/server-discovery-and-monitoring/rs/pre-6.0-null_election_id.json new file mode 100644 index 0000000000..f1fa2e252e --- /dev/null +++ b/test/spec/server-discovery-and-monitoring/rs/pre-6.0-null_election_id.json @@ -0,0 +1,203 @@ +{ + "description": "Pre 6.0 Primaries with and without electionIds", + "uri": "mongodb://a/?replicaSet=rs", + "phases": [ + { + "responses": [ + [ + "a:27017", + { + "ok": 1, + "helloOk": true, + "isWritablePrimary": true, + "hosts": [ + "a:27017", + "b:27017", + "c:27017" + ], + "setVersion": 1, + "setName": "rs", + "minWireVersion": 0, + "maxWireVersion": 6 + } + ] + ], + "outcome": { + "servers": { + "a:27017": { + "type": "RSPrimary", + "setName": "rs", + "setVersion": 1, + "electionId": null + }, + "b:27017": { + "type": "Unknown", + "setName": null, + "electionId": null + }, + "c:27017": { + "type": "Unknown", + "setName": null, + "electionId": null + } + }, + "topologyType": "ReplicaSetWithPrimary", + "logicalSessionTimeoutMinutes": null, + "setName": "rs", + "maxSetVersion": 1 + } + }, + { + "responses": [ + [ + "b:27017", + { + "ok": 1, + "helloOk": true, + "isWritablePrimary": true, + "hosts": [ + "a:27017", + "b:27017", + "c:27017" + ], + "setName": "rs", + "setVersion": 1, + "electionId": { + "$oid": "000000000000000000000002" + }, + "minWireVersion": 0, + "maxWireVersion": 6 + } + ] + ], + "outcome": { + "servers": { + "a:27017": { + "type": "Unknown", + "setName": null, + "electionId": null + }, + "b:27017": { + "type": "RSPrimary", + "setName": "rs", + "setVersion": 1, + "electionId": { + "$oid": "000000000000000000000002" + } + }, + "c:27017": { + "type": "Unknown", + "setName": null, + "electionId": null + } + }, + "topologyType": "ReplicaSetWithPrimary", + "logicalSessionTimeoutMinutes": null, + "setName": "rs", + "maxSetVersion": 1, + "maxElectionId": { + "$oid": "000000000000000000000002" + } + } + }, + { + "responses": [ + [ + "a:27017", + { + "ok": 1, + "helloOk": true, + "isWritablePrimary": true, + "hosts": [ + "a:27017", + "b:27017", + "c:27017" + ], + "setVersion": 1, + "setName": "rs", + "minWireVersion": 0, + "maxWireVersion": 6 + } + ] + ], + "outcome": { + "servers": { + "a:27017": { + "type": "RSPrimary", + "setName": "rs", + "setVersion": 1, + "electionId": null + }, + "b:27017": { + "type": "Unknown", + "setName": null, + "electionId": null + }, + "c:27017": { + "type": "Unknown", + "setName": null, + "electionId": null + } + }, + "topologyType": "ReplicaSetWithPrimary", + "logicalSessionTimeoutMinutes": null, + "setName": "rs", + "maxSetVersion": 1, + "maxElectionId": { + "$oid": "000000000000000000000002" + } + } + }, + { + "responses": [ + [ + "c:27017", + { + "ok": 1, + "helloOk": true, + "isWritablePrimary": true, + "hosts": [ + "a:27017", + "b:27017", + "c:27017" + ], + "setName": "rs", + "setVersion": 1, + "electionId": { + "$oid": "000000000000000000000001" + }, + "minWireVersion": 0, + "maxWireVersion": 6 + } + ] + ], + "outcome": { + "servers": { + "a:27017": { + "type": "RSPrimary", + "setName": "rs", + "setVersion": 1, + "electionId": null + }, + "b:27017": { + "type": "Unknown", + "setName": null, + "electionId": null + }, + "c:27017": { + "type": "Unknown", + "setName": null, + "electionId": null + } + }, + "topologyType": "ReplicaSetWithPrimary", + "logicalSessionTimeoutMinutes": null, + "setName": "rs", + "maxSetVersion": 1, + "maxElectionId": { + "$oid": "000000000000000000000002" + } + } + } + ] +} diff --git a/test/spec/server-discovery-and-monitoring/rs/pre-6.0-null_election_id.yml b/test/spec/server-discovery-and-monitoring/rs/pre-6.0-null_election_id.yml new file mode 100644 index 0000000000..7e9bd55021 --- /dev/null +++ b/test/spec/server-discovery-and-monitoring/rs/pre-6.0-null_election_id.yml @@ -0,0 +1,175 @@ +description: "Pre 6.0 Primaries with and without electionIds" + +uri: "mongodb://a/?replicaSet=rs" + +phases: [ + + # Primary A has no electionId. + { + responses: [ + ["a:27017", { + ok: 1, + helloOk: true, + isWritablePrimary: true, + hosts: ["a:27017", "b:27017", "c:27017"], + setVersion: 1, + setName: "rs", + minWireVersion: 0, + maxWireVersion: 6 + }] + ], + + outcome: { + servers: { + "a:27017": { + type: "RSPrimary", + setName: "rs", + setVersion: 1, + electionId: + }, + "b:27017": { + type: "Unknown", + setName: , + electionId: + }, + "c:27017": { + type: "Unknown", + setName: , + electionId: + } + }, + topologyType: "ReplicaSetWithPrimary", + logicalSessionTimeoutMinutes: null, + setName: "rs", + maxSetVersion: 1, + } + }, + + # B is elected, it has an electionId. + { + responses: [ + ["b:27017", { + ok: 1, + helloOk: true, + isWritablePrimary: true, + hosts: ["a:27017", "b:27017", "c:27017"], + setName: "rs", + setVersion: 1, + electionId: {"$oid": "000000000000000000000002"}, + minWireVersion: 0, + maxWireVersion: 6 + }] + ], + + outcome: { + servers: { + "a:27017": { + type: "Unknown", + setName: , + electionId: + }, + "b:27017": { + type: "RSPrimary", + setName: "rs", + setVersion: 1, + electionId: {"$oid": "000000000000000000000002"} + }, + "c:27017": { + type: "Unknown", + setName: , + electionId: + } + }, + topologyType: "ReplicaSetWithPrimary", + logicalSessionTimeoutMinutes: null, + setName: "rs", + maxSetVersion: 1, + maxElectionId: {"$oid": "000000000000000000000002"}, + } + }, + + # A still claims to be primary, no electionId, we have to trust it. + { + responses: [ + ["a:27017", { + ok: 1, + helloOk: true, + isWritablePrimary: true, + hosts: ["a:27017", "b:27017", "c:27017"], + setVersion: 1, + setName: "rs", + minWireVersion: 0, + maxWireVersion: 6 + }] + ], + outcome: { + servers: { + "a:27017": { + type: "RSPrimary", + setName: "rs", + setVersion: 1, + electionId: + }, + "b:27017": { + type: "Unknown", + setName: , + electionId: + }, + "c:27017": { + type: "Unknown", + setName: , + electionId: + } + }, + topologyType: "ReplicaSetWithPrimary", + logicalSessionTimeoutMinutes: null, + setName: "rs", + maxSetVersion: 1, + maxElectionId: {"$oid": "000000000000000000000002"}, + } + }, + + # But we remember B's electionId, so when we finally hear from C + # claiming it is primary, we ignore it due to its outdated electionId + { + responses: [ + ["c:27017", { + ok: 1, + helloOk: true, + isWritablePrimary: true, + hosts: ["a:27017", "b:27017", "c:27017"], + setName: "rs", + setVersion: 1, + electionId: {"$oid": "000000000000000000000001"}, + minWireVersion: 0, + maxWireVersion: 6 + }] + ], + outcome: { + servers: { + # Still primary. + "a:27017": { + type: "RSPrimary", + setName: "rs", + setVersion: 1, + electionId: + }, + "b:27017": { + type: "Unknown", + setName: , + electionId: + }, + "c:27017": { + type: "Unknown", + setName: , + electionId: + } + }, + topologyType: "ReplicaSetWithPrimary", + logicalSessionTimeoutMinutes: null, + setName: "rs", + maxSetVersion: 1, + maxElectionId: {"$oid": "000000000000000000000002"}, + } + } +] diff --git a/test/spec/server-discovery-and-monitoring/rs/pre-6.0-secondary_ignore_ok_0.json b/test/spec/server-discovery-and-monitoring/rs/pre-6.0-secondary_ignore_ok_0.json new file mode 100644 index 0000000000..054425c84c --- /dev/null +++ b/test/spec/server-discovery-and-monitoring/rs/pre-6.0-secondary_ignore_ok_0.json @@ -0,0 +1,83 @@ +{ + "description": "Pre 6.0 New primary", + "uri": "mongodb://a,b/?replicaSet=rs", + "phases": [ + { + "responses": [ + [ + "a:27017", + { + "ok": 1, + "helloOk": true, + "isWritablePrimary": true, + "setName": "rs", + "hosts": [ + "a:27017", + "b:27017" + ], + "minWireVersion": 0, + "maxWireVersion": 6 + } + ], + [ + "b:27017", + { + "ok": 1, + "helloOk": true, + "isWritablePrimary": false, + "secondary": true, + "setName": "rs", + "hosts": [ + "a:27017", + "b:27017" + ], + "minWireVersion": 0, + "maxWireVersion": 6 + } + ] + ], + "outcome": { + "servers": { + "a:27017": { + "type": "RSPrimary", + "setName": "rs" + }, + "b:27017": { + "type": "RSSecondary", + "setName": "rs" + } + }, + "topologyType": "ReplicaSetWithPrimary", + "logicalSessionTimeoutMinutes": null, + "setName": "rs" + } + }, + { + "responses": [ + [ + "b:27017", + { + "ok": 0, + "minWireVersion": 0, + "maxWireVersion": 6 + } + ] + ], + "outcome": { + "servers": { + "a:27017": { + "type": "RSPrimary", + "setName": "rs" + }, + "b:27017": { + "type": "Unknown", + "setName": null + } + }, + "topologyType": "ReplicaSetWithPrimary", + "logicalSessionTimeoutMinutes": null, + "setName": "rs" + } + } + ] +} diff --git a/test/spec/server-discovery-and-monitoring/rs/pre-6.0-secondary_ignore_ok_0.yml b/test/spec/server-discovery-and-monitoring/rs/pre-6.0-secondary_ignore_ok_0.yml new file mode 100644 index 0000000000..de9048d401 --- /dev/null +++ b/test/spec/server-discovery-and-monitoring/rs/pre-6.0-secondary_ignore_ok_0.yml @@ -0,0 +1,87 @@ +description: "Pre 6.0 New primary" + +uri: "mongodb://a,b/?replicaSet=rs" + +phases: [ + + { + responses: [ + + ["a:27017", { + + ok: 1, + helloOk: true, + isWritablePrimary: true, + setName: "rs", + hosts: ["a:27017", "b:27017"], + minWireVersion: 0, + maxWireVersion: 6 + }], + ["b:27017", { + + ok: 1, + helloOk: true, + isWritablePrimary: false, + secondary: true, + setName: "rs", + hosts: ["a:27017", "b:27017"], + minWireVersion: 0, + maxWireVersion: 6 + }] + ], + + outcome: { + + servers: { + + "a:27017": { + + type: "RSPrimary", + setName: "rs" + }, + + "b:27017": { + + type: "RSSecondary", + setName: "rs" + } + }, + topologyType: "ReplicaSetWithPrimary", + logicalSessionTimeoutMinutes: null, + setName: "rs" + } + }, + + { + responses: [ + + ["b:27017", { + + ok: 0, + minWireVersion: 0, + maxWireVersion: 6 + }] + ], + + outcome: { + + servers: { + "a:27017": { + + type: "RSPrimary", + setName: "rs" + }, + + "b:27017": { + + type: "Unknown", + setName: + } + + }, + topologyType: "ReplicaSetWithPrimary", + logicalSessionTimeoutMinutes: null, + setName: "rs" + } + } +] diff --git a/test/spec/server-discovery-and-monitoring/rs/pre-6.0-setversion_without_electionid.json b/test/spec/server-discovery-and-monitoring/rs/pre-6.0-setversion_without_electionid.json new file mode 100644 index 0000000000..c2e2fe5b9b --- /dev/null +++ b/test/spec/server-discovery-and-monitoring/rs/pre-6.0-setversion_without_electionid.json @@ -0,0 +1,84 @@ +{ + "description": "Pre 6.0 setVersion is ignored if there is no electionId", + "uri": "mongodb://a/?replicaSet=rs", + "phases": [ + { + "responses": [ + [ + "a:27017", + { + "ok": 1, + "helloOk": true, + "isWritablePrimary": true, + "hosts": [ + "a:27017", + "b:27017" + ], + "setName": "rs", + "setVersion": 2, + "minWireVersion": 0, + "maxWireVersion": 6 + } + ] + ], + "outcome": { + "servers": { + "a:27017": { + "type": "RSPrimary", + "setName": "rs", + "setVersion": 2, + "electionId": null + }, + "b:27017": { + "type": "Unknown", + "setName": null, + "electionId": null + } + }, + "topologyType": "ReplicaSetWithPrimary", + "logicalSessionTimeoutMinutes": null, + "setName": "rs", + "maxSetVersion": 2 + } + }, + { + "responses": [ + [ + "b:27017", + { + "ok": 1, + "helloOk": true, + "isWritablePrimary": true, + "hosts": [ + "a:27017", + "b:27017" + ], + "setName": "rs", + "setVersion": 1, + "minWireVersion": 0, + "maxWireVersion": 6 + } + ] + ], + "outcome": { + "servers": { + "a:27017": { + "type": "Unknown", + "setName": null, + "electionId": null + }, + "b:27017": { + "type": "RSPrimary", + "setName": "rs", + "setVersion": 1, + "electionId": null + } + }, + "topologyType": "ReplicaSetWithPrimary", + "logicalSessionTimeoutMinutes": null, + "setName": "rs", + "maxSetVersion": 2 + } + } + ] +} diff --git a/test/spec/server-discovery-and-monitoring/rs/pre-6.0-setversion_without_electionid.yml b/test/spec/server-discovery-and-monitoring/rs/pre-6.0-setversion_without_electionid.yml new file mode 100644 index 0000000000..54bfa4d256 --- /dev/null +++ b/test/spec/server-discovery-and-monitoring/rs/pre-6.0-setversion_without_electionid.yml @@ -0,0 +1,79 @@ +description: "Pre 6.0 setVersion is ignored if there is no electionId" + +uri: "mongodb://a/?replicaSet=rs" + +phases: [ + + # Primary A is discovered and tells us about B. + { + responses: [ + ["a:27017", { + ok: 1, + helloOk: true, + isWritablePrimary: true, + hosts: ["a:27017", "b:27017"], + setName: "rs", + setVersion: 2, + minWireVersion: 0, + maxWireVersion: 6 + }] + ], + + outcome: { + servers: { + "a:27017": { + type: "RSPrimary", + setName: "rs", + setVersion: 2 , + electionId: + }, + "b:27017": { + type: "Unknown", + setName: , + electionId: + } + }, + topologyType: "ReplicaSetWithPrimary", + logicalSessionTimeoutMinutes: null, + setName: "rs", + maxSetVersion: 2, + } + }, + + # B is elected, its setVersion is older but we believe it anyway, because + # setVersion is only used in conjunction with electionId. + { + responses: [ + ["b:27017", { + ok: 1, + helloOk: true, + isWritablePrimary: true, + hosts: ["a:27017", "b:27017"], + setName: "rs", + setVersion: 1, + minWireVersion: 0, + maxWireVersion: 6 + }] + ], + + outcome: { + servers: { + "a:27017": { + type: "Unknown", + setName: , + electionId: + }, + "b:27017": { + type: "RSPrimary", + setName: "rs", + setVersion: 1, + electionId: + } + }, + topologyType: "ReplicaSetWithPrimary", + logicalSessionTimeoutMinutes: null, + setName: "rs", + maxSetVersion: 2, + } + } +] diff --git a/test/spec/server-discovery-and-monitoring/rs/pre-6.0-use_setversion_without_electionid.json b/test/spec/server-discovery-and-monitoring/rs/pre-6.0-use_setversion_without_electionid.json new file mode 100644 index 0000000000..5c58b65614 --- /dev/null +++ b/test/spec/server-discovery-and-monitoring/rs/pre-6.0-use_setversion_without_electionid.json @@ -0,0 +1,138 @@ +{ + "description": "Pre 6.0 Record max setVersion, even from primary without electionId", + "uri": "mongodb://a/?replicaSet=rs", + "phases": [ + { + "responses": [ + [ + "a:27017", + { + "ok": 1, + "helloOk": true, + "isWritablePrimary": true, + "hosts": [ + "a:27017", + "b:27017" + ], + "setName": "rs", + "setVersion": 1, + "electionId": { + "$oid": "000000000000000000000001" + }, + "minWireVersion": 0, + "maxWireVersion": 6 + } + ] + ], + "outcome": { + "servers": { + "a:27017": { + "type": "RSPrimary", + "setName": "rs", + "setVersion": 1, + "electionId": { + "$oid": "000000000000000000000001" + } + }, + "b:27017": { + "type": "Unknown", + "setName": null, + "electionId": null + } + }, + "topologyType": "ReplicaSetWithPrimary", + "logicalSessionTimeoutMinutes": null, + "setName": "rs", + "maxSetVersion": 1, + "maxElectionId": { + "$oid": "000000000000000000000001" + } + } + }, + { + "responses": [ + [ + "b:27017", + { + "ok": 1, + "helloOk": true, + "isWritablePrimary": true, + "hosts": [ + "a:27017", + "b:27017" + ], + "setName": "rs", + "setVersion": 2, + "minWireVersion": 0, + "maxWireVersion": 6 + } + ] + ], + "outcome": { + "servers": { + "a:27017": { + "type": "Unknown", + "setName": null, + "electionId": null + }, + "b:27017": { + "type": "RSPrimary", + "setName": "rs", + "setVersion": 2 + } + }, + "topologyType": "ReplicaSetWithPrimary", + "logicalSessionTimeoutMinutes": null, + "setName": "rs", + "maxSetVersion": 2, + "maxElectionId": { + "$oid": "000000000000000000000001" + } + } + }, + { + "responses": [ + [ + "a:27017", + { + "ok": 1, + "helloOk": true, + "isWritablePrimary": true, + "hosts": [ + "a:27017", + "b:27017" + ], + "setName": "rs", + "setVersion": 1, + "electionId": { + "$oid": "000000000000000000000002" + }, + "minWireVersion": 0, + "maxWireVersion": 6 + } + ] + ], + "outcome": { + "servers": { + "a:27017": { + "type": "Unknown", + "setName": null, + "electionId": null + }, + "b:27017": { + "type": "RSPrimary", + "setName": "rs", + "setVersion": 2 + } + }, + "topologyType": "ReplicaSetWithPrimary", + "logicalSessionTimeoutMinutes": null, + "setName": "rs", + "maxSetVersion": 2, + "maxElectionId": { + "$oid": "000000000000000000000001" + } + } + } + ] +} diff --git a/test/spec/server-discovery-and-monitoring/rs/pre-6.0-use_setversion_without_electionid.yml b/test/spec/server-discovery-and-monitoring/rs/pre-6.0-use_setversion_without_electionid.yml new file mode 100644 index 0000000000..a0434eb45c --- /dev/null +++ b/test/spec/server-discovery-and-monitoring/rs/pre-6.0-use_setversion_without_electionid.yml @@ -0,0 +1,117 @@ +description: "Pre 6.0 Record max setVersion, even from primary without electionId" + +uri: "mongodb://a/?replicaSet=rs" + +phases: [ + + # Primary A has setVersion and electionId, tells us about B. + { + responses: [ + ["a:27017", { + ok: 1, + helloOk: true, + isWritablePrimary: true, + hosts: ["a:27017", "b:27017"], + setName: "rs", + setVersion: 1, + electionId: {"$oid": "000000000000000000000001"}, + minWireVersion: 0, + maxWireVersion: 6 + }] + ], + + outcome: { + servers: { + "a:27017": { + type: "RSPrimary", + setName: "rs", + setVersion: 1, + electionId: {"$oid": "000000000000000000000001"} + }, + "b:27017": { + type: "Unknown", + setName: , + electionId: + } + }, + topologyType: "ReplicaSetWithPrimary", + logicalSessionTimeoutMinutes: null, + setName: "rs", + maxSetVersion: 1, + maxElectionId: {"$oid": "000000000000000000000001"}, + } + }, + + # Reconfig the set and elect B, it has a new setVersion but no electionId. + { + responses: [ + ["b:27017", { + ok: 1, + helloOk: true, + isWritablePrimary: true, + hosts: ["a:27017", "b:27017"], + setName: "rs", + setVersion: 2, + minWireVersion: 0, + maxWireVersion: 6 + }] + ], + + outcome: { + servers: { + "a:27017": { + type: "Unknown", + setName: , + electionId: + }, + "b:27017": { + type: "RSPrimary", + setName: "rs", + setVersion: 2 + } + }, + topologyType: "ReplicaSetWithPrimary", + logicalSessionTimeoutMinutes: null, + setName: "rs", + maxSetVersion: 2, + maxElectionId: {"$oid": "000000000000000000000001"}, + } + }, + + # Delayed response from A, reporting its reelection. Its setVersion shows + # the election preceded B's so we ignore it. + { + responses: [ + ["a:27017", { + ok: 1, + helloOk: true, + isWritablePrimary: true, + hosts: ["a:27017", "b:27017"], + setName: "rs", + setVersion: 1, + electionId: {"$oid": "000000000000000000000002"}, + minWireVersion: 0, + maxWireVersion: 6 + }] + ], + outcome: { + servers: { + "a:27017": { + type: "Unknown", + setName: , + electionId: + }, + "b:27017": { + type: "RSPrimary", + setName: "rs", + setVersion: 2 + } + }, + topologyType: "ReplicaSetWithPrimary", + logicalSessionTimeoutMinutes: null, + setName: "rs", + maxSetVersion: 2, + maxElectionId: {"$oid": "000000000000000000000001"}, + } + } +] diff --git a/test/spec/server-discovery-and-monitoring/rs/secondary_ignore_ok_0-pre-6.0.json b/test/spec/server-discovery-and-monitoring/rs/secondary_ignore_ok_0-pre-6.0.json new file mode 100644 index 0000000000..054425c84c --- /dev/null +++ b/test/spec/server-discovery-and-monitoring/rs/secondary_ignore_ok_0-pre-6.0.json @@ -0,0 +1,83 @@ +{ + "description": "Pre 6.0 New primary", + "uri": "mongodb://a,b/?replicaSet=rs", + "phases": [ + { + "responses": [ + [ + "a:27017", + { + "ok": 1, + "helloOk": true, + "isWritablePrimary": true, + "setName": "rs", + "hosts": [ + "a:27017", + "b:27017" + ], + "minWireVersion": 0, + "maxWireVersion": 6 + } + ], + [ + "b:27017", + { + "ok": 1, + "helloOk": true, + "isWritablePrimary": false, + "secondary": true, + "setName": "rs", + "hosts": [ + "a:27017", + "b:27017" + ], + "minWireVersion": 0, + "maxWireVersion": 6 + } + ] + ], + "outcome": { + "servers": { + "a:27017": { + "type": "RSPrimary", + "setName": "rs" + }, + "b:27017": { + "type": "RSSecondary", + "setName": "rs" + } + }, + "topologyType": "ReplicaSetWithPrimary", + "logicalSessionTimeoutMinutes": null, + "setName": "rs" + } + }, + { + "responses": [ + [ + "b:27017", + { + "ok": 0, + "minWireVersion": 0, + "maxWireVersion": 6 + } + ] + ], + "outcome": { + "servers": { + "a:27017": { + "type": "RSPrimary", + "setName": "rs" + }, + "b:27017": { + "type": "Unknown", + "setName": null + } + }, + "topologyType": "ReplicaSetWithPrimary", + "logicalSessionTimeoutMinutes": null, + "setName": "rs" + } + } + ] +} diff --git a/test/spec/server-discovery-and-monitoring/rs/secondary_ignore_ok_0-pre-6.0.yml b/test/spec/server-discovery-and-monitoring/rs/secondary_ignore_ok_0-pre-6.0.yml new file mode 100644 index 0000000000..de9048d401 --- /dev/null +++ b/test/spec/server-discovery-and-monitoring/rs/secondary_ignore_ok_0-pre-6.0.yml @@ -0,0 +1,87 @@ +description: "Pre 6.0 New primary" + +uri: "mongodb://a,b/?replicaSet=rs" + +phases: [ + + { + responses: [ + + ["a:27017", { + + ok: 1, + helloOk: true, + isWritablePrimary: true, + setName: "rs", + hosts: ["a:27017", "b:27017"], + minWireVersion: 0, + maxWireVersion: 6 + }], + ["b:27017", { + + ok: 1, + helloOk: true, + isWritablePrimary: false, + secondary: true, + setName: "rs", + hosts: ["a:27017", "b:27017"], + minWireVersion: 0, + maxWireVersion: 6 + }] + ], + + outcome: { + + servers: { + + "a:27017": { + + type: "RSPrimary", + setName: "rs" + }, + + "b:27017": { + + type: "RSSecondary", + setName: "rs" + } + }, + topologyType: "ReplicaSetWithPrimary", + logicalSessionTimeoutMinutes: null, + setName: "rs" + } + }, + + { + responses: [ + + ["b:27017", { + + ok: 0, + minWireVersion: 0, + maxWireVersion: 6 + }] + ], + + outcome: { + + servers: { + "a:27017": { + + type: "RSPrimary", + setName: "rs" + }, + + "b:27017": { + + type: "Unknown", + setName: + } + + }, + topologyType: "ReplicaSetWithPrimary", + logicalSessionTimeoutMinutes: null, + setName: "rs" + } + } +] diff --git a/test/spec/server-discovery-and-monitoring/rs/set_version_can_rollback.json b/test/spec/server-discovery-and-monitoring/rs/set_version_can_rollback.json index 28ecbeefca..1cc608a344 100644 --- a/test/spec/server-discovery-and-monitoring/rs/set_version_can_rollback.json +++ b/test/spec/server-discovery-and-monitoring/rs/set_version_can_rollback.json @@ -8,7 +8,7 @@ "a:27017", { "ok": 1, - "hello": true, + "helloOk": true, "isWritablePrimary": true, "hosts": [ "a:27017", @@ -20,7 +20,7 @@ "$oid": "000000000000000000000001" }, "minWireVersion": 0, - "maxWireVersion": 6 + "maxWireVersion": 17 } ] ], @@ -50,13 +50,12 @@ } }, { - "_comment": "Response from new primary with newer election Id", "responses": [ [ "b:27017", { "ok": 1, - "hello": true, + "helloOk": true, "isWritablePrimary": true, "hosts": [ "a:27017", @@ -68,7 +67,7 @@ "$oid": "000000000000000000000002" }, "minWireVersion": 0, - "maxWireVersion": 6 + "maxWireVersion": 17 } ] ], @@ -98,13 +97,12 @@ } }, { - "_comment": "Response from stale primary", "responses": [ [ "a:27017", { "ok": 1, - "hello": true, + "helloOk": true, "isWritablePrimary": true, "hosts": [ "a:27017", @@ -116,7 +114,7 @@ "$oid": "000000000000000000000001" }, "minWireVersion": 0, - "maxWireVersion": 6 + "maxWireVersion": 17 } ] ], diff --git a/test/spec/server-discovery-and-monitoring/rs/set_version_can_rollback.yml b/test/spec/server-discovery-and-monitoring/rs/set_version_can_rollback.yml index ef91a074a6..c30a8660ec 100644 --- a/test/spec/server-discovery-and-monitoring/rs/set_version_can_rollback.yml +++ b/test/spec/server-discovery-and-monitoring/rs/set_version_can_rollback.yml @@ -4,7 +4,7 @@ phases: - responses: - - a:27017 - ok: 1 - hello: true + helloOk: true isWritablePrimary: true hosts: - a:27017 @@ -14,7 +14,7 @@ phases: electionId: $oid: '000000000000000000000001' minWireVersion: 0 - maxWireVersion: 6 + maxWireVersion: 17 outcome: servers: a:27017: @@ -33,11 +33,11 @@ phases: maxSetVersion: 2 maxElectionId: $oid: '000000000000000000000001' - - _comment: Response from new primary with newer election Id + - # Response from new primary with newer election Id responses: - - b:27017 - ok: 1 - hello: true + helloOk: true isWritablePrimary: true hosts: - a:27017 @@ -47,7 +47,7 @@ phases: electionId: $oid: '000000000000000000000002' minWireVersion: 0 - maxWireVersion: 6 + maxWireVersion: 17 outcome: servers: a:27017: @@ -66,11 +66,11 @@ phases: maxSetVersion: 1 maxElectionId: $oid: '000000000000000000000002' - - _comment: Response from stale primary + - # Response from stale primary responses: - - a:27017 - ok: 1 - hello: true + helloOk: true isWritablePrimary: true hosts: - a:27017 @@ -80,7 +80,7 @@ phases: electionId: $oid: '000000000000000000000001' minWireVersion: 0 - maxWireVersion: 6 + maxWireVersion: 17 outcome: servers: a:27017: diff --git a/test/spec/server-discovery-and-monitoring/rs/setversion_equal_max_without_electionid.json b/test/spec/server-discovery-and-monitoring/rs/setversion_equal_max_without_electionid.json index 91e84d4fa0..3669511c5a 100644 --- a/test/spec/server-discovery-and-monitoring/rs/setversion_equal_max_without_electionid.json +++ b/test/spec/server-discovery-and-monitoring/rs/setversion_equal_max_without_electionid.json @@ -17,7 +17,7 @@ "setName": "rs", "setVersion": 1, "minWireVersion": 0, - "maxWireVersion": 6 + "maxWireVersion": 17 } ] ], @@ -56,7 +56,7 @@ "setName": "rs", "setVersion": 1, "minWireVersion": 0, - "maxWireVersion": 6 + "maxWireVersion": 17 } ] ], diff --git a/test/spec/server-discovery-and-monitoring/rs/setversion_equal_max_without_electionid.yml b/test/spec/server-discovery-and-monitoring/rs/setversion_equal_max_without_electionid.yml index cdce70f030..3733a12e56 100644 --- a/test/spec/server-discovery-and-monitoring/rs/setversion_equal_max_without_electionid.yml +++ b/test/spec/server-discovery-and-monitoring/rs/setversion_equal_max_without_electionid.yml @@ -15,7 +15,7 @@ phases: [ setName: "rs", setVersion: 1, minWireVersion: 0, - maxWireVersion: 6 + maxWireVersion: 17 }] ], @@ -51,7 +51,7 @@ phases: [ setName: "rs", setVersion: 1, minWireVersion: 0, - maxWireVersion: 6 + maxWireVersion: 17 }] ], diff --git a/test/spec/server-discovery-and-monitoring/rs/setversion_greaterthan_max_without_electionid.json b/test/spec/server-discovery-and-monitoring/rs/setversion_greaterthan_max_without_electionid.json index b15fd5c1a7..97870d71d5 100644 --- a/test/spec/server-discovery-and-monitoring/rs/setversion_greaterthan_max_without_electionid.json +++ b/test/spec/server-discovery-and-monitoring/rs/setversion_greaterthan_max_without_electionid.json @@ -17,7 +17,7 @@ "setName": "rs", "setVersion": 1, "minWireVersion": 0, - "maxWireVersion": 6 + "maxWireVersion": 17 } ] ], @@ -56,7 +56,7 @@ "setName": "rs", "setVersion": 2, "minWireVersion": 0, - "maxWireVersion": 6 + "maxWireVersion": 17 } ] ], diff --git a/test/spec/server-discovery-and-monitoring/rs/setversion_greaterthan_max_without_electionid.yml b/test/spec/server-discovery-and-monitoring/rs/setversion_greaterthan_max_without_electionid.yml index 34150c4422..3252e0f611 100644 --- a/test/spec/server-discovery-and-monitoring/rs/setversion_greaterthan_max_without_electionid.yml +++ b/test/spec/server-discovery-and-monitoring/rs/setversion_greaterthan_max_without_electionid.yml @@ -15,7 +15,7 @@ phases: [ setName: "rs", setVersion: 1, minWireVersion: 0, - maxWireVersion: 6 + maxWireVersion: 17 }] ], @@ -52,7 +52,7 @@ phases: [ setName: "rs", setVersion: 2, minWireVersion: 0, - maxWireVersion: 6 + maxWireVersion: 17 }] ], diff --git a/test/spec/server-discovery-and-monitoring/rs/setversion_without_electionid-pre-6.0.json b/test/spec/server-discovery-and-monitoring/rs/setversion_without_electionid-pre-6.0.json new file mode 100644 index 0000000000..c2e2fe5b9b --- /dev/null +++ b/test/spec/server-discovery-and-monitoring/rs/setversion_without_electionid-pre-6.0.json @@ -0,0 +1,84 @@ +{ + "description": "Pre 6.0 setVersion is ignored if there is no electionId", + "uri": "mongodb://a/?replicaSet=rs", + "phases": [ + { + "responses": [ + [ + "a:27017", + { + "ok": 1, + "helloOk": true, + "isWritablePrimary": true, + "hosts": [ + "a:27017", + "b:27017" + ], + "setName": "rs", + "setVersion": 2, + "minWireVersion": 0, + "maxWireVersion": 6 + } + ] + ], + "outcome": { + "servers": { + "a:27017": { + "type": "RSPrimary", + "setName": "rs", + "setVersion": 2, + "electionId": null + }, + "b:27017": { + "type": "Unknown", + "setName": null, + "electionId": null + } + }, + "topologyType": "ReplicaSetWithPrimary", + "logicalSessionTimeoutMinutes": null, + "setName": "rs", + "maxSetVersion": 2 + } + }, + { + "responses": [ + [ + "b:27017", + { + "ok": 1, + "helloOk": true, + "isWritablePrimary": true, + "hosts": [ + "a:27017", + "b:27017" + ], + "setName": "rs", + "setVersion": 1, + "minWireVersion": 0, + "maxWireVersion": 6 + } + ] + ], + "outcome": { + "servers": { + "a:27017": { + "type": "Unknown", + "setName": null, + "electionId": null + }, + "b:27017": { + "type": "RSPrimary", + "setName": "rs", + "setVersion": 1, + "electionId": null + } + }, + "topologyType": "ReplicaSetWithPrimary", + "logicalSessionTimeoutMinutes": null, + "setName": "rs", + "maxSetVersion": 2 + } + } + ] +} diff --git a/test/spec/server-discovery-and-monitoring/rs/setversion_without_electionid-pre-6.0.yml b/test/spec/server-discovery-and-monitoring/rs/setversion_without_electionid-pre-6.0.yml new file mode 100644 index 0000000000..54bfa4d256 --- /dev/null +++ b/test/spec/server-discovery-and-monitoring/rs/setversion_without_electionid-pre-6.0.yml @@ -0,0 +1,79 @@ +description: "Pre 6.0 setVersion is ignored if there is no electionId" + +uri: "mongodb://a/?replicaSet=rs" + +phases: [ + + # Primary A is discovered and tells us about B. + { + responses: [ + ["a:27017", { + ok: 1, + helloOk: true, + isWritablePrimary: true, + hosts: ["a:27017", "b:27017"], + setName: "rs", + setVersion: 2, + minWireVersion: 0, + maxWireVersion: 6 + }] + ], + + outcome: { + servers: { + "a:27017": { + type: "RSPrimary", + setName: "rs", + setVersion: 2 , + electionId: + }, + "b:27017": { + type: "Unknown", + setName: , + electionId: + } + }, + topologyType: "ReplicaSetWithPrimary", + logicalSessionTimeoutMinutes: null, + setName: "rs", + maxSetVersion: 2, + } + }, + + # B is elected, its setVersion is older but we believe it anyway, because + # setVersion is only used in conjunction with electionId. + { + responses: [ + ["b:27017", { + ok: 1, + helloOk: true, + isWritablePrimary: true, + hosts: ["a:27017", "b:27017"], + setName: "rs", + setVersion: 1, + minWireVersion: 0, + maxWireVersion: 6 + }] + ], + + outcome: { + servers: { + "a:27017": { + type: "Unknown", + setName: , + electionId: + }, + "b:27017": { + type: "RSPrimary", + setName: "rs", + setVersion: 1, + electionId: + } + }, + topologyType: "ReplicaSetWithPrimary", + logicalSessionTimeoutMinutes: null, + setName: "rs", + maxSetVersion: 2, + } + } +] diff --git a/test/spec/server-discovery-and-monitoring/rs/setversion_without_electionid.json b/test/spec/server-discovery-and-monitoring/rs/setversion_without_electionid.json index f59c162ae1..256fafe108 100644 --- a/test/spec/server-discovery-and-monitoring/rs/setversion_without_electionid.json +++ b/test/spec/server-discovery-and-monitoring/rs/setversion_without_electionid.json @@ -17,7 +17,7 @@ "setName": "rs", "setVersion": 2, "minWireVersion": 0, - "maxWireVersion": 6 + "maxWireVersion": 17 } ] ], @@ -56,7 +56,7 @@ "setName": "rs", "setVersion": 1, "minWireVersion": 0, - "maxWireVersion": 6 + "maxWireVersion": 17 } ] ], diff --git a/test/spec/server-discovery-and-monitoring/rs/setversion_without_electionid.yml b/test/spec/server-discovery-and-monitoring/rs/setversion_without_electionid.yml index ea8f28c238..04992929a1 100644 --- a/test/spec/server-discovery-and-monitoring/rs/setversion_without_electionid.yml +++ b/test/spec/server-discovery-and-monitoring/rs/setversion_without_electionid.yml @@ -15,7 +15,7 @@ phases: [ setName: "rs", setVersion: 2, minWireVersion: 0, - maxWireVersion: 6 + maxWireVersion: 17 }] ], @@ -51,7 +51,7 @@ phases: [ setName: "rs", setVersion: 1, minWireVersion: 0, - maxWireVersion: 6 + maxWireVersion: 17 }] ], diff --git a/test/spec/server-discovery-and-monitoring/rs/use_setversion_without_electionid-pre-6.0.json b/test/spec/server-discovery-and-monitoring/rs/use_setversion_without_electionid-pre-6.0.json new file mode 100644 index 0000000000..5c58b65614 --- /dev/null +++ b/test/spec/server-discovery-and-monitoring/rs/use_setversion_without_electionid-pre-6.0.json @@ -0,0 +1,138 @@ +{ + "description": "Pre 6.0 Record max setVersion, even from primary without electionId", + "uri": "mongodb://a/?replicaSet=rs", + "phases": [ + { + "responses": [ + [ + "a:27017", + { + "ok": 1, + "helloOk": true, + "isWritablePrimary": true, + "hosts": [ + "a:27017", + "b:27017" + ], + "setName": "rs", + "setVersion": 1, + "electionId": { + "$oid": "000000000000000000000001" + }, + "minWireVersion": 0, + "maxWireVersion": 6 + } + ] + ], + "outcome": { + "servers": { + "a:27017": { + "type": "RSPrimary", + "setName": "rs", + "setVersion": 1, + "electionId": { + "$oid": "000000000000000000000001" + } + }, + "b:27017": { + "type": "Unknown", + "setName": null, + "electionId": null + } + }, + "topologyType": "ReplicaSetWithPrimary", + "logicalSessionTimeoutMinutes": null, + "setName": "rs", + "maxSetVersion": 1, + "maxElectionId": { + "$oid": "000000000000000000000001" + } + } + }, + { + "responses": [ + [ + "b:27017", + { + "ok": 1, + "helloOk": true, + "isWritablePrimary": true, + "hosts": [ + "a:27017", + "b:27017" + ], + "setName": "rs", + "setVersion": 2, + "minWireVersion": 0, + "maxWireVersion": 6 + } + ] + ], + "outcome": { + "servers": { + "a:27017": { + "type": "Unknown", + "setName": null, + "electionId": null + }, + "b:27017": { + "type": "RSPrimary", + "setName": "rs", + "setVersion": 2 + } + }, + "topologyType": "ReplicaSetWithPrimary", + "logicalSessionTimeoutMinutes": null, + "setName": "rs", + "maxSetVersion": 2, + "maxElectionId": { + "$oid": "000000000000000000000001" + } + } + }, + { + "responses": [ + [ + "a:27017", + { + "ok": 1, + "helloOk": true, + "isWritablePrimary": true, + "hosts": [ + "a:27017", + "b:27017" + ], + "setName": "rs", + "setVersion": 1, + "electionId": { + "$oid": "000000000000000000000002" + }, + "minWireVersion": 0, + "maxWireVersion": 6 + } + ] + ], + "outcome": { + "servers": { + "a:27017": { + "type": "Unknown", + "setName": null, + "electionId": null + }, + "b:27017": { + "type": "RSPrimary", + "setName": "rs", + "setVersion": 2 + } + }, + "topologyType": "ReplicaSetWithPrimary", + "logicalSessionTimeoutMinutes": null, + "setName": "rs", + "maxSetVersion": 2, + "maxElectionId": { + "$oid": "000000000000000000000001" + } + } + } + ] +} diff --git a/test/spec/server-discovery-and-monitoring/rs/use_setversion_without_electionid-pre-6.0.yml b/test/spec/server-discovery-and-monitoring/rs/use_setversion_without_electionid-pre-6.0.yml new file mode 100644 index 0000000000..a0434eb45c --- /dev/null +++ b/test/spec/server-discovery-and-monitoring/rs/use_setversion_without_electionid-pre-6.0.yml @@ -0,0 +1,117 @@ +description: "Pre 6.0 Record max setVersion, even from primary without electionId" + +uri: "mongodb://a/?replicaSet=rs" + +phases: [ + + # Primary A has setVersion and electionId, tells us about B. + { + responses: [ + ["a:27017", { + ok: 1, + helloOk: true, + isWritablePrimary: true, + hosts: ["a:27017", "b:27017"], + setName: "rs", + setVersion: 1, + electionId: {"$oid": "000000000000000000000001"}, + minWireVersion: 0, + maxWireVersion: 6 + }] + ], + + outcome: { + servers: { + "a:27017": { + type: "RSPrimary", + setName: "rs", + setVersion: 1, + electionId: {"$oid": "000000000000000000000001"} + }, + "b:27017": { + type: "Unknown", + setName: , + electionId: + } + }, + topologyType: "ReplicaSetWithPrimary", + logicalSessionTimeoutMinutes: null, + setName: "rs", + maxSetVersion: 1, + maxElectionId: {"$oid": "000000000000000000000001"}, + } + }, + + # Reconfig the set and elect B, it has a new setVersion but no electionId. + { + responses: [ + ["b:27017", { + ok: 1, + helloOk: true, + isWritablePrimary: true, + hosts: ["a:27017", "b:27017"], + setName: "rs", + setVersion: 2, + minWireVersion: 0, + maxWireVersion: 6 + }] + ], + + outcome: { + servers: { + "a:27017": { + type: "Unknown", + setName: , + electionId: + }, + "b:27017": { + type: "RSPrimary", + setName: "rs", + setVersion: 2 + } + }, + topologyType: "ReplicaSetWithPrimary", + logicalSessionTimeoutMinutes: null, + setName: "rs", + maxSetVersion: 2, + maxElectionId: {"$oid": "000000000000000000000001"}, + } + }, + + # Delayed response from A, reporting its reelection. Its setVersion shows + # the election preceded B's so we ignore it. + { + responses: [ + ["a:27017", { + ok: 1, + helloOk: true, + isWritablePrimary: true, + hosts: ["a:27017", "b:27017"], + setName: "rs", + setVersion: 1, + electionId: {"$oid": "000000000000000000000002"}, + minWireVersion: 0, + maxWireVersion: 6 + }] + ], + outcome: { + servers: { + "a:27017": { + type: "Unknown", + setName: , + electionId: + }, + "b:27017": { + type: "RSPrimary", + setName: "rs", + setVersion: 2 + } + }, + topologyType: "ReplicaSetWithPrimary", + logicalSessionTimeoutMinutes: null, + setName: "rs", + maxSetVersion: 2, + maxElectionId: {"$oid": "000000000000000000000001"}, + } + } +] diff --git a/test/spec/server-discovery-and-monitoring/rs/use_setversion_without_electionid.json b/test/spec/server-discovery-and-monitoring/rs/use_setversion_without_electionid.json index 6dd753d5d8..551f3e12c2 100644 --- a/test/spec/server-discovery-and-monitoring/rs/use_setversion_without_electionid.json +++ b/test/spec/server-discovery-and-monitoring/rs/use_setversion_without_electionid.json @@ -20,7 +20,7 @@ "$oid": "000000000000000000000001" }, "minWireVersion": 0, - "maxWireVersion": 6 + "maxWireVersion": 17 } ] ], @@ -64,7 +64,7 @@ "setName": "rs", "setVersion": 2, "minWireVersion": 0, - "maxWireVersion": 6 + "maxWireVersion": 17 } ] ], @@ -111,7 +111,7 @@ "$oid": "000000000000000000000002" }, "minWireVersion": 0, - "maxWireVersion": 6 + "maxWireVersion": 17 } ] ], diff --git a/test/spec/server-discovery-and-monitoring/rs/use_setversion_without_electionid.yml b/test/spec/server-discovery-and-monitoring/rs/use_setversion_without_electionid.yml index 669ec20d43..68c88bc503 100644 --- a/test/spec/server-discovery-and-monitoring/rs/use_setversion_without_electionid.yml +++ b/test/spec/server-discovery-and-monitoring/rs/use_setversion_without_electionid.yml @@ -16,7 +16,7 @@ phases: [ setVersion: 1, electionId: {"$oid": "000000000000000000000001"}, minWireVersion: 0, - maxWireVersion: 6 + maxWireVersion: 17 }] ], @@ -53,7 +53,7 @@ phases: [ setName: "rs", setVersion: 2, minWireVersion: 0, - maxWireVersion: 6 + maxWireVersion: 17 }] ], @@ -92,7 +92,7 @@ phases: [ setVersion: 1, electionId: {"$oid": "000000000000000000000002"}, minWireVersion: 0, - maxWireVersion: 6 + maxWireVersion: 17 }] ], outcome: { From a6f406e14c89b6e8207d85af11fd471d0f66795d Mon Sep 17 00:00:00 2001 From: Neal Beeken Date: Tue, 4 Oct 2022 09:53:16 -0400 Subject: [PATCH 6/7] rm prefixed tests, only post fixed test names --- .../rs/pre-6.0-null_election_id.json | 203 ------------------ .../rs/pre-6.0-null_election_id.yml | 175 --------------- .../rs/pre-6.0-secondary_ignore_ok_0.json | 83 ------- .../rs/pre-6.0-secondary_ignore_ok_0.yml | 87 -------- ...pre-6.0-setversion_without_electionid.json | 84 -------- .../pre-6.0-setversion_without_electionid.yml | 79 ------- ...6.0-use_setversion_without_electionid.json | 138 ------------ ...-6.0-use_setversion_without_electionid.yml | 117 ---------- 8 files changed, 966 deletions(-) delete mode 100644 test/spec/server-discovery-and-monitoring/rs/pre-6.0-null_election_id.json delete mode 100644 test/spec/server-discovery-and-monitoring/rs/pre-6.0-null_election_id.yml delete mode 100644 test/spec/server-discovery-and-monitoring/rs/pre-6.0-secondary_ignore_ok_0.json delete mode 100644 test/spec/server-discovery-and-monitoring/rs/pre-6.0-secondary_ignore_ok_0.yml delete mode 100644 test/spec/server-discovery-and-monitoring/rs/pre-6.0-setversion_without_electionid.json delete mode 100644 test/spec/server-discovery-and-monitoring/rs/pre-6.0-setversion_without_electionid.yml delete mode 100644 test/spec/server-discovery-and-monitoring/rs/pre-6.0-use_setversion_without_electionid.json delete mode 100644 test/spec/server-discovery-and-monitoring/rs/pre-6.0-use_setversion_without_electionid.yml diff --git a/test/spec/server-discovery-and-monitoring/rs/pre-6.0-null_election_id.json b/test/spec/server-discovery-and-monitoring/rs/pre-6.0-null_election_id.json deleted file mode 100644 index f1fa2e252e..0000000000 --- a/test/spec/server-discovery-and-monitoring/rs/pre-6.0-null_election_id.json +++ /dev/null @@ -1,203 +0,0 @@ -{ - "description": "Pre 6.0 Primaries with and without electionIds", - "uri": "mongodb://a/?replicaSet=rs", - "phases": [ - { - "responses": [ - [ - "a:27017", - { - "ok": 1, - "helloOk": true, - "isWritablePrimary": true, - "hosts": [ - "a:27017", - "b:27017", - "c:27017" - ], - "setVersion": 1, - "setName": "rs", - "minWireVersion": 0, - "maxWireVersion": 6 - } - ] - ], - "outcome": { - "servers": { - "a:27017": { - "type": "RSPrimary", - "setName": "rs", - "setVersion": 1, - "electionId": null - }, - "b:27017": { - "type": "Unknown", - "setName": null, - "electionId": null - }, - "c:27017": { - "type": "Unknown", - "setName": null, - "electionId": null - } - }, - "topologyType": "ReplicaSetWithPrimary", - "logicalSessionTimeoutMinutes": null, - "setName": "rs", - "maxSetVersion": 1 - } - }, - { - "responses": [ - [ - "b:27017", - { - "ok": 1, - "helloOk": true, - "isWritablePrimary": true, - "hosts": [ - "a:27017", - "b:27017", - "c:27017" - ], - "setName": "rs", - "setVersion": 1, - "electionId": { - "$oid": "000000000000000000000002" - }, - "minWireVersion": 0, - "maxWireVersion": 6 - } - ] - ], - "outcome": { - "servers": { - "a:27017": { - "type": "Unknown", - "setName": null, - "electionId": null - }, - "b:27017": { - "type": "RSPrimary", - "setName": "rs", - "setVersion": 1, - "electionId": { - "$oid": "000000000000000000000002" - } - }, - "c:27017": { - "type": "Unknown", - "setName": null, - "electionId": null - } - }, - "topologyType": "ReplicaSetWithPrimary", - "logicalSessionTimeoutMinutes": null, - "setName": "rs", - "maxSetVersion": 1, - "maxElectionId": { - "$oid": "000000000000000000000002" - } - } - }, - { - "responses": [ - [ - "a:27017", - { - "ok": 1, - "helloOk": true, - "isWritablePrimary": true, - "hosts": [ - "a:27017", - "b:27017", - "c:27017" - ], - "setVersion": 1, - "setName": "rs", - "minWireVersion": 0, - "maxWireVersion": 6 - } - ] - ], - "outcome": { - "servers": { - "a:27017": { - "type": "RSPrimary", - "setName": "rs", - "setVersion": 1, - "electionId": null - }, - "b:27017": { - "type": "Unknown", - "setName": null, - "electionId": null - }, - "c:27017": { - "type": "Unknown", - "setName": null, - "electionId": null - } - }, - "topologyType": "ReplicaSetWithPrimary", - "logicalSessionTimeoutMinutes": null, - "setName": "rs", - "maxSetVersion": 1, - "maxElectionId": { - "$oid": "000000000000000000000002" - } - } - }, - { - "responses": [ - [ - "c:27017", - { - "ok": 1, - "helloOk": true, - "isWritablePrimary": true, - "hosts": [ - "a:27017", - "b:27017", - "c:27017" - ], - "setName": "rs", - "setVersion": 1, - "electionId": { - "$oid": "000000000000000000000001" - }, - "minWireVersion": 0, - "maxWireVersion": 6 - } - ] - ], - "outcome": { - "servers": { - "a:27017": { - "type": "RSPrimary", - "setName": "rs", - "setVersion": 1, - "electionId": null - }, - "b:27017": { - "type": "Unknown", - "setName": null, - "electionId": null - }, - "c:27017": { - "type": "Unknown", - "setName": null, - "electionId": null - } - }, - "topologyType": "ReplicaSetWithPrimary", - "logicalSessionTimeoutMinutes": null, - "setName": "rs", - "maxSetVersion": 1, - "maxElectionId": { - "$oid": "000000000000000000000002" - } - } - } - ] -} diff --git a/test/spec/server-discovery-and-monitoring/rs/pre-6.0-null_election_id.yml b/test/spec/server-discovery-and-monitoring/rs/pre-6.0-null_election_id.yml deleted file mode 100644 index 7e9bd55021..0000000000 --- a/test/spec/server-discovery-and-monitoring/rs/pre-6.0-null_election_id.yml +++ /dev/null @@ -1,175 +0,0 @@ -description: "Pre 6.0 Primaries with and without electionIds" - -uri: "mongodb://a/?replicaSet=rs" - -phases: [ - - # Primary A has no electionId. - { - responses: [ - ["a:27017", { - ok: 1, - helloOk: true, - isWritablePrimary: true, - hosts: ["a:27017", "b:27017", "c:27017"], - setVersion: 1, - setName: "rs", - minWireVersion: 0, - maxWireVersion: 6 - }] - ], - - outcome: { - servers: { - "a:27017": { - type: "RSPrimary", - setName: "rs", - setVersion: 1, - electionId: - }, - "b:27017": { - type: "Unknown", - setName: , - electionId: - }, - "c:27017": { - type: "Unknown", - setName: , - electionId: - } - }, - topologyType: "ReplicaSetWithPrimary", - logicalSessionTimeoutMinutes: null, - setName: "rs", - maxSetVersion: 1, - } - }, - - # B is elected, it has an electionId. - { - responses: [ - ["b:27017", { - ok: 1, - helloOk: true, - isWritablePrimary: true, - hosts: ["a:27017", "b:27017", "c:27017"], - setName: "rs", - setVersion: 1, - electionId: {"$oid": "000000000000000000000002"}, - minWireVersion: 0, - maxWireVersion: 6 - }] - ], - - outcome: { - servers: { - "a:27017": { - type: "Unknown", - setName: , - electionId: - }, - "b:27017": { - type: "RSPrimary", - setName: "rs", - setVersion: 1, - electionId: {"$oid": "000000000000000000000002"} - }, - "c:27017": { - type: "Unknown", - setName: , - electionId: - } - }, - topologyType: "ReplicaSetWithPrimary", - logicalSessionTimeoutMinutes: null, - setName: "rs", - maxSetVersion: 1, - maxElectionId: {"$oid": "000000000000000000000002"}, - } - }, - - # A still claims to be primary, no electionId, we have to trust it. - { - responses: [ - ["a:27017", { - ok: 1, - helloOk: true, - isWritablePrimary: true, - hosts: ["a:27017", "b:27017", "c:27017"], - setVersion: 1, - setName: "rs", - minWireVersion: 0, - maxWireVersion: 6 - }] - ], - outcome: { - servers: { - "a:27017": { - type: "RSPrimary", - setName: "rs", - setVersion: 1, - electionId: - }, - "b:27017": { - type: "Unknown", - setName: , - electionId: - }, - "c:27017": { - type: "Unknown", - setName: , - electionId: - } - }, - topologyType: "ReplicaSetWithPrimary", - logicalSessionTimeoutMinutes: null, - setName: "rs", - maxSetVersion: 1, - maxElectionId: {"$oid": "000000000000000000000002"}, - } - }, - - # But we remember B's electionId, so when we finally hear from C - # claiming it is primary, we ignore it due to its outdated electionId - { - responses: [ - ["c:27017", { - ok: 1, - helloOk: true, - isWritablePrimary: true, - hosts: ["a:27017", "b:27017", "c:27017"], - setName: "rs", - setVersion: 1, - electionId: {"$oid": "000000000000000000000001"}, - minWireVersion: 0, - maxWireVersion: 6 - }] - ], - outcome: { - servers: { - # Still primary. - "a:27017": { - type: "RSPrimary", - setName: "rs", - setVersion: 1, - electionId: - }, - "b:27017": { - type: "Unknown", - setName: , - electionId: - }, - "c:27017": { - type: "Unknown", - setName: , - electionId: - } - }, - topologyType: "ReplicaSetWithPrimary", - logicalSessionTimeoutMinutes: null, - setName: "rs", - maxSetVersion: 1, - maxElectionId: {"$oid": "000000000000000000000002"}, - } - } -] diff --git a/test/spec/server-discovery-and-monitoring/rs/pre-6.0-secondary_ignore_ok_0.json b/test/spec/server-discovery-and-monitoring/rs/pre-6.0-secondary_ignore_ok_0.json deleted file mode 100644 index 054425c84c..0000000000 --- a/test/spec/server-discovery-and-monitoring/rs/pre-6.0-secondary_ignore_ok_0.json +++ /dev/null @@ -1,83 +0,0 @@ -{ - "description": "Pre 6.0 New primary", - "uri": "mongodb://a,b/?replicaSet=rs", - "phases": [ - { - "responses": [ - [ - "a:27017", - { - "ok": 1, - "helloOk": true, - "isWritablePrimary": true, - "setName": "rs", - "hosts": [ - "a:27017", - "b:27017" - ], - "minWireVersion": 0, - "maxWireVersion": 6 - } - ], - [ - "b:27017", - { - "ok": 1, - "helloOk": true, - "isWritablePrimary": false, - "secondary": true, - "setName": "rs", - "hosts": [ - "a:27017", - "b:27017" - ], - "minWireVersion": 0, - "maxWireVersion": 6 - } - ] - ], - "outcome": { - "servers": { - "a:27017": { - "type": "RSPrimary", - "setName": "rs" - }, - "b:27017": { - "type": "RSSecondary", - "setName": "rs" - } - }, - "topologyType": "ReplicaSetWithPrimary", - "logicalSessionTimeoutMinutes": null, - "setName": "rs" - } - }, - { - "responses": [ - [ - "b:27017", - { - "ok": 0, - "minWireVersion": 0, - "maxWireVersion": 6 - } - ] - ], - "outcome": { - "servers": { - "a:27017": { - "type": "RSPrimary", - "setName": "rs" - }, - "b:27017": { - "type": "Unknown", - "setName": null - } - }, - "topologyType": "ReplicaSetWithPrimary", - "logicalSessionTimeoutMinutes": null, - "setName": "rs" - } - } - ] -} diff --git a/test/spec/server-discovery-and-monitoring/rs/pre-6.0-secondary_ignore_ok_0.yml b/test/spec/server-discovery-and-monitoring/rs/pre-6.0-secondary_ignore_ok_0.yml deleted file mode 100644 index de9048d401..0000000000 --- a/test/spec/server-discovery-and-monitoring/rs/pre-6.0-secondary_ignore_ok_0.yml +++ /dev/null @@ -1,87 +0,0 @@ -description: "Pre 6.0 New primary" - -uri: "mongodb://a,b/?replicaSet=rs" - -phases: [ - - { - responses: [ - - ["a:27017", { - - ok: 1, - helloOk: true, - isWritablePrimary: true, - setName: "rs", - hosts: ["a:27017", "b:27017"], - minWireVersion: 0, - maxWireVersion: 6 - }], - ["b:27017", { - - ok: 1, - helloOk: true, - isWritablePrimary: false, - secondary: true, - setName: "rs", - hosts: ["a:27017", "b:27017"], - minWireVersion: 0, - maxWireVersion: 6 - }] - ], - - outcome: { - - servers: { - - "a:27017": { - - type: "RSPrimary", - setName: "rs" - }, - - "b:27017": { - - type: "RSSecondary", - setName: "rs" - } - }, - topologyType: "ReplicaSetWithPrimary", - logicalSessionTimeoutMinutes: null, - setName: "rs" - } - }, - - { - responses: [ - - ["b:27017", { - - ok: 0, - minWireVersion: 0, - maxWireVersion: 6 - }] - ], - - outcome: { - - servers: { - "a:27017": { - - type: "RSPrimary", - setName: "rs" - }, - - "b:27017": { - - type: "Unknown", - setName: - } - - }, - topologyType: "ReplicaSetWithPrimary", - logicalSessionTimeoutMinutes: null, - setName: "rs" - } - } -] diff --git a/test/spec/server-discovery-and-monitoring/rs/pre-6.0-setversion_without_electionid.json b/test/spec/server-discovery-and-monitoring/rs/pre-6.0-setversion_without_electionid.json deleted file mode 100644 index c2e2fe5b9b..0000000000 --- a/test/spec/server-discovery-and-monitoring/rs/pre-6.0-setversion_without_electionid.json +++ /dev/null @@ -1,84 +0,0 @@ -{ - "description": "Pre 6.0 setVersion is ignored if there is no electionId", - "uri": "mongodb://a/?replicaSet=rs", - "phases": [ - { - "responses": [ - [ - "a:27017", - { - "ok": 1, - "helloOk": true, - "isWritablePrimary": true, - "hosts": [ - "a:27017", - "b:27017" - ], - "setName": "rs", - "setVersion": 2, - "minWireVersion": 0, - "maxWireVersion": 6 - } - ] - ], - "outcome": { - "servers": { - "a:27017": { - "type": "RSPrimary", - "setName": "rs", - "setVersion": 2, - "electionId": null - }, - "b:27017": { - "type": "Unknown", - "setName": null, - "electionId": null - } - }, - "topologyType": "ReplicaSetWithPrimary", - "logicalSessionTimeoutMinutes": null, - "setName": "rs", - "maxSetVersion": 2 - } - }, - { - "responses": [ - [ - "b:27017", - { - "ok": 1, - "helloOk": true, - "isWritablePrimary": true, - "hosts": [ - "a:27017", - "b:27017" - ], - "setName": "rs", - "setVersion": 1, - "minWireVersion": 0, - "maxWireVersion": 6 - } - ] - ], - "outcome": { - "servers": { - "a:27017": { - "type": "Unknown", - "setName": null, - "electionId": null - }, - "b:27017": { - "type": "RSPrimary", - "setName": "rs", - "setVersion": 1, - "electionId": null - } - }, - "topologyType": "ReplicaSetWithPrimary", - "logicalSessionTimeoutMinutes": null, - "setName": "rs", - "maxSetVersion": 2 - } - } - ] -} diff --git a/test/spec/server-discovery-and-monitoring/rs/pre-6.0-setversion_without_electionid.yml b/test/spec/server-discovery-and-monitoring/rs/pre-6.0-setversion_without_electionid.yml deleted file mode 100644 index 54bfa4d256..0000000000 --- a/test/spec/server-discovery-and-monitoring/rs/pre-6.0-setversion_without_electionid.yml +++ /dev/null @@ -1,79 +0,0 @@ -description: "Pre 6.0 setVersion is ignored if there is no electionId" - -uri: "mongodb://a/?replicaSet=rs" - -phases: [ - - # Primary A is discovered and tells us about B. - { - responses: [ - ["a:27017", { - ok: 1, - helloOk: true, - isWritablePrimary: true, - hosts: ["a:27017", "b:27017"], - setName: "rs", - setVersion: 2, - minWireVersion: 0, - maxWireVersion: 6 - }] - ], - - outcome: { - servers: { - "a:27017": { - type: "RSPrimary", - setName: "rs", - setVersion: 2 , - electionId: - }, - "b:27017": { - type: "Unknown", - setName: , - electionId: - } - }, - topologyType: "ReplicaSetWithPrimary", - logicalSessionTimeoutMinutes: null, - setName: "rs", - maxSetVersion: 2, - } - }, - - # B is elected, its setVersion is older but we believe it anyway, because - # setVersion is only used in conjunction with electionId. - { - responses: [ - ["b:27017", { - ok: 1, - helloOk: true, - isWritablePrimary: true, - hosts: ["a:27017", "b:27017"], - setName: "rs", - setVersion: 1, - minWireVersion: 0, - maxWireVersion: 6 - }] - ], - - outcome: { - servers: { - "a:27017": { - type: "Unknown", - setName: , - electionId: - }, - "b:27017": { - type: "RSPrimary", - setName: "rs", - setVersion: 1, - electionId: - } - }, - topologyType: "ReplicaSetWithPrimary", - logicalSessionTimeoutMinutes: null, - setName: "rs", - maxSetVersion: 2, - } - } -] diff --git a/test/spec/server-discovery-and-monitoring/rs/pre-6.0-use_setversion_without_electionid.json b/test/spec/server-discovery-and-monitoring/rs/pre-6.0-use_setversion_without_electionid.json deleted file mode 100644 index 5c58b65614..0000000000 --- a/test/spec/server-discovery-and-monitoring/rs/pre-6.0-use_setversion_without_electionid.json +++ /dev/null @@ -1,138 +0,0 @@ -{ - "description": "Pre 6.0 Record max setVersion, even from primary without electionId", - "uri": "mongodb://a/?replicaSet=rs", - "phases": [ - { - "responses": [ - [ - "a:27017", - { - "ok": 1, - "helloOk": true, - "isWritablePrimary": true, - "hosts": [ - "a:27017", - "b:27017" - ], - "setName": "rs", - "setVersion": 1, - "electionId": { - "$oid": "000000000000000000000001" - }, - "minWireVersion": 0, - "maxWireVersion": 6 - } - ] - ], - "outcome": { - "servers": { - "a:27017": { - "type": "RSPrimary", - "setName": "rs", - "setVersion": 1, - "electionId": { - "$oid": "000000000000000000000001" - } - }, - "b:27017": { - "type": "Unknown", - "setName": null, - "electionId": null - } - }, - "topologyType": "ReplicaSetWithPrimary", - "logicalSessionTimeoutMinutes": null, - "setName": "rs", - "maxSetVersion": 1, - "maxElectionId": { - "$oid": "000000000000000000000001" - } - } - }, - { - "responses": [ - [ - "b:27017", - { - "ok": 1, - "helloOk": true, - "isWritablePrimary": true, - "hosts": [ - "a:27017", - "b:27017" - ], - "setName": "rs", - "setVersion": 2, - "minWireVersion": 0, - "maxWireVersion": 6 - } - ] - ], - "outcome": { - "servers": { - "a:27017": { - "type": "Unknown", - "setName": null, - "electionId": null - }, - "b:27017": { - "type": "RSPrimary", - "setName": "rs", - "setVersion": 2 - } - }, - "topologyType": "ReplicaSetWithPrimary", - "logicalSessionTimeoutMinutes": null, - "setName": "rs", - "maxSetVersion": 2, - "maxElectionId": { - "$oid": "000000000000000000000001" - } - } - }, - { - "responses": [ - [ - "a:27017", - { - "ok": 1, - "helloOk": true, - "isWritablePrimary": true, - "hosts": [ - "a:27017", - "b:27017" - ], - "setName": "rs", - "setVersion": 1, - "electionId": { - "$oid": "000000000000000000000002" - }, - "minWireVersion": 0, - "maxWireVersion": 6 - } - ] - ], - "outcome": { - "servers": { - "a:27017": { - "type": "Unknown", - "setName": null, - "electionId": null - }, - "b:27017": { - "type": "RSPrimary", - "setName": "rs", - "setVersion": 2 - } - }, - "topologyType": "ReplicaSetWithPrimary", - "logicalSessionTimeoutMinutes": null, - "setName": "rs", - "maxSetVersion": 2, - "maxElectionId": { - "$oid": "000000000000000000000001" - } - } - } - ] -} diff --git a/test/spec/server-discovery-and-monitoring/rs/pre-6.0-use_setversion_without_electionid.yml b/test/spec/server-discovery-and-monitoring/rs/pre-6.0-use_setversion_without_electionid.yml deleted file mode 100644 index a0434eb45c..0000000000 --- a/test/spec/server-discovery-and-monitoring/rs/pre-6.0-use_setversion_without_electionid.yml +++ /dev/null @@ -1,117 +0,0 @@ -description: "Pre 6.0 Record max setVersion, even from primary without electionId" - -uri: "mongodb://a/?replicaSet=rs" - -phases: [ - - # Primary A has setVersion and electionId, tells us about B. - { - responses: [ - ["a:27017", { - ok: 1, - helloOk: true, - isWritablePrimary: true, - hosts: ["a:27017", "b:27017"], - setName: "rs", - setVersion: 1, - electionId: {"$oid": "000000000000000000000001"}, - minWireVersion: 0, - maxWireVersion: 6 - }] - ], - - outcome: { - servers: { - "a:27017": { - type: "RSPrimary", - setName: "rs", - setVersion: 1, - electionId: {"$oid": "000000000000000000000001"} - }, - "b:27017": { - type: "Unknown", - setName: , - electionId: - } - }, - topologyType: "ReplicaSetWithPrimary", - logicalSessionTimeoutMinutes: null, - setName: "rs", - maxSetVersion: 1, - maxElectionId: {"$oid": "000000000000000000000001"}, - } - }, - - # Reconfig the set and elect B, it has a new setVersion but no electionId. - { - responses: [ - ["b:27017", { - ok: 1, - helloOk: true, - isWritablePrimary: true, - hosts: ["a:27017", "b:27017"], - setName: "rs", - setVersion: 2, - minWireVersion: 0, - maxWireVersion: 6 - }] - ], - - outcome: { - servers: { - "a:27017": { - type: "Unknown", - setName: , - electionId: - }, - "b:27017": { - type: "RSPrimary", - setName: "rs", - setVersion: 2 - } - }, - topologyType: "ReplicaSetWithPrimary", - logicalSessionTimeoutMinutes: null, - setName: "rs", - maxSetVersion: 2, - maxElectionId: {"$oid": "000000000000000000000001"}, - } - }, - - # Delayed response from A, reporting its reelection. Its setVersion shows - # the election preceded B's so we ignore it. - { - responses: [ - ["a:27017", { - ok: 1, - helloOk: true, - isWritablePrimary: true, - hosts: ["a:27017", "b:27017"], - setName: "rs", - setVersion: 1, - electionId: {"$oid": "000000000000000000000002"}, - minWireVersion: 0, - maxWireVersion: 6 - }] - ], - outcome: { - servers: { - "a:27017": { - type: "Unknown", - setName: , - electionId: - }, - "b:27017": { - type: "RSPrimary", - setName: "rs", - setVersion: 2 - } - }, - topologyType: "ReplicaSetWithPrimary", - logicalSessionTimeoutMinutes: null, - setName: "rs", - maxSetVersion: 2, - maxElectionId: {"$oid": "000000000000000000000001"}, - } - } -] From 6892ddc6c5153d7a19173235f32c409b6d7ffe36 Mon Sep 17 00:00:00 2001 From: Neal Beeken Date: Tue, 4 Oct 2022 14:24:19 -0400 Subject: [PATCH 7/7] test: add unit test for objectId comparison --- test/unit/utils.test.ts | 47 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/test/unit/utils.test.ts b/test/unit/utils.test.ts index 2dd0a68730..ae6d91deb0 100644 --- a/test/unit/utils.test.ts +++ b/test/unit/utils.test.ts @@ -3,9 +3,10 @@ import { expect } from 'chai'; import { LEGACY_HELLO_COMMAND } from '../../src/constants'; import { MongoRuntimeError } from '../../src/error'; -import { Promise as PromiseProvider } from '../../src/index'; +import { ObjectId, Promise as PromiseProvider } from '../../src/index'; import { BufferPool, + compareObjectId, eachAsync, HostAddress, isHello, @@ -481,4 +482,48 @@ describe('driver utils', function () { }); }); }); + + describe('compareObjectId()', () => { + const table = [ + { oid1: null, oid2: null, result: 0 }, + { oid1: undefined, oid2: null, result: 0 }, + { oid1: null, oid2: undefined, result: 0 }, + { oid1: undefined, oid2: undefined, result: 0 }, + { oid1: new ObjectId('00'.repeat(12)), oid2: undefined, result: 1 }, + { oid1: new ObjectId('00'.repeat(12)), oid2: null, result: 1 }, + { oid1: undefined, oid2: new ObjectId('00'.repeat(12)), result: -1 }, + { oid1: null, oid2: new ObjectId('00'.repeat(12)), result: -1 }, + { oid1: new ObjectId('00'.repeat(12)), oid2: new ObjectId('00'.repeat(12)), result: 0 }, + { + oid1: new ObjectId('00'.repeat(11) + '01'), + oid2: new ObjectId('00'.repeat(12)), + result: 1 + }, + { + oid1: new ObjectId('00'.repeat(12)), + oid2: new ObjectId('00'.repeat(11) + '01'), + result: -1 + }, + { + oid1: 2, + oid2: 1, + result: 'throws' + } + ]; + + for (const { oid1, oid2, result } of table) { + if (result === 'throws') { + it('passing non-objectId values throw', () => + // @ts-expect-error: Passing bad values to ensure thrown error + expect(() => compareObjectId(oid1, oid2)).to.throw()); + continue; + } + + const title = `comparing ${oid1} to ${oid2} returns ${ + result === 0 ? 'equal' : result === -1 ? 'less than' : 'greater than' + }`; + // @ts-expect-error: not narrowed based on numeric result, but these values are correct + it(title, () => expect(compareObjectId(oid1, oid2)).to.equal(result)); + } + }); });