From 2e19107c900a4108c0a03f9d831082533017df34 Mon Sep 17 00:00:00 2001
From: Neal Beeken <neal.beeken@mongodb.com>
Date: Wed, 8 Sep 2021 10:36:53 -0400
Subject: [PATCH 01/14] chore: add spec changes

---
 .../errors/error_handling_handshake.json      |   3 +-
 .../errors/error_handling_handshake.yml       |   3 +-
 .../errors/generate-error-tests.py            |  10 +-
 .../errors/non-stale-network-error.json       |   3 +-
 .../errors/non-stale-network-error.yml        |   3 +-
 .../non-stale-network-timeout-error.json      |   3 +-
 .../non-stale-network-timeout-error.yml       |   3 +-
 ...Version-greater-InterruptedAtShutdown.json |   3 +-
 ...yVersion-greater-InterruptedAtShutdown.yml |   3 +-
 ...eater-InterruptedDueToReplStateChange.json |   3 +-
 ...reater-InterruptedDueToReplStateChange.yml |   3 +-
 ...ologyVersion-greater-LegacyNotPrimary.json | 100 ++++++
 ...pologyVersion-greater-LegacyNotPrimary.yml |  61 ++++
 ...sion-greater-NotPrimaryNoSecondaryOk.json} |   9 +-
 ...rsion-greater-NotPrimaryNoSecondaryOk.yml} |   9 +-
 ...ersion-greater-NotPrimaryOrSecondary.json} |   9 +-
 ...Version-greater-NotPrimaryOrSecondary.yml} |   9 +-
 ...gyVersion-greater-NotWritablePrimary.json} |   9 +-
 ...ogyVersion-greater-NotWritablePrimary.yml} |   9 +-
 ...ogyVersion-greater-PrimarySteppedDown.json |   3 +-
 ...logyVersion-greater-PrimarySteppedDown.yml |   3 +-
 ...ogyVersion-greater-ShutdownInProgress.json |   3 +-
 ...logyVersion-greater-ShutdownInProgress.yml |   3 +-
 ...Version-missing-InterruptedAtShutdown.json |   3 +-
 ...yVersion-missing-InterruptedAtShutdown.yml |   3 +-
 ...ssing-InterruptedDueToReplStateChange.json |   3 +-
 ...issing-InterruptedDueToReplStateChange.yml |   3 +-
 ...ologyVersion-missing-LegacyNotPrimary.json |  85 +++++
 ...pologyVersion-missing-LegacyNotPrimary.yml |  52 +++
 ...sion-missing-NotPrimaryNoSecondaryOk.json} |   9 +-
 ...rsion-missing-NotPrimaryNoSecondaryOk.yml} |   9 +-
 ...ersion-missing-NotPrimaryOrSecondary.json} |   9 +-
 ...Version-missing-NotPrimaryOrSecondary.yml} |   9 +-
 ...gyVersion-missing-NotWritablePrimary.json} |   9 +-
 ...ogyVersion-missing-NotWritablePrimary.yml} |   9 +-
 ...ogyVersion-missing-PrimarySteppedDown.json |   3 +-
 ...logyVersion-missing-PrimarySteppedDown.yml |   3 +-
 ...ogyVersion-missing-ShutdownInProgress.json |   3 +-
 ...logyVersion-missing-ShutdownInProgress.yml |   3 +-
 ...ccessId-changed-InterruptedAtShutdown.json |   3 +-
 ...occessId-changed-InterruptedAtShutdown.yml |   3 +-
 ...anged-InterruptedDueToReplStateChange.json |   3 +-
 ...hanged-InterruptedDueToReplStateChange.yml |   3 +-
 ...n-proccessId-changed-LegacyNotPrimary.json | 100 ++++++
 ...on-proccessId-changed-LegacyNotPrimary.yml |  61 ++++
 ...ssId-changed-NotPrimaryNoSecondaryOk.json} |   9 +-
 ...essId-changed-NotPrimaryNoSecondaryOk.yml} |   9 +-
 ...cessId-changed-NotPrimaryOrSecondary.json} |   9 +-
 ...ccessId-changed-NotPrimaryOrSecondary.yml} |   9 +-
 ...roccessId-changed-NotWritablePrimary.json} |   9 +-
 ...proccessId-changed-NotWritablePrimary.yml} |   9 +-
 ...proccessId-changed-PrimarySteppedDown.json |   3 +-
 ...-proccessId-changed-PrimarySteppedDown.yml |   3 +-
 ...proccessId-changed-ShutdownInProgress.json |   3 +-
 ...-proccessId-changed-ShutdownInProgress.yml |   3 +-
 .../non-stale-topologyVersion.yml.template    |   3 +-
 .../errors/post-42-InterruptedAtShutdown.json |   3 +-
 .../errors/post-42-InterruptedAtShutdown.yml  |   3 +-
 ...st-42-InterruptedDueToReplStateChange.json |   3 +-
 ...ost-42-InterruptedDueToReplStateChange.yml |   3 +-
 .../errors/post-42-LegacyNotPrimary.json      |  70 ++++
 .../errors/post-42-LegacyNotPrimary.yml       |  47 +++
 ...n => post-42-NotPrimaryNoSecondaryOk.json} |   9 +-
 ...ml => post-42-NotPrimaryNoSecondaryOk.yml} |   9 +-
 ...son => post-42-NotPrimaryOrSecondary.json} |   9 +-
 ....yml => post-42-NotPrimaryOrSecondary.yml} |   9 +-
 ...r.json => post-42-NotWritablePrimary.json} |   9 +-
 ...ter.yml => post-42-NotWritablePrimary.yml} |   9 +-
 .../errors/post-42-PrimarySteppedDown.json    |   3 +-
 .../errors/post-42-PrimarySteppedDown.yml     |   3 +-
 .../errors/post-42-ShutdownInProgress.json    |   3 +-
 .../errors/post-42-ShutdownInProgress.yml     |   3 +-
 .../errors/post-42.yml.template               |   3 +-
 .../errors/pre-42-InterruptedAtShutdown.json  |   3 +-
 .../errors/pre-42-InterruptedAtShutdown.yml   |   3 +-
 ...re-42-InterruptedDueToReplStateChange.json |   3 +-
 ...pre-42-InterruptedDueToReplStateChange.yml |   3 +-
 ...ster.json => pre-42-LegacyNotPrimary.json} |  11 +-
 ...Master.yml => pre-42-LegacyNotPrimary.yml} |  11 +-
 .../pre-42-NotPrimaryNoSecondaryOk.json       |  70 ++++
 .../errors/pre-42-NotPrimaryNoSecondaryOk.yml |  47 +++
 ...json => pre-42-NotPrimaryOrSecondary.json} |   9 +-
 ...y.yml => pre-42-NotPrimaryOrSecondary.yml} |   9 +-
 ...Ok.json => pre-42-NotWritablePrimary.json} |  11 +-
 ...veOk.yml => pre-42-NotWritablePrimary.yml} |  11 +-
 .../errors/pre-42-PrimarySteppedDown.json     |   3 +-
 .../errors/pre-42-PrimarySteppedDown.yml      |   3 +-
 .../errors/pre-42-ShutdownInProgress.json     |   3 +-
 .../errors/pre-42-ShutdownInProgress.yml      |   3 +-
 .../errors/pre-42.yml.template                |   3 +-
 .../errors/prefer-error-code.json             | 131 ++++++++
 .../errors/prefer-error-code.yml              |  54 +++
 ...tale-generation-InterruptedAtShutdown.json |   6 +-
 ...stale-generation-InterruptedAtShutdown.yml |   6 +-
 ...ation-InterruptedDueToReplStateChange.json |   6 +-
 ...ration-InterruptedDueToReplStateChange.yml |   6 +-
 ...e-generation-NotPrimaryNoSecondaryOk.json} |  12 +-
 ...le-generation-NotPrimaryNoSecondaryOk.yml} |  12 +-
 ...ale-generation-NotPrimaryOrSecondary.json} |  12 +-
 ...tale-generation-NotPrimaryOrSecondary.yml} |  12 +-
 ... stale-generation-NotWritablePrimary.json} |  12 +-
 ...> stale-generation-NotWritablePrimary.yml} |  12 +-
 .../stale-generation-PrimarySteppedDown.json  |   6 +-
 .../stale-generation-PrimarySteppedDown.yml   |   6 +-
 .../stale-generation-ShutdownInProgress.json  |   6 +-
 .../stale-generation-ShutdownInProgress.yml   |   6 +-
 ...dshakeCompletes-InterruptedAtShutdown.json |   6 +-
 ...ndshakeCompletes-InterruptedAtShutdown.yml |   6 +-
 ...letes-InterruptedDueToReplStateChange.json |   6 +-
 ...pletes-InterruptedDueToReplStateChange.yml |   6 +-
 ...rHandshakeCompletes-LegacyNotPrimary.json} |  14 +-
 ...erHandshakeCompletes-LegacyNotPrimary.yml} |  14 +-
 ...hakeCompletes-NotPrimaryNoSecondaryOk.json | 176 ++++++++++
 ...shakeCompletes-NotPrimaryNoSecondaryOk.yml |  91 ++++++
 ...shakeCompletes-NotPrimaryOrSecondary.json} |  12 +-
 ...dshakeCompletes-NotPrimaryOrSecondary.yml} |  12 +-
 ...andshakeCompletes-NotWritablePrimary.json} |  14 +-
 ...HandshakeCompletes-NotWritablePrimary.yml} |  14 +-
 ...HandshakeCompletes-PrimarySteppedDown.json |   6 +-
 ...rHandshakeCompletes-PrimarySteppedDown.yml |   6 +-
 ...HandshakeCompletes-ShutdownInProgress.json |   6 +-
 ...rHandshakeCompletes-ShutdownInProgress.yml |   6 +-
 ...ation-afterHandshakeCompletes-network.json |  10 +-
 ...ration-afterHandshakeCompletes-network.yml |  10 +-
 ...ation-afterHandshakeCompletes-timeout.json |  10 +-
 ...ration-afterHandshakeCompletes-timeout.yml |  10 +-
 ...dshakeCompletes-InterruptedAtShutdown.json |   6 +-
 ...ndshakeCompletes-InterruptedAtShutdown.yml |   6 +-
 ...letes-InterruptedDueToReplStateChange.json |   6 +-
 ...pletes-InterruptedDueToReplStateChange.yml |   6 +-
 ...eHandshakeCompletes-LegacyNotPrimary.json} |  14 +-
 ...reHandshakeCompletes-LegacyNotPrimary.yml} |  14 +-
 ...hakeCompletes-NotPrimaryNoSecondaryOk.json | 176 ++++++++++
 ...shakeCompletes-NotPrimaryNoSecondaryOk.yml |  91 ++++++
 ...shakeCompletes-NotPrimaryOrSecondary.json} |  12 +-
 ...dshakeCompletes-NotPrimaryOrSecondary.yml} |  12 +-
 ...andshakeCompletes-NotWritablePrimary.json} |  14 +-
 ...HandshakeCompletes-NotWritablePrimary.yml} |  14 +-
 ...HandshakeCompletes-PrimarySteppedDown.json |   6 +-
 ...eHandshakeCompletes-PrimarySteppedDown.yml |   6 +-
 ...HandshakeCompletes-ShutdownInProgress.json |   6 +-
 ...eHandshakeCompletes-ShutdownInProgress.yml |   6 +-
 ...tion-beforeHandshakeCompletes-network.json |  10 +-
 ...ation-beforeHandshakeCompletes-network.yml |  10 +-
 ...tion-beforeHandshakeCompletes-timeout.json |  10 +-
 ...ation-beforeHandshakeCompletes-timeout.yml |  10 +-
 .../errors/stale-generation.yml.template      |   6 +-
 ...topologyVersion-InterruptedAtShutdown.json |   3 +-
 ...-topologyVersion-InterruptedAtShutdown.yml |   3 +-
 ...rsion-InterruptedDueToReplStateChange.json |   3 +-
 ...ersion-InterruptedDueToReplStateChange.yml |   3 +-
 ...tale-topologyVersion-LegacyNotPrimary.json | 147 +++++++++
 ...stale-topologyVersion-LegacyNotPrimary.yml |  65 ++++
 ...ologyVersion-NotPrimaryNoSecondaryOk.json} |  13 +-
 ...pologyVersion-NotPrimaryNoSecondaryOk.yml} |  13 +-
 ...opologyVersion-NotPrimaryOrSecondary.json} |  13 +-
 ...topologyVersion-NotPrimaryOrSecondary.yml} |  13 +-
 ...e-topologyVersion-NotWritablePrimary.json} |  13 +-
 ...le-topologyVersion-NotWritablePrimary.yml} |  13 +-
 ...le-topologyVersion-PrimarySteppedDown.json |   3 +-
 ...ale-topologyVersion-PrimarySteppedDown.yml |   3 +-
 ...le-topologyVersion-ShutdownInProgress.json |   3 +-
 ...ale-topologyVersion-ShutdownInProgress.yml |   3 +-
 .../errors/stale-topologyVersion.yml.template |   3 +-
 .../errors/write_errors_ignored.json          |   8 +-
 .../errors/write_errors_ignored.yml           |   5 +-
 .../integration/auth-error.json               | 140 ++++++++
 .../integration/auth-error.yml                |  81 +++++
 .../integration/auth-misc-command-error.json  | 140 ++++++++
 .../integration/auth-misc-command-error.yml   |  81 +++++
 .../integration/auth-network-error.json       | 140 ++++++++
 .../integration/auth-network-error.yml        |  81 +++++
 .../auth-network-timeout-error.json           | 143 ++++++++
 .../auth-network-timeout-error.yml            |  86 +++++
 .../integration/auth-shutdown-error.json      | 140 ++++++++
 .../integration/auth-shutdown-error.yml       |  81 +++++
 .../integration/cancel-server-check.yml       |   2 +-
 .../integration/connectTimeoutMS.json         |   4 +-
 .../integration/connectTimeoutMS.yml          |   4 +-
 .../find-network-timeout-error.json           | 119 +++++++
 .../find-network-timeout-error.yml            |  73 +++++
 ...nd-error.json => hello-command-error.json} |  16 +-
 ...mand-error.yml => hello-command-error.yml} |  14 +-
 ...rk-error.json => hello-network-error.json} |  16 +-
 ...work-error.yml => hello-network-error.yml} |  18 +-
 ...Master-timeout.json => hello-timeout.json} |  20 +-
 ...isMaster-timeout.yml => hello-timeout.yml} |  14 +-
 .../integration/minPoolSize-error.json        | 102 ++++++
 .../integration/minPoolSize-error.yml         |  77 +++++
 .../integration/pool-cleared-error.json       | 307 ++++++++++++++++++
 .../integration/pool-cleared-error.yml        | 201 ++++++++++++
 .../load-balanced/discover_load_balancer.json |  28 ++
 .../load-balanced/discover_load_balancer.yml  |  25 ++
 .../monitoring/discovered_standalone.json     |   5 +-
 .../monitoring/discovered_standalone.yml      |   2 +-
 .../monitoring/load_balancer.json             |  93 ++++++
 .../monitoring/load_balancer.yml              |  65 ++++
 .../replica_set_with_no_primary.json          |   5 +-
 .../replica_set_with_no_primary.yml           |  80 ++---
 .../monitoring/replica_set_with_primary.json  |   5 +-
 .../monitoring/replica_set_with_primary.yml   |  80 ++---
 .../monitoring/replica_set_with_removal.json  |   8 +-
 .../monitoring/replica_set_with_removal.yml   |   7 +-
 .../monitoring/required_replica_set.json      |   5 +-
 .../monitoring/required_replica_set.yml       |   5 +-
 .../monitoring/standalone.json                |   5 +-
 .../monitoring/standalone.yml                 |   2 +-
 ...ne_suppress_equal_description_changes.json |  10 +-
 ...one_suppress_equal_description_changes.yml |   4 +-
 .../rs/compatible.json                        |   6 +-
 .../rs/compatible.yml                         |   6 +-
 .../rs/compatible_unknown.json                |   3 +-
 .../rs/compatible_unknown.yml                 |   3 +-
 .../rs/discover_arbiters.json                 |   3 +-
 .../rs/discover_arbiters.yml                  |   3 +-
 .../rs/discover_arbiters_replicaset.json      |   3 +-
 .../rs/discover_arbiters_replicaset.yml       |   3 +-
 .../rs/discover_ghost.json                    |   3 +-
 .../rs/discover_ghost.yml                     |   3 +-
 .../rs/discover_ghost_replicaset.json         |   3 +-
 .../rs/discover_ghost_replicaset.yml          |   3 +-
 .../rs/discover_hidden.json                   |   3 +-
 .../rs/discover_hidden.yml                    |   3 +-
 .../rs/discover_hidden_replicaset.json        |   3 +-
 .../rs/discover_hidden_replicaset.yml         |   3 +-
 .../rs/discover_passives.json                 |   6 +-
 .../rs/discover_passives.yml                  |   6 +-
 .../rs/discover_passives_replicaset.json      |   6 +-
 .../rs/discover_passives_replicaset.yml       |   6 +-
 .../rs/discover_primary.json                  |   3 +-
 .../rs/discover_primary.yml                   |   3 +-
 .../rs/discover_primary_replicaset.json       |   3 +-
 .../rs/discover_primary_replicaset.yml        |   3 +-
 .../rs/discover_rsother.json                  |   3 +-
 .../rs/discover_rsother.yml                   |   3 +-
 .../rs/discover_rsother_replicaset.json       |   6 +-
 .../rs/discover_rsother_replicaset.yml        |   6 +-
 .../rs/discover_secondary.json                |   3 +-
 .../rs/discover_secondary.yml                 |   3 +-
 .../rs/discover_secondary_replicaset.json     |   3 +-
 .../rs/discover_secondary_replicaset.yml      |   3 +-
 .../rs/discovery.json                         |  12 +-
 .../rs/discovery.yml                          |  12 +-
 .../rs/equal_electionids.json                 |   6 +-
 .../rs/equal_electionids.yml                  |   6 +-
 .../rs/hosts_differ_from_seeds.json           |   3 +-
 .../rs/hosts_differ_from_seeds.yml            |   3 +-
 .../rs/incompatible_arbiter.json              |   4 +-
 .../rs/incompatible_arbiter.yml               |   4 +-
 .../rs/incompatible_ghost.json                |   4 +-
 .../rs/incompatible_ghost.yml                 |   4 +-
 .../rs/incompatible_other.json                |   4 +-
 .../rs/incompatible_other.yml                 |   4 +-
 .../rs/ls_timeout.json                        |  18 +-
 .../rs/ls_timeout.yml                         |  18 +-
 .../rs/member_reconfig.json                   |   6 +-
 .../rs/member_reconfig.yml                    |   6 +-
 .../rs/member_standalone.json                 |   6 +-
 .../rs/member_standalone.yml                  |   6 +-
 .../rs/new_primary.json                       |   6 +-
 .../rs/new_primary.yml                        |   6 +-
 .../rs/new_primary_new_electionid.json        |   9 +-
 .../rs/new_primary_new_electionid.yml         |   9 +-
 .../rs/new_primary_new_setversion.json        |   9 +-
 .../rs/new_primary_new_setversion.yml         |   9 +-
 .../rs/new_primary_wrong_set_name.json        |   6 +-
 .../rs/new_primary_wrong_set_name.yml         |   6 +-
 .../rs/non_rs_member.json                     |   1 +
 .../rs/non_rs_member.yml                      |   1 +
 .../rs/normalize_case.json                    |   3 +-
 .../rs/normalize_case.yml                     |   3 +-
 .../rs/normalize_case_me.json                 |   6 +-
 .../rs/normalize_case_me.yml                  |   6 +-
 .../rs/null_election_id.json                  |  12 +-
 .../rs/null_election_id.yml                   |  12 +-
 .../rs/primary_becomes_ghost.json             |   6 +-
 .../rs/primary_becomes_ghost.yml              |   6 +-
 .../rs/primary_becomes_mongos.json            |   6 +-
 .../rs/primary_becomes_mongos.yml             |   6 +-
 .../rs/primary_becomes_standalone.json        |   3 +-
 .../rs/primary_becomes_standalone.yml         |   3 +-
 .../rs/primary_changes_set_name.json          |   6 +-
 .../rs/primary_changes_set_name.yml           |   6 +-
 .../rs/primary_disconnect.json                |   3 +-
 .../rs/primary_disconnect.yml                 |   3 +-
 .../rs/primary_disconnect_electionid.json     |  15 +-
 .../rs/primary_disconnect_electionid.yml      |  15 +-
 .../rs/primary_disconnect_setversion.json     |  15 +-
 .../rs/primary_disconnect_setversion.yml      |  15 +-
 ...int_from_secondary_with_mismatched_me.json |   6 +-
 ...hint_from_secondary_with_mismatched_me.yml |   6 +-
 .../rs/primary_mismatched_me.json             |   3 +-
 .../rs/primary_mismatched_me.yml              |   3 +-
 .../rs/primary_mismatched_me_not_removed.json |   6 +-
 .../rs/primary_mismatched_me_not_removed.yml  |   8 +-
 .../rs/primary_reports_new_member.json        |  12 +-
 .../rs/primary_reports_new_member.yml         |  12 +-
 .../primary_to_no_primary_mismatched_me.json  |   6 +-
 .../primary_to_no_primary_mismatched_me.yml   |   6 +-
 .../rs/primary_wrong_set_name.json            |   3 +-
 .../rs/primary_wrong_set_name.yml             |   3 +-
 .../rs/repeated.json                          |  14 +-
 .../rs/repeated.yml                           |  14 +-
 .../rs/replicaset_rsnp.json                   |   3 +-
 .../rs/replicaset_rsnp.yml                    |   3 +-
 .../rs/response_from_removed.json             |   6 +-
 .../rs/response_from_removed.yml              |   6 +-
 .../rs/sec_not_auth.json                      |   6 +-
 .../rs/sec_not_auth.yml                       |   6 +-
 .../rs/secondary_ignore_ok_0.json             |   6 +-
 .../rs/secondary_ignore_ok_0.yml              |   6 +-
 .../rs/secondary_mismatched_me.json           |   3 +-
 .../rs/secondary_mismatched_me.yml            |   3 +-
 .../rs/secondary_wrong_set_name.json          |   3 +-
 .../rs/secondary_wrong_set_name.yml           |   3 +-
 ...secondary_wrong_set_name_with_primary.json |   6 +-
 .../secondary_wrong_set_name_with_primary.yml |   6 +-
 .../rs/setversion_without_electionid.json     |   6 +-
 .../rs/setversion_without_electionid.yml      |   6 +-
 .../rs/stepdown_change_set_name.json          |   6 +-
 .../rs/stepdown_change_set_name.yml           |   6 +-
 .../rs/too_new.json                           |   6 +-
 .../rs/too_new.yml                            |   6 +-
 .../rs/too_old.json                           |   6 +-
 .../rs/too_old.yml                            |   6 +-
 .../rs/topology_version_equal.json            |   6 +-
 .../rs/topology_version_equal.yml             |   6 +-
 .../rs/topology_version_greater.json          |  15 +-
 .../rs/topology_version_greater.yml           |  15 +-
 .../rs/topology_version_less.json             |   6 +-
 .../rs/topology_version_less.yml              |   6 +-
 .../rs/unexpected_mongos.json                 |   3 +-
 .../rs/unexpected_mongos.yml                  |   3 +-
 .../rs/use_setversion_without_electionid.json |   9 +-
 .../rs/use_setversion_without_electionid.yml  |   9 +-
 .../rs/wrong_set_name.json                    |   3 +-
 .../rs/wrong_set_name.yml                     |   3 +-
 .../sharded/compatible.json                   |   6 +-
 .../sharded/compatible.yml                    |   6 +-
 .../sharded/discover_single_mongos.json       |   3 +-
 .../sharded/discover_single_mongos.yml        |   3 +-
 .../sharded/ls_timeout_mongos.json            |  12 +-
 .../sharded/ls_timeout_mongos.yml             |  14 +-
 .../sharded/mongos_disconnect.json            |   9 +-
 .../sharded/mongos_disconnect.yml             |   9 +-
 .../sharded/multiple_mongoses.json            |   6 +-
 .../sharded/multiple_mongoses.yml             |   6 +-
 .../sharded/non_mongos_removed.json           |   6 +-
 .../sharded/non_mongos_removed.yml            |   6 +-
 .../sharded/too_new.json                      |   6 +-
 .../sharded/too_new.yml                       |   6 +-
 .../sharded/too_old.json                      |   6 +-
 .../sharded/too_old.yml                       |   6 +-
 .../single/compatible.json                    |   3 +-
 .../single/compatible.yml                     |   3 +-
 .../single/direct_connection_external_ip.json |   3 +-
 .../single/direct_connection_external_ip.yml  |   3 +-
 .../single/direct_connection_mongos.json      |   3 +-
 .../single/direct_connection_mongos.yml       |   3 +-
 .../single/direct_connection_replicaset.json  |   3 +-
 .../single/direct_connection_replicaset.yml   |   3 +-
 .../single/direct_connection_rsarbiter.json   |   3 +-
 .../single/direct_connection_rsarbiter.yml    |   3 +-
 .../single/direct_connection_rsprimary.json   |   3 +-
 .../single/direct_connection_rsprimary.yml    |   3 +-
 .../single/direct_connection_rssecondary.json |   3 +-
 .../single/direct_connection_rssecondary.yml  |   3 +-
 .../single/direct_connection_standalone.json  |   3 +-
 .../single/direct_connection_standalone.yml   |   3 +-
 .../direct_connection_wrong_set_name.json     |   6 +-
 .../direct_connection_wrong_set_name.yml      |   6 +-
 .../single/discover_standalone.json           |   3 +-
 .../single/discover_standalone.yml            |   3 +-
 .../single/ls_timeout_standalone.json         |   3 +-
 .../single/ls_timeout_standalone.yml          |   3 +-
 .../single/not_ok_response.json               |   8 +-
 .../single/not_ok_response.yml                |   8 +-
 .../single/standalone_removed.json            |   3 +-
 .../single/standalone_removed.yml             |   3 +-
 ...son => standalone_using_legacy_hello.json} |   6 +-
 ....yml => standalone_using_legacy_hello.yml} |   6 +-
 .../single/too_new.json                       |   3 +-
 .../single/too_new.yml                        |   3 +-
 .../single/too_old.json                       |   3 +-
 .../single/too_old.yml                        |   3 +-
 .../single/too_old_then_upgraded.json         |   6 +-
 .../single/too_old_then_upgraded.yml          |   6 +-
 387 files changed, 5270 insertions(+), 901 deletions(-)
 create mode 100644 test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-greater-LegacyNotPrimary.json
 create mode 100644 test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-greater-LegacyNotPrimary.yml
 rename test/spec/server-discovery-and-monitoring/errors/{non-stale-topologyVersion-greater-NotMasterNoSlaveOk.json => non-stale-topologyVersion-greater-NotPrimaryNoSecondaryOk.json} (87%)
 rename test/spec/server-discovery-and-monitoring/errors/{non-stale-topologyVersion-greater-NotMasterNoSlaveOk.yml => non-stale-topologyVersion-greater-NotPrimaryNoSecondaryOk.yml} (83%)
 rename test/spec/server-discovery-and-monitoring/errors/{non-stale-topologyVersion-greater-NotMasterOrSecondary.json => non-stale-topologyVersion-greater-NotPrimaryOrSecondary.json} (87%)
 rename test/spec/server-discovery-and-monitoring/errors/{non-stale-topologyVersion-greater-NotMasterOrSecondary.yml => non-stale-topologyVersion-greater-NotPrimaryOrSecondary.yml} (83%)
 rename test/spec/server-discovery-and-monitoring/errors/{non-stale-topologyVersion-greater-NotMaster.json => non-stale-topologyVersion-greater-NotWritablePrimary.json} (88%)
 rename test/spec/server-discovery-and-monitoring/errors/{non-stale-topologyVersion-greater-NotMaster.yml => non-stale-topologyVersion-greater-NotWritablePrimary.yml} (84%)
 create mode 100644 test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-missing-LegacyNotPrimary.json
 create mode 100644 test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-missing-LegacyNotPrimary.yml
 rename test/spec/server-discovery-and-monitoring/errors/{non-stale-topologyVersion-missing-NotMasterNoSlaveOk.json => non-stale-topologyVersion-missing-NotPrimaryNoSecondaryOk.json} (85%)
 rename test/spec/server-discovery-and-monitoring/errors/{non-stale-topologyVersion-missing-NotMasterNoSlaveOk.yml => non-stale-topologyVersion-missing-NotPrimaryNoSecondaryOk.yml} (80%)
 rename test/spec/server-discovery-and-monitoring/errors/{non-stale-topologyVersion-missing-NotMasterOrSecondary.json => non-stale-topologyVersion-missing-NotPrimaryOrSecondary.json} (85%)
 rename test/spec/server-discovery-and-monitoring/errors/{non-stale-topologyVersion-missing-NotMasterOrSecondary.yml => non-stale-topologyVersion-missing-NotPrimaryOrSecondary.yml} (80%)
 rename test/spec/server-discovery-and-monitoring/errors/{non-stale-topologyVersion-missing-NotMaster.json => non-stale-topologyVersion-missing-NotWritablePrimary.json} (86%)
 rename test/spec/server-discovery-and-monitoring/errors/{non-stale-topologyVersion-missing-NotMaster.yml => non-stale-topologyVersion-missing-NotWritablePrimary.yml} (81%)
 create mode 100644 test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-proccessId-changed-LegacyNotPrimary.json
 create mode 100644 test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-proccessId-changed-LegacyNotPrimary.yml
 rename test/spec/server-discovery-and-monitoring/errors/{non-stale-topologyVersion-proccessId-changed-NotMasterNoSlaveOk.json => non-stale-topologyVersion-proccessId-changed-NotPrimaryNoSecondaryOk.json} (92%)
 rename test/spec/server-discovery-and-monitoring/errors/{non-stale-topologyVersion-proccessId-changed-NotMasterNoSlaveOk.yml => non-stale-topologyVersion-proccessId-changed-NotPrimaryNoSecondaryOk.yml} (82%)
 rename test/spec/server-discovery-and-monitoring/errors/{non-stale-topologyVersion-proccessId-changed-NotMasterOrSecondary.json => non-stale-topologyVersion-proccessId-changed-NotPrimaryOrSecondary.json} (92%)
 rename test/spec/server-discovery-and-monitoring/errors/{non-stale-topologyVersion-proccessId-changed-NotMasterOrSecondary.yml => non-stale-topologyVersion-proccessId-changed-NotPrimaryOrSecondary.yml} (82%)
 rename test/spec/server-discovery-and-monitoring/errors/{non-stale-topologyVersion-proccessId-changed-NotMaster.json => non-stale-topologyVersion-proccessId-changed-NotWritablePrimary.json} (92%)
 rename test/spec/server-discovery-and-monitoring/errors/{non-stale-topologyVersion-proccessId-changed-NotMaster.yml => non-stale-topologyVersion-proccessId-changed-NotWritablePrimary.yml} (83%)
 create mode 100644 test/spec/server-discovery-and-monitoring/errors/post-42-LegacyNotPrimary.json
 create mode 100644 test/spec/server-discovery-and-monitoring/errors/post-42-LegacyNotPrimary.yml
 rename test/spec/server-discovery-and-monitoring/errors/{post-42-NotMasterNoSlaveOk.json => post-42-NotPrimaryNoSecondaryOk.json} (84%)
 rename test/spec/server-discovery-and-monitoring/errors/{post-42-NotMasterNoSlaveOk.yml => post-42-NotPrimaryNoSecondaryOk.yml} (81%)
 rename test/spec/server-discovery-and-monitoring/errors/{post-42-NotMasterOrSecondary.json => post-42-NotPrimaryOrSecondary.json} (84%)
 rename test/spec/server-discovery-and-monitoring/errors/{post-42-NotMasterOrSecondary.yml => post-42-NotPrimaryOrSecondary.yml} (81%)
 rename test/spec/server-discovery-and-monitoring/errors/{post-42-NotMaster.json => post-42-NotWritablePrimary.json} (85%)
 rename test/spec/server-discovery-and-monitoring/errors/{post-42-NotMaster.yml => post-42-NotWritablePrimary.yml} (82%)
 rename test/spec/server-discovery-and-monitoring/errors/{pre-42-NotMaster.json => pre-42-LegacyNotPrimary.json} (82%)
 rename test/spec/server-discovery-and-monitoring/errors/{pre-42-NotMaster.yml => pre-42-LegacyNotPrimary.yml} (79%)
 create mode 100644 test/spec/server-discovery-and-monitoring/errors/pre-42-NotPrimaryNoSecondaryOk.json
 create mode 100644 test/spec/server-discovery-and-monitoring/errors/pre-42-NotPrimaryNoSecondaryOk.yml
 rename test/spec/server-discovery-and-monitoring/errors/{pre-42-NotMasterOrSecondary.json => pre-42-NotPrimaryOrSecondary.json} (83%)
 rename test/spec/server-discovery-and-monitoring/errors/{pre-42-NotMasterOrSecondary.yml => pre-42-NotPrimaryOrSecondary.yml} (80%)
 rename test/spec/server-discovery-and-monitoring/errors/{pre-42-NotMasterNoSlaveOk.json => pre-42-NotWritablePrimary.json} (84%)
 rename test/spec/server-discovery-and-monitoring/errors/{pre-42-NotMasterNoSlaveOk.yml => pre-42-NotWritablePrimary.yml} (81%)
 create mode 100644 test/spec/server-discovery-and-monitoring/errors/prefer-error-code.json
 create mode 100644 test/spec/server-discovery-and-monitoring/errors/prefer-error-code.yml
 rename test/spec/server-discovery-and-monitoring/errors/{stale-generation-NotMasterNoSlaveOk.json => stale-generation-NotPrimaryNoSecondaryOk.json} (92%)
 rename test/spec/server-discovery-and-monitoring/errors/{stale-generation-NotMasterNoSlaveOk.yml => stale-generation-NotPrimaryNoSecondaryOk.yml} (87%)
 rename test/spec/server-discovery-and-monitoring/errors/{stale-generation-afterHandshakeCompletes-NotMasterOrSecondary.json => stale-generation-NotPrimaryOrSecondary.json} (92%)
 rename test/spec/server-discovery-and-monitoring/errors/{stale-generation-NotMasterOrSecondary.yml => stale-generation-NotPrimaryOrSecondary.yml} (88%)
 rename test/spec/server-discovery-and-monitoring/errors/{stale-generation-afterHandshakeCompletes-NotMaster.json => stale-generation-NotWritablePrimary.json} (92%)
 rename test/spec/server-discovery-and-monitoring/errors/{stale-generation-NotMaster.yml => stale-generation-NotWritablePrimary.yml} (88%)
 rename test/spec/server-discovery-and-monitoring/errors/{stale-generation-NotMaster.json => stale-generation-afterHandshakeCompletes-LegacyNotPrimary.json} (91%)
 rename test/spec/server-discovery-and-monitoring/errors/{stale-generation-afterHandshakeCompletes-NotMaster.yml => stale-generation-afterHandshakeCompletes-LegacyNotPrimary.yml} (86%)
 create mode 100644 test/spec/server-discovery-and-monitoring/errors/stale-generation-afterHandshakeCompletes-NotPrimaryNoSecondaryOk.json
 create mode 100644 test/spec/server-discovery-and-monitoring/errors/stale-generation-afterHandshakeCompletes-NotPrimaryNoSecondaryOk.yml
 rename test/spec/server-discovery-and-monitoring/errors/{stale-generation-NotMasterOrSecondary.json => stale-generation-afterHandshakeCompletes-NotPrimaryOrSecondary.json} (91%)
 rename test/spec/server-discovery-and-monitoring/errors/{stale-generation-afterHandshakeCompletes-NotMasterOrSecondary.yml => stale-generation-afterHandshakeCompletes-NotPrimaryOrSecondary.yml} (87%)
 rename test/spec/server-discovery-and-monitoring/errors/{stale-generation-afterHandshakeCompletes-NotMasterNoSlaveOk.json => stale-generation-afterHandshakeCompletes-NotWritablePrimary.json} (92%)
 rename test/spec/server-discovery-and-monitoring/errors/{stale-generation-afterHandshakeCompletes-NotMasterNoSlaveOk.yml => stale-generation-afterHandshakeCompletes-NotWritablePrimary.yml} (87%)
 rename test/spec/server-discovery-and-monitoring/errors/{stale-generation-beforeHandshakeCompletes-NotMaster.json => stale-generation-beforeHandshakeCompletes-LegacyNotPrimary.json} (91%)
 rename test/spec/server-discovery-and-monitoring/errors/{stale-generation-beforeHandshakeCompletes-NotMaster.yml => stale-generation-beforeHandshakeCompletes-LegacyNotPrimary.yml} (86%)
 create mode 100644 test/spec/server-discovery-and-monitoring/errors/stale-generation-beforeHandshakeCompletes-NotPrimaryNoSecondaryOk.json
 create mode 100644 test/spec/server-discovery-and-monitoring/errors/stale-generation-beforeHandshakeCompletes-NotPrimaryNoSecondaryOk.yml
 rename test/spec/server-discovery-and-monitoring/errors/{stale-generation-beforeHandshakeCompletes-NotMasterOrSecondary.json => stale-generation-beforeHandshakeCompletes-NotPrimaryOrSecondary.json} (91%)
 rename test/spec/server-discovery-and-monitoring/errors/{stale-generation-beforeHandshakeCompletes-NotMasterOrSecondary.yml => stale-generation-beforeHandshakeCompletes-NotPrimaryOrSecondary.yml} (87%)
 rename test/spec/server-discovery-and-monitoring/errors/{stale-generation-beforeHandshakeCompletes-NotMasterNoSlaveOk.json => stale-generation-beforeHandshakeCompletes-NotWritablePrimary.json} (92%)
 rename test/spec/server-discovery-and-monitoring/errors/{stale-generation-beforeHandshakeCompletes-NotMasterNoSlaveOk.yml => stale-generation-beforeHandshakeCompletes-NotWritablePrimary.yml} (87%)
 create mode 100644 test/spec/server-discovery-and-monitoring/errors/stale-topologyVersion-LegacyNotPrimary.json
 create mode 100644 test/spec/server-discovery-and-monitoring/errors/stale-topologyVersion-LegacyNotPrimary.yml
 rename test/spec/server-discovery-and-monitoring/errors/{stale-topologyVersion-NotMasterNoSlaveOk.json => stale-topologyVersion-NotPrimaryNoSecondaryOk.json} (88%)
 rename test/spec/server-discovery-and-monitoring/errors/{stale-topologyVersion-NotMasterNoSlaveOk.yml => stale-topologyVersion-NotPrimaryNoSecondaryOk.yml} (79%)
 rename test/spec/server-discovery-and-monitoring/errors/{stale-topologyVersion-NotMasterOrSecondary.json => stale-topologyVersion-NotPrimaryOrSecondary.json} (89%)
 rename test/spec/server-discovery-and-monitoring/errors/{stale-topologyVersion-NotMasterOrSecondary.yml => stale-topologyVersion-NotPrimaryOrSecondary.yml} (79%)
 rename test/spec/server-discovery-and-monitoring/errors/{stale-topologyVersion-NotMaster.json => stale-topologyVersion-NotWritablePrimary.json} (89%)
 rename test/spec/server-discovery-and-monitoring/errors/{stale-topologyVersion-NotMaster.yml => stale-topologyVersion-NotWritablePrimary.yml} (80%)
 create mode 100644 test/spec/server-discovery-and-monitoring/integration/auth-error.json
 create mode 100644 test/spec/server-discovery-and-monitoring/integration/auth-error.yml
 create mode 100644 test/spec/server-discovery-and-monitoring/integration/auth-misc-command-error.json
 create mode 100644 test/spec/server-discovery-and-monitoring/integration/auth-misc-command-error.yml
 create mode 100644 test/spec/server-discovery-and-monitoring/integration/auth-network-error.json
 create mode 100644 test/spec/server-discovery-and-monitoring/integration/auth-network-error.yml
 create mode 100644 test/spec/server-discovery-and-monitoring/integration/auth-network-timeout-error.json
 create mode 100644 test/spec/server-discovery-and-monitoring/integration/auth-network-timeout-error.yml
 create mode 100644 test/spec/server-discovery-and-monitoring/integration/auth-shutdown-error.json
 create mode 100644 test/spec/server-discovery-and-monitoring/integration/auth-shutdown-error.yml
 create mode 100644 test/spec/server-discovery-and-monitoring/integration/find-network-timeout-error.json
 create mode 100644 test/spec/server-discovery-and-monitoring/integration/find-network-timeout-error.yml
 rename test/spec/server-discovery-and-monitoring/integration/{isMaster-command-error.json => hello-command-error.json} (94%)
 rename test/spec/server-discovery-and-monitoring/integration/{isMaster-command-error.yml => hello-command-error.yml} (90%)
 rename test/spec/server-discovery-and-monitoring/integration/{isMaster-network-error.json => hello-network-error.json} (93%)
 rename test/spec/server-discovery-and-monitoring/integration/{isMaster-network-error.yml => hello-network-error.yml} (88%)
 rename test/spec/server-discovery-and-monitoring/integration/{isMaster-timeout.json => hello-timeout.json} (95%)
 rename test/spec/server-discovery-and-monitoring/integration/{isMaster-timeout.yml => hello-timeout.yml} (93%)
 create mode 100644 test/spec/server-discovery-and-monitoring/integration/minPoolSize-error.json
 create mode 100644 test/spec/server-discovery-and-monitoring/integration/minPoolSize-error.yml
 create mode 100644 test/spec/server-discovery-and-monitoring/integration/pool-cleared-error.json
 create mode 100644 test/spec/server-discovery-and-monitoring/integration/pool-cleared-error.yml
 create mode 100644 test/spec/server-discovery-and-monitoring/load-balanced/discover_load_balancer.json
 create mode 100644 test/spec/server-discovery-and-monitoring/load-balanced/discover_load_balancer.yml
 create mode 100644 test/spec/server-discovery-and-monitoring/monitoring/load_balancer.json
 create mode 100644 test/spec/server-discovery-and-monitoring/monitoring/load_balancer.yml
 rename test/spec/server-discovery-and-monitoring/single/{direct_connection_slave.json => standalone_using_legacy_hello.json} (79%)
 rename test/spec/server-discovery-and-monitoring/single/{direct_connection_slave.yml => standalone_using_legacy_hello.yml} (80%)

diff --git a/test/spec/server-discovery-and-monitoring/errors/error_handling_handshake.json b/test/spec/server-discovery-and-monitoring/errors/error_handling_handshake.json
index cdd6df6247..56ca7d1132 100644
--- a/test/spec/server-discovery-and-monitoring/errors/error_handling_handshake.json
+++ b/test/spec/server-discovery-and-monitoring/errors/error_handling_handshake.json
@@ -9,7 +9,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
diff --git a/test/spec/server-discovery-and-monitoring/errors/error_handling_handshake.yml b/test/spec/server-discovery-and-monitoring/errors/error_handling_handshake.yml
index 9f0bf919ff..8482ea704c 100644
--- a/test/spec/server-discovery-and-monitoring/errors/error_handling_handshake.yml
+++ b/test/spec/server-discovery-and-monitoring/errors/error_handling_handshake.yml
@@ -5,7 +5,8 @@ phases:
   responses:
   - - a:27017
     - ok: 1
-      ismaster: true
+      helloOk: true
+      isWritablePrimary: true
       hosts:
       - a:27017
       setName: rs
diff --git a/test/spec/server-discovery-and-monitoring/errors/generate-error-tests.py b/test/spec/server-discovery-and-monitoring/errors/generate-error-tests.py
index 8ff3c69104..c9323857ad 100644
--- a/test/spec/server-discovery-and-monitoring/errors/generate-error-tests.py
+++ b/test/spec/server-discovery-and-monitoring/errors/generate-error-tests.py
@@ -35,11 +35,12 @@ def write_test(filename, data):
 ERR_CODES = {
     'InterruptedAtShutdown': (11600,),
     'InterruptedDueToReplStateChange': (11602,),
-    'NotMasterOrSecondary': (13436,),
+    'NotPrimaryOrSecondary': (13436,),
     'PrimarySteppedDown': (189,),
     'ShutdownInProgress': (91,),
-    'NotMaster': (10107,),
-    'NotMasterNoSlaveOk': (13435,),
+    'NotWritablePrimary': (10107,),
+    'NotPrimaryNoSecondaryOk': (13435,),
+    'LegacyNotPrimary': (10058,),
 }
 
 
@@ -129,6 +130,7 @@ def create_stale_generation_tests():
     # Stale network errors
     for network_error_type, when in itertools.product(
             ['network', 'timeout'], WHEN):
+        error_name = network_error_type
         test_name = f'stale-generation-{when}-{network_error_type}'
         stale_error = STALE_GENERATION_NETWORK_ERROR.format(**locals())
         data = tmp.format(**locals())
@@ -137,7 +139,7 @@ def create_stale_generation_tests():
 
 def create_pre_42_tests():
     tmp = template('pre-42.yml.template')
-    # All "not master"/"node is recovering" clear the pool on <4.2
+    # All "not writable primary"/"node is recovering" clear the pool on <4.2
     for error_name in ERR_CODES:
         test_name = f'pre-42-{error_name}'
         error_code, = ERR_CODES[error_name]
diff --git a/test/spec/server-discovery-and-monitoring/errors/non-stale-network-error.json b/test/spec/server-discovery-and-monitoring/errors/non-stale-network-error.json
index d0765dbb6d..c22a47dc8a 100644
--- a/test/spec/server-discovery-and-monitoring/errors/non-stale-network-error.json
+++ b/test/spec/server-discovery-and-monitoring/errors/non-stale-network-error.json
@@ -9,7 +9,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
diff --git a/test/spec/server-discovery-and-monitoring/errors/non-stale-network-error.yml b/test/spec/server-discovery-and-monitoring/errors/non-stale-network-error.yml
index 086950b956..3d29debefe 100644
--- a/test/spec/server-discovery-and-monitoring/errors/non-stale-network-error.yml
+++ b/test/spec/server-discovery-and-monitoring/errors/non-stale-network-error.yml
@@ -5,7 +5,8 @@ phases:
   responses:
   - - a:27017
     - ok: 1
-      ismaster: true
+      helloOk: true
+      isWritablePrimary: true
       hosts:
       - a:27017
       setName: rs
diff --git a/test/spec/server-discovery-and-monitoring/errors/non-stale-network-timeout-error.json b/test/spec/server-discovery-and-monitoring/errors/non-stale-network-timeout-error.json
index 7c1a197a62..03dc5b66c9 100644
--- a/test/spec/server-discovery-and-monitoring/errors/non-stale-network-timeout-error.json
+++ b/test/spec/server-discovery-and-monitoring/errors/non-stale-network-timeout-error.json
@@ -9,7 +9,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
diff --git a/test/spec/server-discovery-and-monitoring/errors/non-stale-network-timeout-error.yml b/test/spec/server-discovery-and-monitoring/errors/non-stale-network-timeout-error.yml
index f06e9efb0e..0c27f52d2e 100644
--- a/test/spec/server-discovery-and-monitoring/errors/non-stale-network-timeout-error.yml
+++ b/test/spec/server-discovery-and-monitoring/errors/non-stale-network-timeout-error.yml
@@ -5,7 +5,8 @@ phases:
   responses:
   - - a:27017
     - ok: 1
-      ismaster: true
+      helloOk: true
+      isWritablePrimary: true
       hosts:
       - a:27017
       setName: rs
diff --git a/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-greater-InterruptedAtShutdown.json b/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-greater-InterruptedAtShutdown.json
index 68b7f455aa..777e703a3c 100644
--- a/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-greater-InterruptedAtShutdown.json
+++ b/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-greater-InterruptedAtShutdown.json
@@ -9,7 +9,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
diff --git a/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-greater-InterruptedAtShutdown.yml b/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-greater-InterruptedAtShutdown.yml
index 407c18b60c..9672debceb 100644
--- a/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-greater-InterruptedAtShutdown.yml
+++ b/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-greater-InterruptedAtShutdown.yml
@@ -6,7 +6,8 @@ phases:
   responses:
   - - a:27017
     - ok: 1
-      ismaster: true
+      helloOk: true
+      isWritablePrimary: true
       hosts:
       - a:27017
       setName: rs
diff --git a/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-greater-InterruptedDueToReplStateChange.json b/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-greater-InterruptedDueToReplStateChange.json
index d4a409d268..c4aa7fb71b 100644
--- a/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-greater-InterruptedDueToReplStateChange.json
+++ b/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-greater-InterruptedDueToReplStateChange.json
@@ -9,7 +9,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
diff --git a/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-greater-InterruptedDueToReplStateChange.yml b/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-greater-InterruptedDueToReplStateChange.yml
index 616690ee5a..87162a1595 100644
--- a/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-greater-InterruptedDueToReplStateChange.yml
+++ b/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-greater-InterruptedDueToReplStateChange.yml
@@ -6,7 +6,8 @@ phases:
   responses:
   - - a:27017
     - ok: 1
-      ismaster: true
+      helloOk: true
+      isWritablePrimary: true
       hosts:
       - a:27017
       setName: rs
diff --git a/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-greater-LegacyNotPrimary.json b/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-greater-LegacyNotPrimary.json
new file mode 100644
index 0000000000..2a9bc8a5cf
--- /dev/null
+++ b/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-greater-LegacyNotPrimary.json
@@ -0,0 +1,100 @@
+{
+  "description": "Non-stale topologyVersion greater LegacyNotPrimary error",
+  "uri": "mongodb://a/?replicaSet=rs",
+  "phases": [
+    {
+      "description": "Primary A is discovered",
+      "responses": [
+        [
+          "a:27017",
+          {
+            "ok": 1,
+            "helloOk": true,
+            "isWritablePrimary": true,
+            "hosts": [
+              "a:27017"
+            ],
+            "setName": "rs",
+            "minWireVersion": 0,
+            "maxWireVersion": 9,
+            "topologyVersion": {
+              "processId": {
+                "$oid": "000000000000000000000001"
+              },
+              "counter": {
+                "$numberLong": "1"
+              }
+            }
+          }
+        ]
+      ],
+      "outcome": {
+        "servers": {
+          "a:27017": {
+            "type": "RSPrimary",
+            "setName": "rs",
+            "topologyVersion": {
+              "processId": {
+                "$oid": "000000000000000000000001"
+              },
+              "counter": {
+                "$numberLong": "1"
+              }
+            },
+            "pool": {
+              "generation": 0
+            }
+          }
+        },
+        "topologyType": "ReplicaSetWithPrimary",
+        "logicalSessionTimeoutMinutes": null,
+        "setName": "rs"
+      }
+    },
+    {
+      "description": "Non-stale topologyVersion greater LegacyNotPrimary error marks server Unknown",
+      "applicationErrors": [
+        {
+          "address": "a:27017",
+          "when": "afterHandshakeCompletes",
+          "maxWireVersion": 9,
+          "type": "command",
+          "response": {
+            "ok": 0,
+            "errmsg": "LegacyNotPrimary",
+            "code": 10058,
+            "topologyVersion": {
+              "processId": {
+                "$oid": "000000000000000000000001"
+              },
+              "counter": {
+                "$numberLong": "2"
+              }
+            }
+          }
+        }
+      ],
+      "outcome": {
+        "servers": {
+          "a:27017": {
+            "type": "Unknown",
+            "topologyVersion": {
+              "processId": {
+                "$oid": "000000000000000000000001"
+              },
+              "counter": {
+                "$numberLong": "2"
+              }
+            },
+            "pool": {
+              "generation": 0
+            }
+          }
+        },
+        "topologyType": "ReplicaSetNoPrimary",
+        "logicalSessionTimeoutMinutes": null,
+        "setName": "rs"
+      }
+    }
+  ]
+}
diff --git a/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-greater-LegacyNotPrimary.yml b/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-greater-LegacyNotPrimary.yml
new file mode 100644
index 0000000000..ca25a16512
--- /dev/null
+++ b/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-greater-LegacyNotPrimary.yml
@@ -0,0 +1,61 @@
+# Autogenerated tests for SDAM error handling, see generate-error-tests.py
+description: Non-stale topologyVersion greater LegacyNotPrimary error
+uri: mongodb://a/?replicaSet=rs
+phases:
+- description: Primary A is discovered
+  responses:
+  - - a:27017
+    - ok: 1
+      helloOk: true
+      isWritablePrimary: true
+      hosts:
+      - a:27017
+      setName: rs
+      minWireVersion: 0
+      maxWireVersion: 9
+      topologyVersion: &topologyVersion_1_1
+        processId:
+          "$oid": '000000000000000000000001'
+        counter:
+          "$numberLong": '1'
+  outcome: &outcome
+    servers:
+      a:27017:
+        type: RSPrimary
+        setName: rs
+        topologyVersion: *topologyVersion_1_1
+        pool:
+          generation: 0
+    topologyType: ReplicaSetWithPrimary
+    logicalSessionTimeoutMinutes: null
+    setName: rs
+
+- description: Non-stale topologyVersion greater LegacyNotPrimary error marks server Unknown
+  applicationErrors:
+  - address: a:27017
+    when: afterHandshakeCompletes
+    maxWireVersion: 9
+    type: command
+    response:
+      ok: 0
+      errmsg: LegacyNotPrimary
+      code: 10058
+      topologyVersion:
+        processId:
+          "$oid": '000000000000000000000001'
+        counter:
+          "$numberLong": "2"
+  outcome:
+    servers:
+      a:27017:
+        type: Unknown
+        topologyVersion:
+          processId:
+            "$oid": '000000000000000000000001'
+          counter:
+            "$numberLong": "2"
+        pool:
+          generation: 0
+    topologyType: ReplicaSetNoPrimary
+    logicalSessionTimeoutMinutes: null
+    setName: rs
diff --git a/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-greater-NotMasterNoSlaveOk.json b/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-greater-NotPrimaryNoSecondaryOk.json
similarity index 87%
rename from test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-greater-NotMasterNoSlaveOk.json
rename to test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-greater-NotPrimaryNoSecondaryOk.json
index 30d8698aac..638aa306cb 100644
--- a/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-greater-NotMasterNoSlaveOk.json
+++ b/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-greater-NotPrimaryNoSecondaryOk.json
@@ -1,5 +1,5 @@
 {
-  "description": "Non-stale topologyVersion greater NotMasterNoSlaveOk error",
+  "description": "Non-stale topologyVersion greater NotPrimaryNoSecondaryOk error",
   "uri": "mongodb://a/?replicaSet=rs",
   "phases": [
     {
@@ -9,7 +9,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
@@ -51,7 +52,7 @@
       }
     },
     {
-      "description": "Non-stale topologyVersion greater NotMasterNoSlaveOk error marks server Unknown",
+      "description": "Non-stale topologyVersion greater NotPrimaryNoSecondaryOk error marks server Unknown",
       "applicationErrors": [
         {
           "address": "a:27017",
@@ -60,7 +61,7 @@
           "type": "command",
           "response": {
             "ok": 0,
-            "errmsg": "NotMasterNoSlaveOk",
+            "errmsg": "NotPrimaryNoSecondaryOk",
             "code": 13435,
             "topologyVersion": {
               "processId": {
diff --git a/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-greater-NotMasterNoSlaveOk.yml b/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-greater-NotPrimaryNoSecondaryOk.yml
similarity index 83%
rename from test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-greater-NotMasterNoSlaveOk.yml
rename to test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-greater-NotPrimaryNoSecondaryOk.yml
index 86196dae19..b5dfc46978 100644
--- a/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-greater-NotMasterNoSlaveOk.yml
+++ b/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-greater-NotPrimaryNoSecondaryOk.yml
@@ -1,12 +1,13 @@
 # Autogenerated tests for SDAM error handling, see generate-error-tests.py
-description: Non-stale topologyVersion greater NotMasterNoSlaveOk error
+description: Non-stale topologyVersion greater NotPrimaryNoSecondaryOk error
 uri: mongodb://a/?replicaSet=rs
 phases:
 - description: Primary A is discovered
   responses:
   - - a:27017
     - ok: 1
-      ismaster: true
+      helloOk: true
+      isWritablePrimary: true
       hosts:
       - a:27017
       setName: rs
@@ -29,7 +30,7 @@ phases:
     logicalSessionTimeoutMinutes: null
     setName: rs
 
-- description: Non-stale topologyVersion greater NotMasterNoSlaveOk error marks server Unknown
+- description: Non-stale topologyVersion greater NotPrimaryNoSecondaryOk error marks server Unknown
   applicationErrors:
   - address: a:27017
     when: afterHandshakeCompletes
@@ -37,7 +38,7 @@ phases:
     type: command
     response:
       ok: 0
-      errmsg: NotMasterNoSlaveOk
+      errmsg: NotPrimaryNoSecondaryOk
       code: 13435
       topologyVersion:
         processId:
diff --git a/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-greater-NotMasterOrSecondary.json b/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-greater-NotPrimaryOrSecondary.json
similarity index 87%
rename from test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-greater-NotMasterOrSecondary.json
rename to test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-greater-NotPrimaryOrSecondary.json
index 9d1c236565..f327954a9d 100644
--- a/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-greater-NotMasterOrSecondary.json
+++ b/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-greater-NotPrimaryOrSecondary.json
@@ -1,5 +1,5 @@
 {
-  "description": "Non-stale topologyVersion greater NotMasterOrSecondary error",
+  "description": "Non-stale topologyVersion greater NotPrimaryOrSecondary error",
   "uri": "mongodb://a/?replicaSet=rs",
   "phases": [
     {
@@ -9,7 +9,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
@@ -51,7 +52,7 @@
       }
     },
     {
-      "description": "Non-stale topologyVersion greater NotMasterOrSecondary error marks server Unknown",
+      "description": "Non-stale topologyVersion greater NotPrimaryOrSecondary error marks server Unknown",
       "applicationErrors": [
         {
           "address": "a:27017",
@@ -60,7 +61,7 @@
           "type": "command",
           "response": {
             "ok": 0,
-            "errmsg": "NotMasterOrSecondary",
+            "errmsg": "NotPrimaryOrSecondary",
             "code": 13436,
             "topologyVersion": {
               "processId": {
diff --git a/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-greater-NotMasterOrSecondary.yml b/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-greater-NotPrimaryOrSecondary.yml
similarity index 83%
rename from test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-greater-NotMasterOrSecondary.yml
rename to test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-greater-NotPrimaryOrSecondary.yml
index 7437afeb40..8583704c90 100644
--- a/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-greater-NotMasterOrSecondary.yml
+++ b/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-greater-NotPrimaryOrSecondary.yml
@@ -1,12 +1,13 @@
 # Autogenerated tests for SDAM error handling, see generate-error-tests.py
-description: Non-stale topologyVersion greater NotMasterOrSecondary error
+description: Non-stale topologyVersion greater NotPrimaryOrSecondary error
 uri: mongodb://a/?replicaSet=rs
 phases:
 - description: Primary A is discovered
   responses:
   - - a:27017
     - ok: 1
-      ismaster: true
+      helloOk: true
+      isWritablePrimary: true
       hosts:
       - a:27017
       setName: rs
@@ -29,7 +30,7 @@ phases:
     logicalSessionTimeoutMinutes: null
     setName: rs
 
-- description: Non-stale topologyVersion greater NotMasterOrSecondary error marks server Unknown
+- description: Non-stale topologyVersion greater NotPrimaryOrSecondary error marks server Unknown
   applicationErrors:
   - address: a:27017
     when: afterHandshakeCompletes
@@ -37,7 +38,7 @@ phases:
     type: command
     response:
       ok: 0
-      errmsg: NotMasterOrSecondary
+      errmsg: NotPrimaryOrSecondary
       code: 13436
       topologyVersion:
         processId:
diff --git a/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-greater-NotMaster.json b/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-greater-NotWritablePrimary.json
similarity index 88%
rename from test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-greater-NotMaster.json
rename to test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-greater-NotWritablePrimary.json
index dbd7154573..0ac02fb19b 100644
--- a/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-greater-NotMaster.json
+++ b/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-greater-NotWritablePrimary.json
@@ -1,5 +1,5 @@
 {
-  "description": "Non-stale topologyVersion greater NotMaster error",
+  "description": "Non-stale topologyVersion greater NotWritablePrimary error",
   "uri": "mongodb://a/?replicaSet=rs",
   "phases": [
     {
@@ -9,7 +9,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
@@ -51,7 +52,7 @@
       }
     },
     {
-      "description": "Non-stale topologyVersion greater NotMaster error marks server Unknown",
+      "description": "Non-stale topologyVersion greater NotWritablePrimary error marks server Unknown",
       "applicationErrors": [
         {
           "address": "a:27017",
@@ -60,7 +61,7 @@
           "type": "command",
           "response": {
             "ok": 0,
-            "errmsg": "NotMaster",
+            "errmsg": "NotWritablePrimary",
             "code": 10107,
             "topologyVersion": {
               "processId": {
diff --git a/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-greater-NotMaster.yml b/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-greater-NotWritablePrimary.yml
similarity index 84%
rename from test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-greater-NotMaster.yml
rename to test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-greater-NotWritablePrimary.yml
index aae29895a1..6770de0519 100644
--- a/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-greater-NotMaster.yml
+++ b/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-greater-NotWritablePrimary.yml
@@ -1,12 +1,13 @@
 # Autogenerated tests for SDAM error handling, see generate-error-tests.py
-description: Non-stale topologyVersion greater NotMaster error
+description: Non-stale topologyVersion greater NotWritablePrimary error
 uri: mongodb://a/?replicaSet=rs
 phases:
 - description: Primary A is discovered
   responses:
   - - a:27017
     - ok: 1
-      ismaster: true
+      helloOk: true
+      isWritablePrimary: true
       hosts:
       - a:27017
       setName: rs
@@ -29,7 +30,7 @@ phases:
     logicalSessionTimeoutMinutes: null
     setName: rs
 
-- description: Non-stale topologyVersion greater NotMaster error marks server Unknown
+- description: Non-stale topologyVersion greater NotWritablePrimary error marks server Unknown
   applicationErrors:
   - address: a:27017
     when: afterHandshakeCompletes
@@ -37,7 +38,7 @@ phases:
     type: command
     response:
       ok: 0
-      errmsg: NotMaster
+      errmsg: NotWritablePrimary
       code: 10107
       topologyVersion:
         processId:
diff --git a/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-greater-PrimarySteppedDown.json b/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-greater-PrimarySteppedDown.json
index d189dd3fba..daf2a7e8e1 100644
--- a/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-greater-PrimarySteppedDown.json
+++ b/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-greater-PrimarySteppedDown.json
@@ -9,7 +9,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
diff --git a/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-greater-PrimarySteppedDown.yml b/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-greater-PrimarySteppedDown.yml
index 972acc14b1..a302307d97 100644
--- a/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-greater-PrimarySteppedDown.yml
+++ b/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-greater-PrimarySteppedDown.yml
@@ -6,7 +6,8 @@ phases:
   responses:
   - - a:27017
     - ok: 1
-      ismaster: true
+      helloOk: true
+      isWritablePrimary: true
       hosts:
       - a:27017
       setName: rs
diff --git a/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-greater-ShutdownInProgress.json b/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-greater-ShutdownInProgress.json
index 9e88f5ce3f..a7d9e1fe24 100644
--- a/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-greater-ShutdownInProgress.json
+++ b/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-greater-ShutdownInProgress.json
@@ -9,7 +9,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
diff --git a/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-greater-ShutdownInProgress.yml b/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-greater-ShutdownInProgress.yml
index 6b892864ae..2d7a0c7d27 100644
--- a/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-greater-ShutdownInProgress.yml
+++ b/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-greater-ShutdownInProgress.yml
@@ -6,7 +6,8 @@ phases:
   responses:
   - - a:27017
     - ok: 1
-      ismaster: true
+      helloOk: true
+      isWritablePrimary: true
       hosts:
       - a:27017
       setName: rs
diff --git a/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-missing-InterruptedAtShutdown.json b/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-missing-InterruptedAtShutdown.json
index 06c61a93da..2c59e785ab 100644
--- a/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-missing-InterruptedAtShutdown.json
+++ b/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-missing-InterruptedAtShutdown.json
@@ -9,7 +9,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
diff --git a/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-missing-InterruptedAtShutdown.yml b/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-missing-InterruptedAtShutdown.yml
index d870a57687..74e59d2056 100644
--- a/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-missing-InterruptedAtShutdown.yml
+++ b/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-missing-InterruptedAtShutdown.yml
@@ -6,7 +6,8 @@ phases:
   responses:
   - - a:27017
     - ok: 1
-      ismaster: true
+      helloOk: true
+      isWritablePrimary: true
       hosts:
       - a:27017
       setName: rs
diff --git a/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-missing-InterruptedDueToReplStateChange.json b/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-missing-InterruptedDueToReplStateChange.json
index ebf5a1a4a1..f2cb834e83 100644
--- a/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-missing-InterruptedDueToReplStateChange.json
+++ b/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-missing-InterruptedDueToReplStateChange.json
@@ -9,7 +9,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
diff --git a/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-missing-InterruptedDueToReplStateChange.yml b/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-missing-InterruptedDueToReplStateChange.yml
index 03120cc586..3eab8ad40f 100644
--- a/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-missing-InterruptedDueToReplStateChange.yml
+++ b/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-missing-InterruptedDueToReplStateChange.yml
@@ -6,7 +6,8 @@ phases:
   responses:
   - - a:27017
     - ok: 1
-      ismaster: true
+      helloOk: true
+      isWritablePrimary: true
       hosts:
       - a:27017
       setName: rs
diff --git a/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-missing-LegacyNotPrimary.json b/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-missing-LegacyNotPrimary.json
new file mode 100644
index 0000000000..095128d615
--- /dev/null
+++ b/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-missing-LegacyNotPrimary.json
@@ -0,0 +1,85 @@
+{
+  "description": "Non-stale topologyVersion missing LegacyNotPrimary error",
+  "uri": "mongodb://a/?replicaSet=rs",
+  "phases": [
+    {
+      "description": "Primary A is discovered",
+      "responses": [
+        [
+          "a:27017",
+          {
+            "ok": 1,
+            "helloOk": true,
+            "isWritablePrimary": true,
+            "hosts": [
+              "a:27017"
+            ],
+            "setName": "rs",
+            "minWireVersion": 0,
+            "maxWireVersion": 9,
+            "topologyVersion": {
+              "processId": {
+                "$oid": "000000000000000000000001"
+              },
+              "counter": {
+                "$numberLong": "1"
+              }
+            }
+          }
+        ]
+      ],
+      "outcome": {
+        "servers": {
+          "a:27017": {
+            "type": "RSPrimary",
+            "setName": "rs",
+            "topologyVersion": {
+              "processId": {
+                "$oid": "000000000000000000000001"
+              },
+              "counter": {
+                "$numberLong": "1"
+              }
+            },
+            "pool": {
+              "generation": 0
+            }
+          }
+        },
+        "topologyType": "ReplicaSetWithPrimary",
+        "logicalSessionTimeoutMinutes": null,
+        "setName": "rs"
+      }
+    },
+    {
+      "description": "Non-stale topologyVersion missing LegacyNotPrimary error marks server Unknown",
+      "applicationErrors": [
+        {
+          "address": "a:27017",
+          "when": "afterHandshakeCompletes",
+          "maxWireVersion": 9,
+          "type": "command",
+          "response": {
+            "ok": 0,
+            "errmsg": "LegacyNotPrimary",
+            "code": 10058
+          }
+        }
+      ],
+      "outcome": {
+        "servers": {
+          "a:27017": {
+            "type": "Unknown",
+            "topologyVersion": null,
+            "pool": {
+              "generation": 0
+            }
+          }
+        },
+        "topologyType": "ReplicaSetNoPrimary",
+        "logicalSessionTimeoutMinutes": null,
+        "setName": "rs"
+      }
+    }
+  ]
+}
diff --git a/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-missing-LegacyNotPrimary.yml b/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-missing-LegacyNotPrimary.yml
new file mode 100644
index 0000000000..a7d0113357
--- /dev/null
+++ b/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-missing-LegacyNotPrimary.yml
@@ -0,0 +1,52 @@
+# Autogenerated tests for SDAM error handling, see generate-error-tests.py
+description: Non-stale topologyVersion missing LegacyNotPrimary error
+uri: mongodb://a/?replicaSet=rs
+phases:
+- description: Primary A is discovered
+  responses:
+  - - a:27017
+    - ok: 1
+      helloOk: true
+      isWritablePrimary: true
+      hosts:
+      - a:27017
+      setName: rs
+      minWireVersion: 0
+      maxWireVersion: 9
+      topologyVersion: &topologyVersion_1_1
+        processId:
+          "$oid": '000000000000000000000001'
+        counter:
+          "$numberLong": '1'
+  outcome: &outcome
+    servers:
+      a:27017:
+        type: RSPrimary
+        setName: rs
+        topologyVersion: *topologyVersion_1_1
+        pool:
+          generation: 0
+    topologyType: ReplicaSetWithPrimary
+    logicalSessionTimeoutMinutes: null
+    setName: rs
+
+- description: Non-stale topologyVersion missing LegacyNotPrimary error marks server Unknown
+  applicationErrors:
+  - address: a:27017
+    when: afterHandshakeCompletes
+    maxWireVersion: 9
+    type: command
+    response:
+      ok: 0
+      errmsg: LegacyNotPrimary
+      code: 10058
+  outcome:
+    servers:
+      a:27017:
+        type: Unknown
+        topologyVersion: null
+        pool:
+          generation: 0
+    topologyType: ReplicaSetNoPrimary
+    logicalSessionTimeoutMinutes: null
+    setName: rs
diff --git a/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-missing-NotMasterNoSlaveOk.json b/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-missing-NotPrimaryNoSecondaryOk.json
similarity index 85%
rename from test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-missing-NotMasterNoSlaveOk.json
rename to test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-missing-NotPrimaryNoSecondaryOk.json
index 502ebc549c..3d7312d4a5 100644
--- a/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-missing-NotMasterNoSlaveOk.json
+++ b/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-missing-NotPrimaryNoSecondaryOk.json
@@ -1,5 +1,5 @@
 {
-  "description": "Non-stale topologyVersion missing NotMasterNoSlaveOk error",
+  "description": "Non-stale topologyVersion missing NotPrimaryNoSecondaryOk error",
   "uri": "mongodb://a/?replicaSet=rs",
   "phases": [
     {
@@ -9,7 +9,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
@@ -51,7 +52,7 @@
       }
     },
     {
-      "description": "Non-stale topologyVersion missing NotMasterNoSlaveOk error marks server Unknown",
+      "description": "Non-stale topologyVersion missing NotPrimaryNoSecondaryOk error marks server Unknown",
       "applicationErrors": [
         {
           "address": "a:27017",
@@ -60,7 +61,7 @@
           "type": "command",
           "response": {
             "ok": 0,
-            "errmsg": "NotMasterNoSlaveOk",
+            "errmsg": "NotPrimaryNoSecondaryOk",
             "code": 13435
           }
         }
diff --git a/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-missing-NotMasterNoSlaveOk.yml b/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-missing-NotPrimaryNoSecondaryOk.yml
similarity index 80%
rename from test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-missing-NotMasterNoSlaveOk.yml
rename to test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-missing-NotPrimaryNoSecondaryOk.yml
index 5b25c67e3a..0f43246070 100644
--- a/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-missing-NotMasterNoSlaveOk.yml
+++ b/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-missing-NotPrimaryNoSecondaryOk.yml
@@ -1,12 +1,13 @@
 # Autogenerated tests for SDAM error handling, see generate-error-tests.py
-description: Non-stale topologyVersion missing NotMasterNoSlaveOk error
+description: Non-stale topologyVersion missing NotPrimaryNoSecondaryOk error
 uri: mongodb://a/?replicaSet=rs
 phases:
 - description: Primary A is discovered
   responses:
   - - a:27017
     - ok: 1
-      ismaster: true
+      helloOk: true
+      isWritablePrimary: true
       hosts:
       - a:27017
       setName: rs
@@ -29,7 +30,7 @@ phases:
     logicalSessionTimeoutMinutes: null
     setName: rs
 
-- description: Non-stale topologyVersion missing NotMasterNoSlaveOk error marks server Unknown
+- description: Non-stale topologyVersion missing NotPrimaryNoSecondaryOk error marks server Unknown
   applicationErrors:
   - address: a:27017
     when: afterHandshakeCompletes
@@ -37,7 +38,7 @@ phases:
     type: command
     response:
       ok: 0
-      errmsg: NotMasterNoSlaveOk
+      errmsg: NotPrimaryNoSecondaryOk
       code: 13435
   outcome:
     servers:
diff --git a/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-missing-NotMasterOrSecondary.json b/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-missing-NotPrimaryOrSecondary.json
similarity index 85%
rename from test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-missing-NotMasterOrSecondary.json
rename to test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-missing-NotPrimaryOrSecondary.json
index 8e84038e29..a457ba3072 100644
--- a/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-missing-NotMasterOrSecondary.json
+++ b/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-missing-NotPrimaryOrSecondary.json
@@ -1,5 +1,5 @@
 {
-  "description": "Non-stale topologyVersion missing NotMasterOrSecondary error",
+  "description": "Non-stale topologyVersion missing NotPrimaryOrSecondary error",
   "uri": "mongodb://a/?replicaSet=rs",
   "phases": [
     {
@@ -9,7 +9,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
@@ -51,7 +52,7 @@
       }
     },
     {
-      "description": "Non-stale topologyVersion missing NotMasterOrSecondary error marks server Unknown",
+      "description": "Non-stale topologyVersion missing NotPrimaryOrSecondary error marks server Unknown",
       "applicationErrors": [
         {
           "address": "a:27017",
@@ -60,7 +61,7 @@
           "type": "command",
           "response": {
             "ok": 0,
-            "errmsg": "NotMasterOrSecondary",
+            "errmsg": "NotPrimaryOrSecondary",
             "code": 13436
           }
         }
diff --git a/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-missing-NotMasterOrSecondary.yml b/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-missing-NotPrimaryOrSecondary.yml
similarity index 80%
rename from test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-missing-NotMasterOrSecondary.yml
rename to test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-missing-NotPrimaryOrSecondary.yml
index 3847cd6291..fcc72bf794 100644
--- a/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-missing-NotMasterOrSecondary.yml
+++ b/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-missing-NotPrimaryOrSecondary.yml
@@ -1,12 +1,13 @@
 # Autogenerated tests for SDAM error handling, see generate-error-tests.py
-description: Non-stale topologyVersion missing NotMasterOrSecondary error
+description: Non-stale topologyVersion missing NotPrimaryOrSecondary error
 uri: mongodb://a/?replicaSet=rs
 phases:
 - description: Primary A is discovered
   responses:
   - - a:27017
     - ok: 1
-      ismaster: true
+      helloOk: true
+      isWritablePrimary: true
       hosts:
       - a:27017
       setName: rs
@@ -29,7 +30,7 @@ phases:
     logicalSessionTimeoutMinutes: null
     setName: rs
 
-- description: Non-stale topologyVersion missing NotMasterOrSecondary error marks server Unknown
+- description: Non-stale topologyVersion missing NotPrimaryOrSecondary error marks server Unknown
   applicationErrors:
   - address: a:27017
     when: afterHandshakeCompletes
@@ -37,7 +38,7 @@ phases:
     type: command
     response:
       ok: 0
-      errmsg: NotMasterOrSecondary
+      errmsg: NotPrimaryOrSecondary
       code: 13436
   outcome:
     servers:
diff --git a/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-missing-NotMaster.json b/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-missing-NotWritablePrimary.json
similarity index 86%
rename from test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-missing-NotMaster.json
rename to test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-missing-NotWritablePrimary.json
index 54ce115e68..b7427a3f3d 100644
--- a/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-missing-NotMaster.json
+++ b/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-missing-NotWritablePrimary.json
@@ -1,5 +1,5 @@
 {
-  "description": "Non-stale topologyVersion missing NotMaster error",
+  "description": "Non-stale topologyVersion missing NotWritablePrimary error",
   "uri": "mongodb://a/?replicaSet=rs",
   "phases": [
     {
@@ -9,7 +9,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
@@ -51,7 +52,7 @@
       }
     },
     {
-      "description": "Non-stale topologyVersion missing NotMaster error marks server Unknown",
+      "description": "Non-stale topologyVersion missing NotWritablePrimary error marks server Unknown",
       "applicationErrors": [
         {
           "address": "a:27017",
@@ -60,7 +61,7 @@
           "type": "command",
           "response": {
             "ok": 0,
-            "errmsg": "NotMaster",
+            "errmsg": "NotWritablePrimary",
             "code": 10107
           }
         }
diff --git a/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-missing-NotMaster.yml b/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-missing-NotWritablePrimary.yml
similarity index 81%
rename from test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-missing-NotMaster.yml
rename to test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-missing-NotWritablePrimary.yml
index 55d9a9bb30..4a9ef427fb 100644
--- a/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-missing-NotMaster.yml
+++ b/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-missing-NotWritablePrimary.yml
@@ -1,12 +1,13 @@
 # Autogenerated tests for SDAM error handling, see generate-error-tests.py
-description: Non-stale topologyVersion missing NotMaster error
+description: Non-stale topologyVersion missing NotWritablePrimary error
 uri: mongodb://a/?replicaSet=rs
 phases:
 - description: Primary A is discovered
   responses:
   - - a:27017
     - ok: 1
-      ismaster: true
+      helloOk: true
+      isWritablePrimary: true
       hosts:
       - a:27017
       setName: rs
@@ -29,7 +30,7 @@ phases:
     logicalSessionTimeoutMinutes: null
     setName: rs
 
-- description: Non-stale topologyVersion missing NotMaster error marks server Unknown
+- description: Non-stale topologyVersion missing NotWritablePrimary error marks server Unknown
   applicationErrors:
   - address: a:27017
     when: afterHandshakeCompletes
@@ -37,7 +38,7 @@ phases:
     type: command
     response:
       ok: 0
-      errmsg: NotMaster
+      errmsg: NotWritablePrimary
       code: 10107
   outcome:
     servers:
diff --git a/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-missing-PrimarySteppedDown.json b/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-missing-PrimarySteppedDown.json
index f7e0932542..8146a60d6e 100644
--- a/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-missing-PrimarySteppedDown.json
+++ b/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-missing-PrimarySteppedDown.json
@@ -9,7 +9,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
diff --git a/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-missing-PrimarySteppedDown.yml b/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-missing-PrimarySteppedDown.yml
index f248336cf3..8ca1251a2d 100644
--- a/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-missing-PrimarySteppedDown.yml
+++ b/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-missing-PrimarySteppedDown.yml
@@ -6,7 +6,8 @@ phases:
   responses:
   - - a:27017
     - ok: 1
-      ismaster: true
+      helloOk: true
+      isWritablePrimary: true
       hosts:
       - a:27017
       setName: rs
diff --git a/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-missing-ShutdownInProgress.json b/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-missing-ShutdownInProgress.json
index 5eceb1bcee..c7597007d7 100644
--- a/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-missing-ShutdownInProgress.json
+++ b/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-missing-ShutdownInProgress.json
@@ -9,7 +9,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
diff --git a/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-missing-ShutdownInProgress.yml b/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-missing-ShutdownInProgress.yml
index a02ac1a04c..cd8857008d 100644
--- a/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-missing-ShutdownInProgress.yml
+++ b/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-missing-ShutdownInProgress.yml
@@ -6,7 +6,8 @@ phases:
   responses:
   - - a:27017
     - ok: 1
-      ismaster: true
+      helloOk: true
+      isWritablePrimary: true
       hosts:
       - a:27017
       setName: rs
diff --git a/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-proccessId-changed-InterruptedAtShutdown.json b/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-proccessId-changed-InterruptedAtShutdown.json
index 2b77eb2087..8448c60599 100644
--- a/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-proccessId-changed-InterruptedAtShutdown.json
+++ b/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-proccessId-changed-InterruptedAtShutdown.json
@@ -9,7 +9,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
diff --git a/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-proccessId-changed-InterruptedAtShutdown.yml b/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-proccessId-changed-InterruptedAtShutdown.yml
index c2a0263694..126ed23b44 100644
--- a/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-proccessId-changed-InterruptedAtShutdown.yml
+++ b/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-proccessId-changed-InterruptedAtShutdown.yml
@@ -6,7 +6,8 @@ phases:
   responses:
   - - a:27017
     - ok: 1
-      ismaster: true
+      helloOk: true
+      isWritablePrimary: true
       hosts:
       - a:27017
       setName: rs
diff --git a/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-proccessId-changed-InterruptedDueToReplStateChange.json b/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-proccessId-changed-InterruptedDueToReplStateChange.json
index 584219e508..9d601c4ede 100644
--- a/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-proccessId-changed-InterruptedDueToReplStateChange.json
+++ b/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-proccessId-changed-InterruptedDueToReplStateChange.json
@@ -9,7 +9,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
diff --git a/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-proccessId-changed-InterruptedDueToReplStateChange.yml b/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-proccessId-changed-InterruptedDueToReplStateChange.yml
index 8317ecbee0..bcb69479d1 100644
--- a/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-proccessId-changed-InterruptedDueToReplStateChange.yml
+++ b/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-proccessId-changed-InterruptedDueToReplStateChange.yml
@@ -6,7 +6,8 @@ phases:
   responses:
   - - a:27017
     - ok: 1
-      ismaster: true
+      helloOk: true
+      isWritablePrimary: true
       hosts:
       - a:27017
       setName: rs
diff --git a/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-proccessId-changed-LegacyNotPrimary.json b/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-proccessId-changed-LegacyNotPrimary.json
new file mode 100644
index 0000000000..8be833f104
--- /dev/null
+++ b/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-proccessId-changed-LegacyNotPrimary.json
@@ -0,0 +1,100 @@
+{
+  "description": "Non-stale topologyVersion proccessId changed LegacyNotPrimary error",
+  "uri": "mongodb://a/?replicaSet=rs",
+  "phases": [
+    {
+      "description": "Primary A is discovered",
+      "responses": [
+        [
+          "a:27017",
+          {
+            "ok": 1,
+            "helloOk": true,
+            "isWritablePrimary": true,
+            "hosts": [
+              "a:27017"
+            ],
+            "setName": "rs",
+            "minWireVersion": 0,
+            "maxWireVersion": 9,
+            "topologyVersion": {
+              "processId": {
+                "$oid": "000000000000000000000001"
+              },
+              "counter": {
+                "$numberLong": "1"
+              }
+            }
+          }
+        ]
+      ],
+      "outcome": {
+        "servers": {
+          "a:27017": {
+            "type": "RSPrimary",
+            "setName": "rs",
+            "topologyVersion": {
+              "processId": {
+                "$oid": "000000000000000000000001"
+              },
+              "counter": {
+                "$numberLong": "1"
+              }
+            },
+            "pool": {
+              "generation": 0
+            }
+          }
+        },
+        "topologyType": "ReplicaSetWithPrimary",
+        "logicalSessionTimeoutMinutes": null,
+        "setName": "rs"
+      }
+    },
+    {
+      "description": "Non-stale topologyVersion proccessId changed LegacyNotPrimary error marks server Unknown",
+      "applicationErrors": [
+        {
+          "address": "a:27017",
+          "when": "afterHandshakeCompletes",
+          "maxWireVersion": 9,
+          "type": "command",
+          "response": {
+            "ok": 0,
+            "errmsg": "LegacyNotPrimary",
+            "code": 10058,
+            "topologyVersion": {
+              "processId": {
+                "$oid": "000000000000000000000002"
+              },
+              "counter": {
+                "$numberLong": "1"
+              }
+            }
+          }
+        }
+      ],
+      "outcome": {
+        "servers": {
+          "a:27017": {
+            "type": "Unknown",
+            "topologyVersion": {
+              "processId": {
+                "$oid": "000000000000000000000002"
+              },
+              "counter": {
+                "$numberLong": "1"
+              }
+            },
+            "pool": {
+              "generation": 0
+            }
+          }
+        },
+        "topologyType": "ReplicaSetNoPrimary",
+        "logicalSessionTimeoutMinutes": null,
+        "setName": "rs"
+      }
+    }
+  ]
+}
diff --git a/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-proccessId-changed-LegacyNotPrimary.yml b/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-proccessId-changed-LegacyNotPrimary.yml
new file mode 100644
index 0000000000..172240cb78
--- /dev/null
+++ b/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-proccessId-changed-LegacyNotPrimary.yml
@@ -0,0 +1,61 @@
+# Autogenerated tests for SDAM error handling, see generate-error-tests.py
+description: Non-stale topologyVersion proccessId changed LegacyNotPrimary error
+uri: mongodb://a/?replicaSet=rs
+phases:
+- description: Primary A is discovered
+  responses:
+  - - a:27017
+    - ok: 1
+      helloOk: true
+      isWritablePrimary: true
+      hosts:
+      - a:27017
+      setName: rs
+      minWireVersion: 0
+      maxWireVersion: 9
+      topologyVersion: &topologyVersion_1_1
+        processId:
+          "$oid": '000000000000000000000001'
+        counter:
+          "$numberLong": '1'
+  outcome: &outcome
+    servers:
+      a:27017:
+        type: RSPrimary
+        setName: rs
+        topologyVersion: *topologyVersion_1_1
+        pool:
+          generation: 0
+    topologyType: ReplicaSetWithPrimary
+    logicalSessionTimeoutMinutes: null
+    setName: rs
+
+- description: Non-stale topologyVersion proccessId changed LegacyNotPrimary error marks server Unknown
+  applicationErrors:
+  - address: a:27017
+    when: afterHandshakeCompletes
+    maxWireVersion: 9
+    type: command
+    response:
+      ok: 0
+      errmsg: LegacyNotPrimary
+      code: 10058
+      topologyVersion:
+        processId:
+          "$oid": '000000000000000000000002'
+        counter:
+          "$numberLong": "1"
+  outcome:
+    servers:
+      a:27017:
+        type: Unknown
+        topologyVersion:
+          processId:
+            "$oid": '000000000000000000000002'
+          counter:
+            "$numberLong": "1"
+        pool:
+          generation: 0
+    topologyType: ReplicaSetNoPrimary
+    logicalSessionTimeoutMinutes: null
+    setName: rs
diff --git a/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-proccessId-changed-NotMasterNoSlaveOk.json b/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-proccessId-changed-NotPrimaryNoSecondaryOk.json
similarity index 92%
rename from test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-proccessId-changed-NotMasterNoSlaveOk.json
rename to test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-proccessId-changed-NotPrimaryNoSecondaryOk.json
index 812b973524..f2f94c0d00 100644
--- a/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-proccessId-changed-NotMasterNoSlaveOk.json
+++ b/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-proccessId-changed-NotPrimaryNoSecondaryOk.json
@@ -1,5 +1,5 @@
 {
-  "description": "Non-stale topologyVersion proccessId changed NotMasterNoSlaveOk error",
+  "description": "Non-stale topologyVersion proccessId changed NotPrimaryNoSecondaryOk error",
   "uri": "mongodb://a/?replicaSet=rs",
   "phases": [
     {
@@ -9,7 +9,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
@@ -51,7 +52,7 @@
       }
     },
     {
-      "description": "Non-stale topologyVersion proccessId changed NotMasterNoSlaveOk error marks server Unknown",
+      "description": "Non-stale topologyVersion proccessId changed NotPrimaryNoSecondaryOk error marks server Unknown",
       "applicationErrors": [
         {
           "address": "a:27017",
@@ -60,7 +61,7 @@
           "type": "command",
           "response": {
             "ok": 0,
-            "errmsg": "NotMasterNoSlaveOk",
+            "errmsg": "NotPrimaryNoSecondaryOk",
             "code": 13435,
             "topologyVersion": {
               "processId": {
diff --git a/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-proccessId-changed-NotMasterNoSlaveOk.yml b/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-proccessId-changed-NotPrimaryNoSecondaryOk.yml
similarity index 82%
rename from test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-proccessId-changed-NotMasterNoSlaveOk.yml
rename to test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-proccessId-changed-NotPrimaryNoSecondaryOk.yml
index 12b7a21a6a..b915fb97f3 100644
--- a/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-proccessId-changed-NotMasterNoSlaveOk.yml
+++ b/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-proccessId-changed-NotPrimaryNoSecondaryOk.yml
@@ -1,12 +1,13 @@
 # Autogenerated tests for SDAM error handling, see generate-error-tests.py
-description: Non-stale topologyVersion proccessId changed NotMasterNoSlaveOk error
+description: Non-stale topologyVersion proccessId changed NotPrimaryNoSecondaryOk error
 uri: mongodb://a/?replicaSet=rs
 phases:
 - description: Primary A is discovered
   responses:
   - - a:27017
     - ok: 1
-      ismaster: true
+      helloOk: true
+      isWritablePrimary: true
       hosts:
       - a:27017
       setName: rs
@@ -29,7 +30,7 @@ phases:
     logicalSessionTimeoutMinutes: null
     setName: rs
 
-- description: Non-stale topologyVersion proccessId changed NotMasterNoSlaveOk error marks server Unknown
+- description: Non-stale topologyVersion proccessId changed NotPrimaryNoSecondaryOk error marks server Unknown
   applicationErrors:
   - address: a:27017
     when: afterHandshakeCompletes
@@ -37,7 +38,7 @@ phases:
     type: command
     response:
       ok: 0
-      errmsg: NotMasterNoSlaveOk
+      errmsg: NotPrimaryNoSecondaryOk
       code: 13435
       topologyVersion:
         processId:
diff --git a/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-proccessId-changed-NotMasterOrSecondary.json b/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-proccessId-changed-NotPrimaryOrSecondary.json
similarity index 92%
rename from test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-proccessId-changed-NotMasterOrSecondary.json
rename to test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-proccessId-changed-NotPrimaryOrSecondary.json
index 027f4bddee..6d3b397566 100644
--- a/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-proccessId-changed-NotMasterOrSecondary.json
+++ b/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-proccessId-changed-NotPrimaryOrSecondary.json
@@ -1,5 +1,5 @@
 {
-  "description": "Non-stale topologyVersion proccessId changed NotMasterOrSecondary error",
+  "description": "Non-stale topologyVersion proccessId changed NotPrimaryOrSecondary error",
   "uri": "mongodb://a/?replicaSet=rs",
   "phases": [
     {
@@ -9,7 +9,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
@@ -51,7 +52,7 @@
       }
     },
     {
-      "description": "Non-stale topologyVersion proccessId changed NotMasterOrSecondary error marks server Unknown",
+      "description": "Non-stale topologyVersion proccessId changed NotPrimaryOrSecondary error marks server Unknown",
       "applicationErrors": [
         {
           "address": "a:27017",
@@ -60,7 +61,7 @@
           "type": "command",
           "response": {
             "ok": 0,
-            "errmsg": "NotMasterOrSecondary",
+            "errmsg": "NotPrimaryOrSecondary",
             "code": 13436,
             "topologyVersion": {
               "processId": {
diff --git a/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-proccessId-changed-NotMasterOrSecondary.yml b/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-proccessId-changed-NotPrimaryOrSecondary.yml
similarity index 82%
rename from test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-proccessId-changed-NotMasterOrSecondary.yml
rename to test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-proccessId-changed-NotPrimaryOrSecondary.yml
index 3531a1d85a..dc104488cd 100644
--- a/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-proccessId-changed-NotMasterOrSecondary.yml
+++ b/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-proccessId-changed-NotPrimaryOrSecondary.yml
@@ -1,12 +1,13 @@
 # Autogenerated tests for SDAM error handling, see generate-error-tests.py
-description: Non-stale topologyVersion proccessId changed NotMasterOrSecondary error
+description: Non-stale topologyVersion proccessId changed NotPrimaryOrSecondary error
 uri: mongodb://a/?replicaSet=rs
 phases:
 - description: Primary A is discovered
   responses:
   - - a:27017
     - ok: 1
-      ismaster: true
+      helloOk: true
+      isWritablePrimary: true
       hosts:
       - a:27017
       setName: rs
@@ -29,7 +30,7 @@ phases:
     logicalSessionTimeoutMinutes: null
     setName: rs
 
-- description: Non-stale topologyVersion proccessId changed NotMasterOrSecondary error marks server Unknown
+- description: Non-stale topologyVersion proccessId changed NotPrimaryOrSecondary error marks server Unknown
   applicationErrors:
   - address: a:27017
     when: afterHandshakeCompletes
@@ -37,7 +38,7 @@ phases:
     type: command
     response:
       ok: 0
-      errmsg: NotMasterOrSecondary
+      errmsg: NotPrimaryOrSecondary
       code: 13436
       topologyVersion:
         processId:
diff --git a/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-proccessId-changed-NotMaster.json b/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-proccessId-changed-NotWritablePrimary.json
similarity index 92%
rename from test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-proccessId-changed-NotMaster.json
rename to test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-proccessId-changed-NotWritablePrimary.json
index b7bdfabd2d..332ddf5ec1 100644
--- a/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-proccessId-changed-NotMaster.json
+++ b/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-proccessId-changed-NotWritablePrimary.json
@@ -1,5 +1,5 @@
 {
-  "description": "Non-stale topologyVersion proccessId changed NotMaster error",
+  "description": "Non-stale topologyVersion proccessId changed NotWritablePrimary error",
   "uri": "mongodb://a/?replicaSet=rs",
   "phases": [
     {
@@ -9,7 +9,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
@@ -51,7 +52,7 @@
       }
     },
     {
-      "description": "Non-stale topologyVersion proccessId changed NotMaster error marks server Unknown",
+      "description": "Non-stale topologyVersion proccessId changed NotWritablePrimary error marks server Unknown",
       "applicationErrors": [
         {
           "address": "a:27017",
@@ -60,7 +61,7 @@
           "type": "command",
           "response": {
             "ok": 0,
-            "errmsg": "NotMaster",
+            "errmsg": "NotWritablePrimary",
             "code": 10107,
             "topologyVersion": {
               "processId": {
diff --git a/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-proccessId-changed-NotMaster.yml b/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-proccessId-changed-NotWritablePrimary.yml
similarity index 83%
rename from test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-proccessId-changed-NotMaster.yml
rename to test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-proccessId-changed-NotWritablePrimary.yml
index b753d838ad..5146636b65 100644
--- a/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-proccessId-changed-NotMaster.yml
+++ b/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-proccessId-changed-NotWritablePrimary.yml
@@ -1,12 +1,13 @@
 # Autogenerated tests for SDAM error handling, see generate-error-tests.py
-description: Non-stale topologyVersion proccessId changed NotMaster error
+description: Non-stale topologyVersion proccessId changed NotWritablePrimary error
 uri: mongodb://a/?replicaSet=rs
 phases:
 - description: Primary A is discovered
   responses:
   - - a:27017
     - ok: 1
-      ismaster: true
+      helloOk: true
+      isWritablePrimary: true
       hosts:
       - a:27017
       setName: rs
@@ -29,7 +30,7 @@ phases:
     logicalSessionTimeoutMinutes: null
     setName: rs
 
-- description: Non-stale topologyVersion proccessId changed NotMaster error marks server Unknown
+- description: Non-stale topologyVersion proccessId changed NotWritablePrimary error marks server Unknown
   applicationErrors:
   - address: a:27017
     when: afterHandshakeCompletes
@@ -37,7 +38,7 @@ phases:
     type: command
     response:
       ok: 0
-      errmsg: NotMaster
+      errmsg: NotWritablePrimary
       code: 10107
       topologyVersion:
         processId:
diff --git a/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-proccessId-changed-PrimarySteppedDown.json b/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-proccessId-changed-PrimarySteppedDown.json
index 6a49618cfd..c22a537f58 100644
--- a/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-proccessId-changed-PrimarySteppedDown.json
+++ b/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-proccessId-changed-PrimarySteppedDown.json
@@ -9,7 +9,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
diff --git a/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-proccessId-changed-PrimarySteppedDown.yml b/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-proccessId-changed-PrimarySteppedDown.yml
index ff7223bcf6..0c997a2a3e 100644
--- a/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-proccessId-changed-PrimarySteppedDown.yml
+++ b/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-proccessId-changed-PrimarySteppedDown.yml
@@ -6,7 +6,8 @@ phases:
   responses:
   - - a:27017
     - ok: 1
-      ismaster: true
+      helloOk: true
+      isWritablePrimary: true
       hosts:
       - a:27017
       setName: rs
diff --git a/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-proccessId-changed-ShutdownInProgress.json b/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-proccessId-changed-ShutdownInProgress.json
index 3c3c934f8e..eaaab79273 100644
--- a/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-proccessId-changed-ShutdownInProgress.json
+++ b/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-proccessId-changed-ShutdownInProgress.json
@@ -9,7 +9,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
diff --git a/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-proccessId-changed-ShutdownInProgress.yml b/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-proccessId-changed-ShutdownInProgress.yml
index 0efea10939..973c56460b 100644
--- a/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-proccessId-changed-ShutdownInProgress.yml
+++ b/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-proccessId-changed-ShutdownInProgress.yml
@@ -6,7 +6,8 @@ phases:
   responses:
   - - a:27017
     - ok: 1
-      ismaster: true
+      helloOk: true
+      isWritablePrimary: true
       hosts:
       - a:27017
       setName: rs
diff --git a/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion.yml.template b/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion.yml.template
index 22c56b63b6..83cff68e27 100644
--- a/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion.yml.template
+++ b/test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion.yml.template
@@ -6,7 +6,8 @@ phases:
   responses:
   - - a:27017
     - ok: 1
-      ismaster: true
+      helloOk: true
+      isWritablePrimary: true
       hosts:
       - a:27017
       setName: rs
diff --git a/test/spec/server-discovery-and-monitoring/errors/post-42-InterruptedAtShutdown.json b/test/spec/server-discovery-and-monitoring/errors/post-42-InterruptedAtShutdown.json
index 9e171142d1..40c4ed6c80 100644
--- a/test/spec/server-discovery-and-monitoring/errors/post-42-InterruptedAtShutdown.json
+++ b/test/spec/server-discovery-and-monitoring/errors/post-42-InterruptedAtShutdown.json
@@ -9,7 +9,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
diff --git a/test/spec/server-discovery-and-monitoring/errors/post-42-InterruptedAtShutdown.yml b/test/spec/server-discovery-and-monitoring/errors/post-42-InterruptedAtShutdown.yml
index c305131418..73a0f0d285 100644
--- a/test/spec/server-discovery-and-monitoring/errors/post-42-InterruptedAtShutdown.yml
+++ b/test/spec/server-discovery-and-monitoring/errors/post-42-InterruptedAtShutdown.yml
@@ -6,7 +6,8 @@ phases:
   responses:
   - - a:27017
     - ok: 1
-      ismaster: true
+      helloOk: true
+      isWritablePrimary: true
       hosts:
       - a:27017
       setName: rs
diff --git a/test/spec/server-discovery-and-monitoring/errors/post-42-InterruptedDueToReplStateChange.json b/test/spec/server-discovery-and-monitoring/errors/post-42-InterruptedDueToReplStateChange.json
index 52410f0b27..5c489f5ecb 100644
--- a/test/spec/server-discovery-and-monitoring/errors/post-42-InterruptedDueToReplStateChange.json
+++ b/test/spec/server-discovery-and-monitoring/errors/post-42-InterruptedDueToReplStateChange.json
@@ -9,7 +9,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
diff --git a/test/spec/server-discovery-and-monitoring/errors/post-42-InterruptedDueToReplStateChange.yml b/test/spec/server-discovery-and-monitoring/errors/post-42-InterruptedDueToReplStateChange.yml
index d3521bd743..ad333e311e 100644
--- a/test/spec/server-discovery-and-monitoring/errors/post-42-InterruptedDueToReplStateChange.yml
+++ b/test/spec/server-discovery-and-monitoring/errors/post-42-InterruptedDueToReplStateChange.yml
@@ -6,7 +6,8 @@ phases:
   responses:
   - - a:27017
     - ok: 1
-      ismaster: true
+      helloOk: true
+      isWritablePrimary: true
       hosts:
       - a:27017
       setName: rs
diff --git a/test/spec/server-discovery-and-monitoring/errors/post-42-LegacyNotPrimary.json b/test/spec/server-discovery-and-monitoring/errors/post-42-LegacyNotPrimary.json
new file mode 100644
index 0000000000..f0851b299e
--- /dev/null
+++ b/test/spec/server-discovery-and-monitoring/errors/post-42-LegacyNotPrimary.json
@@ -0,0 +1,70 @@
+{
+  "description": "Post-4.2 LegacyNotPrimary error",
+  "uri": "mongodb://a/?replicaSet=rs",
+  "phases": [
+    {
+      "description": "Primary A is discovered",
+      "responses": [
+        [
+          "a:27017",
+          {
+            "ok": 1,
+            "helloOk": true,
+            "isWritablePrimary": true,
+            "hosts": [
+              "a:27017"
+            ],
+            "setName": "rs",
+            "minWireVersion": 0,
+            "maxWireVersion": 8
+          }
+        ]
+      ],
+      "outcome": {
+        "servers": {
+          "a:27017": {
+            "type": "RSPrimary",
+            "setName": "rs",
+            "topologyVersion": null,
+            "pool": {
+              "generation": 0
+            }
+          }
+        },
+        "topologyType": "ReplicaSetWithPrimary",
+        "logicalSessionTimeoutMinutes": null,
+        "setName": "rs"
+      }
+    },
+    {
+      "description": "Post-4.2 LegacyNotPrimary error marks server Unknown",
+      "applicationErrors": [
+        {
+          "address": "a:27017",
+          "when": "afterHandshakeCompletes",
+          "maxWireVersion": 8,
+          "type": "command",
+          "response": {
+            "ok": 0,
+            "errmsg": "LegacyNotPrimary",
+            "code": 10058
+          }
+        }
+      ],
+      "outcome": {
+        "servers": {
+          "a:27017": {
+            "type": "Unknown",
+            "topologyVersion": null,
+            "pool": {
+              "generation": 0
+            }
+          }
+        },
+        "topologyType": "ReplicaSetNoPrimary",
+        "logicalSessionTimeoutMinutes": null,
+        "setName": "rs"
+      }
+    }
+  ]
+}
diff --git a/test/spec/server-discovery-and-monitoring/errors/post-42-LegacyNotPrimary.yml b/test/spec/server-discovery-and-monitoring/errors/post-42-LegacyNotPrimary.yml
new file mode 100644
index 0000000000..9c7723bbf3
--- /dev/null
+++ b/test/spec/server-discovery-and-monitoring/errors/post-42-LegacyNotPrimary.yml
@@ -0,0 +1,47 @@
+# Autogenerated tests for SDAM error handling, see generate-error-tests.py
+description: Post-4.2 LegacyNotPrimary error
+uri: mongodb://a/?replicaSet=rs
+phases:
+- description: Primary A is discovered
+  responses:
+  - - a:27017
+    - ok: 1
+      helloOk: true
+      isWritablePrimary: true
+      hosts:
+      - a:27017
+      setName: rs
+      minWireVersion: 0
+      maxWireVersion: 8
+  outcome: &outcome
+    servers:
+      a:27017:
+        type: RSPrimary
+        setName: rs
+        topologyVersion: null
+        pool:
+          generation: 0
+    topologyType: ReplicaSetWithPrimary
+    logicalSessionTimeoutMinutes: null
+    setName: rs
+
+- description: Post-4.2 LegacyNotPrimary error marks server Unknown
+  applicationErrors:
+  - address: a:27017
+    when: afterHandshakeCompletes
+    maxWireVersion: 8
+    type: command
+    response:
+      ok: 0
+      errmsg: LegacyNotPrimary
+      code: 10058
+  outcome:
+    servers:
+      a:27017:
+        type: Unknown
+        topologyVersion: null
+        pool:
+          generation: 0
+    topologyType: ReplicaSetNoPrimary
+    logicalSessionTimeoutMinutes: null
+    setName: rs
diff --git a/test/spec/server-discovery-and-monitoring/errors/post-42-NotMasterNoSlaveOk.json b/test/spec/server-discovery-and-monitoring/errors/post-42-NotPrimaryNoSecondaryOk.json
similarity index 84%
rename from test/spec/server-discovery-and-monitoring/errors/post-42-NotMasterNoSlaveOk.json
rename to test/spec/server-discovery-and-monitoring/errors/post-42-NotPrimaryNoSecondaryOk.json
index fa5c1f37d5..a675f0ca54 100644
--- a/test/spec/server-discovery-and-monitoring/errors/post-42-NotMasterNoSlaveOk.json
+++ b/test/spec/server-discovery-and-monitoring/errors/post-42-NotPrimaryNoSecondaryOk.json
@@ -1,5 +1,5 @@
 {
-  "description": "Post-4.2 NotMasterNoSlaveOk error",
+  "description": "Post-4.2 NotPrimaryNoSecondaryOk error",
   "uri": "mongodb://a/?replicaSet=rs",
   "phases": [
     {
@@ -9,7 +9,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
@@ -36,7 +37,7 @@
       }
     },
     {
-      "description": "Post-4.2 NotMasterNoSlaveOk error marks server Unknown",
+      "description": "Post-4.2 NotPrimaryNoSecondaryOk error marks server Unknown",
       "applicationErrors": [
         {
           "address": "a:27017",
@@ -45,7 +46,7 @@
           "type": "command",
           "response": {
             "ok": 0,
-            "errmsg": "NotMasterNoSlaveOk",
+            "errmsg": "NotPrimaryNoSecondaryOk",
             "code": 13435
           }
         }
diff --git a/test/spec/server-discovery-and-monitoring/errors/post-42-NotMasterNoSlaveOk.yml b/test/spec/server-discovery-and-monitoring/errors/post-42-NotPrimaryNoSecondaryOk.yml
similarity index 81%
rename from test/spec/server-discovery-and-monitoring/errors/post-42-NotMasterNoSlaveOk.yml
rename to test/spec/server-discovery-and-monitoring/errors/post-42-NotPrimaryNoSecondaryOk.yml
index 2481cad869..49304d6d63 100644
--- a/test/spec/server-discovery-and-monitoring/errors/post-42-NotMasterNoSlaveOk.yml
+++ b/test/spec/server-discovery-and-monitoring/errors/post-42-NotPrimaryNoSecondaryOk.yml
@@ -1,12 +1,13 @@
 # Autogenerated tests for SDAM error handling, see generate-error-tests.py
-description: Post-4.2 NotMasterNoSlaveOk error
+description: Post-4.2 NotPrimaryNoSecondaryOk error
 uri: mongodb://a/?replicaSet=rs
 phases:
 - description: Primary A is discovered
   responses:
   - - a:27017
     - ok: 1
-      ismaster: true
+      helloOk: true
+      isWritablePrimary: true
       hosts:
       - a:27017
       setName: rs
@@ -24,7 +25,7 @@ phases:
     logicalSessionTimeoutMinutes: null
     setName: rs
 
-- description: Post-4.2 NotMasterNoSlaveOk error marks server Unknown
+- description: Post-4.2 NotPrimaryNoSecondaryOk error marks server Unknown
   applicationErrors:
   - address: a:27017
     when: afterHandshakeCompletes
@@ -32,7 +33,7 @@ phases:
     type: command
     response:
       ok: 0
-      errmsg: NotMasterNoSlaveOk
+      errmsg: NotPrimaryNoSecondaryOk
       code: 13435
   outcome:
     servers:
diff --git a/test/spec/server-discovery-and-monitoring/errors/post-42-NotMasterOrSecondary.json b/test/spec/server-discovery-and-monitoring/errors/post-42-NotPrimaryOrSecondary.json
similarity index 84%
rename from test/spec/server-discovery-and-monitoring/errors/post-42-NotMasterOrSecondary.json
rename to test/spec/server-discovery-and-monitoring/errors/post-42-NotPrimaryOrSecondary.json
index 5023662723..ea9bf1d16b 100644
--- a/test/spec/server-discovery-and-monitoring/errors/post-42-NotMasterOrSecondary.json
+++ b/test/spec/server-discovery-and-monitoring/errors/post-42-NotPrimaryOrSecondary.json
@@ -1,5 +1,5 @@
 {
-  "description": "Post-4.2 NotMasterOrSecondary error",
+  "description": "Post-4.2 NotPrimaryOrSecondary error",
   "uri": "mongodb://a/?replicaSet=rs",
   "phases": [
     {
@@ -9,7 +9,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
@@ -36,7 +37,7 @@
       }
     },
     {
-      "description": "Post-4.2 NotMasterOrSecondary error marks server Unknown",
+      "description": "Post-4.2 NotPrimaryOrSecondary error marks server Unknown",
       "applicationErrors": [
         {
           "address": "a:27017",
@@ -45,7 +46,7 @@
           "type": "command",
           "response": {
             "ok": 0,
-            "errmsg": "NotMasterOrSecondary",
+            "errmsg": "NotPrimaryOrSecondary",
             "code": 13436
           }
         }
diff --git a/test/spec/server-discovery-and-monitoring/errors/post-42-NotMasterOrSecondary.yml b/test/spec/server-discovery-and-monitoring/errors/post-42-NotPrimaryOrSecondary.yml
similarity index 81%
rename from test/spec/server-discovery-and-monitoring/errors/post-42-NotMasterOrSecondary.yml
rename to test/spec/server-discovery-and-monitoring/errors/post-42-NotPrimaryOrSecondary.yml
index 1f8e65ad2d..9174b31057 100644
--- a/test/spec/server-discovery-and-monitoring/errors/post-42-NotMasterOrSecondary.yml
+++ b/test/spec/server-discovery-and-monitoring/errors/post-42-NotPrimaryOrSecondary.yml
@@ -1,12 +1,13 @@
 # Autogenerated tests for SDAM error handling, see generate-error-tests.py
-description: Post-4.2 NotMasterOrSecondary error
+description: Post-4.2 NotPrimaryOrSecondary error
 uri: mongodb://a/?replicaSet=rs
 phases:
 - description: Primary A is discovered
   responses:
   - - a:27017
     - ok: 1
-      ismaster: true
+      helloOk: true
+      isWritablePrimary: true
       hosts:
       - a:27017
       setName: rs
@@ -24,7 +25,7 @@ phases:
     logicalSessionTimeoutMinutes: null
     setName: rs
 
-- description: Post-4.2 NotMasterOrSecondary error marks server Unknown
+- description: Post-4.2 NotPrimaryOrSecondary error marks server Unknown
   applicationErrors:
   - address: a:27017
     when: afterHandshakeCompletes
@@ -32,7 +33,7 @@ phases:
     type: command
     response:
       ok: 0
-      errmsg: NotMasterOrSecondary
+      errmsg: NotPrimaryOrSecondary
       code: 13436
   outcome:
     servers:
diff --git a/test/spec/server-discovery-and-monitoring/errors/post-42-NotMaster.json b/test/spec/server-discovery-and-monitoring/errors/post-42-NotWritablePrimary.json
similarity index 85%
rename from test/spec/server-discovery-and-monitoring/errors/post-42-NotMaster.json
rename to test/spec/server-discovery-and-monitoring/errors/post-42-NotWritablePrimary.json
index 6cbb23b89c..10211fca70 100644
--- a/test/spec/server-discovery-and-monitoring/errors/post-42-NotMaster.json
+++ b/test/spec/server-discovery-and-monitoring/errors/post-42-NotWritablePrimary.json
@@ -1,5 +1,5 @@
 {
-  "description": "Post-4.2 NotMaster error",
+  "description": "Post-4.2 NotWritablePrimary error",
   "uri": "mongodb://a/?replicaSet=rs",
   "phases": [
     {
@@ -9,7 +9,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
@@ -36,7 +37,7 @@
       }
     },
     {
-      "description": "Post-4.2 NotMaster error marks server Unknown",
+      "description": "Post-4.2 NotWritablePrimary error marks server Unknown",
       "applicationErrors": [
         {
           "address": "a:27017",
@@ -45,7 +46,7 @@
           "type": "command",
           "response": {
             "ok": 0,
-            "errmsg": "NotMaster",
+            "errmsg": "NotWritablePrimary",
             "code": 10107
           }
         }
diff --git a/test/spec/server-discovery-and-monitoring/errors/post-42-NotMaster.yml b/test/spec/server-discovery-and-monitoring/errors/post-42-NotWritablePrimary.yml
similarity index 82%
rename from test/spec/server-discovery-and-monitoring/errors/post-42-NotMaster.yml
rename to test/spec/server-discovery-and-monitoring/errors/post-42-NotWritablePrimary.yml
index 2a01f1ccba..886b1f5b5b 100644
--- a/test/spec/server-discovery-and-monitoring/errors/post-42-NotMaster.yml
+++ b/test/spec/server-discovery-and-monitoring/errors/post-42-NotWritablePrimary.yml
@@ -1,12 +1,13 @@
 # Autogenerated tests for SDAM error handling, see generate-error-tests.py
-description: Post-4.2 NotMaster error
+description: Post-4.2 NotWritablePrimary error
 uri: mongodb://a/?replicaSet=rs
 phases:
 - description: Primary A is discovered
   responses:
   - - a:27017
     - ok: 1
-      ismaster: true
+      helloOk: true
+      isWritablePrimary: true
       hosts:
       - a:27017
       setName: rs
@@ -24,7 +25,7 @@ phases:
     logicalSessionTimeoutMinutes: null
     setName: rs
 
-- description: Post-4.2 NotMaster error marks server Unknown
+- description: Post-4.2 NotWritablePrimary error marks server Unknown
   applicationErrors:
   - address: a:27017
     when: afterHandshakeCompletes
@@ -32,7 +33,7 @@ phases:
     type: command
     response:
       ok: 0
-      errmsg: NotMaster
+      errmsg: NotWritablePrimary
       code: 10107
   outcome:
     servers:
diff --git a/test/spec/server-discovery-and-monitoring/errors/post-42-PrimarySteppedDown.json b/test/spec/server-discovery-and-monitoring/errors/post-42-PrimarySteppedDown.json
index d58ff26e52..fa98d0bf06 100644
--- a/test/spec/server-discovery-and-monitoring/errors/post-42-PrimarySteppedDown.json
+++ b/test/spec/server-discovery-and-monitoring/errors/post-42-PrimarySteppedDown.json
@@ -9,7 +9,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
diff --git a/test/spec/server-discovery-and-monitoring/errors/post-42-PrimarySteppedDown.yml b/test/spec/server-discovery-and-monitoring/errors/post-42-PrimarySteppedDown.yml
index 38211af72d..6a42267996 100644
--- a/test/spec/server-discovery-and-monitoring/errors/post-42-PrimarySteppedDown.yml
+++ b/test/spec/server-discovery-and-monitoring/errors/post-42-PrimarySteppedDown.yml
@@ -6,7 +6,8 @@ phases:
   responses:
   - - a:27017
     - ok: 1
-      ismaster: true
+      helloOk: true
+      isWritablePrimary: true
       hosts:
       - a:27017
       setName: rs
diff --git a/test/spec/server-discovery-and-monitoring/errors/post-42-ShutdownInProgress.json b/test/spec/server-discovery-and-monitoring/errors/post-42-ShutdownInProgress.json
index a44ecc3824..cd587205b6 100644
--- a/test/spec/server-discovery-and-monitoring/errors/post-42-ShutdownInProgress.json
+++ b/test/spec/server-discovery-and-monitoring/errors/post-42-ShutdownInProgress.json
@@ -9,7 +9,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
diff --git a/test/spec/server-discovery-and-monitoring/errors/post-42-ShutdownInProgress.yml b/test/spec/server-discovery-and-monitoring/errors/post-42-ShutdownInProgress.yml
index 76de04df9e..2ad90d9864 100644
--- a/test/spec/server-discovery-and-monitoring/errors/post-42-ShutdownInProgress.yml
+++ b/test/spec/server-discovery-and-monitoring/errors/post-42-ShutdownInProgress.yml
@@ -6,7 +6,8 @@ phases:
   responses:
   - - a:27017
     - ok: 1
-      ismaster: true
+      helloOk: true
+      isWritablePrimary: true
       hosts:
       - a:27017
       setName: rs
diff --git a/test/spec/server-discovery-and-monitoring/errors/post-42.yml.template b/test/spec/server-discovery-and-monitoring/errors/post-42.yml.template
index 251961f93b..8ca3c79ba4 100644
--- a/test/spec/server-discovery-and-monitoring/errors/post-42.yml.template
+++ b/test/spec/server-discovery-and-monitoring/errors/post-42.yml.template
@@ -6,7 +6,8 @@ phases:
   responses:
   - - a:27017
     - ok: 1
-      ismaster: true
+      helloOk: true
+      isWritablePrimary: true
       hosts:
       - a:27017
       setName: rs
diff --git a/test/spec/server-discovery-and-monitoring/errors/pre-42-InterruptedAtShutdown.json b/test/spec/server-discovery-and-monitoring/errors/pre-42-InterruptedAtShutdown.json
index 5944fe705c..9f6ea212e5 100644
--- a/test/spec/server-discovery-and-monitoring/errors/pre-42-InterruptedAtShutdown.json
+++ b/test/spec/server-discovery-and-monitoring/errors/pre-42-InterruptedAtShutdown.json
@@ -9,7 +9,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
diff --git a/test/spec/server-discovery-and-monitoring/errors/pre-42-InterruptedAtShutdown.yml b/test/spec/server-discovery-and-monitoring/errors/pre-42-InterruptedAtShutdown.yml
index 16b4fe638b..4996e9f25f 100644
--- a/test/spec/server-discovery-and-monitoring/errors/pre-42-InterruptedAtShutdown.yml
+++ b/test/spec/server-discovery-and-monitoring/errors/pre-42-InterruptedAtShutdown.yml
@@ -6,7 +6,8 @@ phases:
   responses:
   - - a:27017
     - ok: 1
-      ismaster: true
+      helloOk: true
+      isWritablePrimary: true
       hosts:
       - a:27017
       setName: rs
diff --git a/test/spec/server-discovery-and-monitoring/errors/pre-42-InterruptedDueToReplStateChange.json b/test/spec/server-discovery-and-monitoring/errors/pre-42-InterruptedDueToReplStateChange.json
index 06ed118779..7e5f235713 100644
--- a/test/spec/server-discovery-and-monitoring/errors/pre-42-InterruptedDueToReplStateChange.json
+++ b/test/spec/server-discovery-and-monitoring/errors/pre-42-InterruptedDueToReplStateChange.json
@@ -9,7 +9,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
diff --git a/test/spec/server-discovery-and-monitoring/errors/pre-42-InterruptedDueToReplStateChange.yml b/test/spec/server-discovery-and-monitoring/errors/pre-42-InterruptedDueToReplStateChange.yml
index 3feac00df5..ada5f1ff73 100644
--- a/test/spec/server-discovery-and-monitoring/errors/pre-42-InterruptedDueToReplStateChange.yml
+++ b/test/spec/server-discovery-and-monitoring/errors/pre-42-InterruptedDueToReplStateChange.yml
@@ -6,7 +6,8 @@ phases:
   responses:
   - - a:27017
     - ok: 1
-      ismaster: true
+      helloOk: true
+      isWritablePrimary: true
       hosts:
       - a:27017
       setName: rs
diff --git a/test/spec/server-discovery-and-monitoring/errors/pre-42-NotMaster.json b/test/spec/server-discovery-and-monitoring/errors/pre-42-LegacyNotPrimary.json
similarity index 82%
rename from test/spec/server-discovery-and-monitoring/errors/pre-42-NotMaster.json
rename to test/spec/server-discovery-and-monitoring/errors/pre-42-LegacyNotPrimary.json
index a6a6bba87a..1635f1a856 100644
--- a/test/spec/server-discovery-and-monitoring/errors/pre-42-NotMaster.json
+++ b/test/spec/server-discovery-and-monitoring/errors/pre-42-LegacyNotPrimary.json
@@ -1,5 +1,5 @@
 {
-  "description": "Pre-4.2 NotMaster error",
+  "description": "Pre-4.2 LegacyNotPrimary error",
   "uri": "mongodb://a/?replicaSet=rs",
   "phases": [
     {
@@ -9,7 +9,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
@@ -36,7 +37,7 @@
       }
     },
     {
-      "description": "Pre-4.2 NotMaster error marks server Unknown and clears the pool",
+      "description": "Pre-4.2 LegacyNotPrimary error marks server Unknown and clears the pool",
       "applicationErrors": [
         {
           "address": "a:27017",
@@ -45,8 +46,8 @@
           "type": "command",
           "response": {
             "ok": 0,
-            "errmsg": "NotMaster",
-            "code": 10107
+            "errmsg": "LegacyNotPrimary",
+            "code": 10058
           }
         }
       ],
diff --git a/test/spec/server-discovery-and-monitoring/errors/pre-42-NotMaster.yml b/test/spec/server-discovery-and-monitoring/errors/pre-42-LegacyNotPrimary.yml
similarity index 79%
rename from test/spec/server-discovery-and-monitoring/errors/pre-42-NotMaster.yml
rename to test/spec/server-discovery-and-monitoring/errors/pre-42-LegacyNotPrimary.yml
index 522480a4b9..e2b37b4f5f 100644
--- a/test/spec/server-discovery-and-monitoring/errors/pre-42-NotMaster.yml
+++ b/test/spec/server-discovery-and-monitoring/errors/pre-42-LegacyNotPrimary.yml
@@ -1,12 +1,13 @@
 # Autogenerated tests for SDAM error handling, see generate-error-tests.py
-description: Pre-4.2 NotMaster error
+description: Pre-4.2 LegacyNotPrimary error
 uri: mongodb://a/?replicaSet=rs
 phases:
 - description: Primary A is discovered
   responses:
   - - a:27017
     - ok: 1
-      ismaster: true
+      helloOk: true
+      isWritablePrimary: true
       hosts:
       - a:27017
       setName: rs
@@ -24,7 +25,7 @@ phases:
     logicalSessionTimeoutMinutes: null
     setName: rs
 
-- description: Pre-4.2 NotMaster error marks server Unknown and clears the pool
+- description: Pre-4.2 LegacyNotPrimary error marks server Unknown and clears the pool
   applicationErrors:
   - address: a:27017
     when: afterHandshakeCompletes
@@ -32,8 +33,8 @@ phases:
     type: command
     response:
       ok: 0
-      errmsg: NotMaster
-      code: 10107
+      errmsg: LegacyNotPrimary
+      code: 10058
   outcome:
     servers:
       a:27017:
diff --git a/test/spec/server-discovery-and-monitoring/errors/pre-42-NotPrimaryNoSecondaryOk.json b/test/spec/server-discovery-and-monitoring/errors/pre-42-NotPrimaryNoSecondaryOk.json
new file mode 100644
index 0000000000..0e70ede02c
--- /dev/null
+++ b/test/spec/server-discovery-and-monitoring/errors/pre-42-NotPrimaryNoSecondaryOk.json
@@ -0,0 +1,70 @@
+{
+  "description": "Pre-4.2 NotPrimaryNoSecondaryOk error",
+  "uri": "mongodb://a/?replicaSet=rs",
+  "phases": [
+    {
+      "description": "Primary A is discovered",
+      "responses": [
+        [
+          "a:27017",
+          {
+            "ok": 1,
+            "helloOk": true,
+            "isWritablePrimary": true,
+            "hosts": [
+              "a:27017"
+            ],
+            "setName": "rs",
+            "minWireVersion": 0,
+            "maxWireVersion": 7
+          }
+        ]
+      ],
+      "outcome": {
+        "servers": {
+          "a:27017": {
+            "type": "RSPrimary",
+            "setName": "rs",
+            "topologyVersion": null,
+            "pool": {
+              "generation": 0
+            }
+          }
+        },
+        "topologyType": "ReplicaSetWithPrimary",
+        "logicalSessionTimeoutMinutes": null,
+        "setName": "rs"
+      }
+    },
+    {
+      "description": "Pre-4.2 NotPrimaryNoSecondaryOk error marks server Unknown and clears the pool",
+      "applicationErrors": [
+        {
+          "address": "a:27017",
+          "when": "afterHandshakeCompletes",
+          "maxWireVersion": 7,
+          "type": "command",
+          "response": {
+            "ok": 0,
+            "errmsg": "NotPrimaryNoSecondaryOk",
+            "code": 13435
+          }
+        }
+      ],
+      "outcome": {
+        "servers": {
+          "a:27017": {
+            "type": "Unknown",
+            "topologyVersion": null,
+            "pool": {
+              "generation": 1
+            }
+          }
+        },
+        "topologyType": "ReplicaSetNoPrimary",
+        "logicalSessionTimeoutMinutes": null,
+        "setName": "rs"
+      }
+    }
+  ]
+}
diff --git a/test/spec/server-discovery-and-monitoring/errors/pre-42-NotPrimaryNoSecondaryOk.yml b/test/spec/server-discovery-and-monitoring/errors/pre-42-NotPrimaryNoSecondaryOk.yml
new file mode 100644
index 0000000000..867b7d3dc1
--- /dev/null
+++ b/test/spec/server-discovery-and-monitoring/errors/pre-42-NotPrimaryNoSecondaryOk.yml
@@ -0,0 +1,47 @@
+# Autogenerated tests for SDAM error handling, see generate-error-tests.py
+description: Pre-4.2 NotPrimaryNoSecondaryOk error
+uri: mongodb://a/?replicaSet=rs
+phases:
+- description: Primary A is discovered
+  responses:
+  - - a:27017
+    - ok: 1
+      helloOk: true
+      isWritablePrimary: true
+      hosts:
+      - a:27017
+      setName: rs
+      minWireVersion: 0
+      maxWireVersion: 7
+  outcome: &outcome
+    servers:
+      a:27017:
+        type: RSPrimary
+        setName: rs
+        topologyVersion: null
+        pool:
+          generation: 0
+    topologyType: ReplicaSetWithPrimary
+    logicalSessionTimeoutMinutes: null
+    setName: rs
+
+- description: Pre-4.2 NotPrimaryNoSecondaryOk error marks server Unknown and clears the pool
+  applicationErrors:
+  - address: a:27017
+    when: afterHandshakeCompletes
+    maxWireVersion: 7
+    type: command
+    response:
+      ok: 0
+      errmsg: NotPrimaryNoSecondaryOk
+      code: 13435
+  outcome:
+    servers:
+      a:27017:
+        type: Unknown
+        topologyVersion: null
+        pool:
+          generation: 1
+    topologyType: ReplicaSetNoPrimary
+    logicalSessionTimeoutMinutes: null
+    setName: rs
diff --git a/test/spec/server-discovery-and-monitoring/errors/pre-42-NotMasterOrSecondary.json b/test/spec/server-discovery-and-monitoring/errors/pre-42-NotPrimaryOrSecondary.json
similarity index 83%
rename from test/spec/server-discovery-and-monitoring/errors/pre-42-NotMasterOrSecondary.json
rename to test/spec/server-discovery-and-monitoring/errors/pre-42-NotPrimaryOrSecondary.json
index f515898281..3fefb21663 100644
--- a/test/spec/server-discovery-and-monitoring/errors/pre-42-NotMasterOrSecondary.json
+++ b/test/spec/server-discovery-and-monitoring/errors/pre-42-NotPrimaryOrSecondary.json
@@ -1,5 +1,5 @@
 {
-  "description": "Pre-4.2 NotMasterOrSecondary error",
+  "description": "Pre-4.2 NotPrimaryOrSecondary error",
   "uri": "mongodb://a/?replicaSet=rs",
   "phases": [
     {
@@ -9,7 +9,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
@@ -36,7 +37,7 @@
       }
     },
     {
-      "description": "Pre-4.2 NotMasterOrSecondary error marks server Unknown and clears the pool",
+      "description": "Pre-4.2 NotPrimaryOrSecondary error marks server Unknown and clears the pool",
       "applicationErrors": [
         {
           "address": "a:27017",
@@ -45,7 +46,7 @@
           "type": "command",
           "response": {
             "ok": 0,
-            "errmsg": "NotMasterOrSecondary",
+            "errmsg": "NotPrimaryOrSecondary",
             "code": 13436
           }
         }
diff --git a/test/spec/server-discovery-and-monitoring/errors/pre-42-NotMasterOrSecondary.yml b/test/spec/server-discovery-and-monitoring/errors/pre-42-NotPrimaryOrSecondary.yml
similarity index 80%
rename from test/spec/server-discovery-and-monitoring/errors/pre-42-NotMasterOrSecondary.yml
rename to test/spec/server-discovery-and-monitoring/errors/pre-42-NotPrimaryOrSecondary.yml
index c29ede7811..705e2339c0 100644
--- a/test/spec/server-discovery-and-monitoring/errors/pre-42-NotMasterOrSecondary.yml
+++ b/test/spec/server-discovery-and-monitoring/errors/pre-42-NotPrimaryOrSecondary.yml
@@ -1,12 +1,13 @@
 # Autogenerated tests for SDAM error handling, see generate-error-tests.py
-description: Pre-4.2 NotMasterOrSecondary error
+description: Pre-4.2 NotPrimaryOrSecondary error
 uri: mongodb://a/?replicaSet=rs
 phases:
 - description: Primary A is discovered
   responses:
   - - a:27017
     - ok: 1
-      ismaster: true
+      helloOk: true
+      isWritablePrimary: true
       hosts:
       - a:27017
       setName: rs
@@ -24,7 +25,7 @@ phases:
     logicalSessionTimeoutMinutes: null
     setName: rs
 
-- description: Pre-4.2 NotMasterOrSecondary error marks server Unknown and clears the pool
+- description: Pre-4.2 NotPrimaryOrSecondary error marks server Unknown and clears the pool
   applicationErrors:
   - address: a:27017
     when: afterHandshakeCompletes
@@ -32,7 +33,7 @@ phases:
     type: command
     response:
       ok: 0
-      errmsg: NotMasterOrSecondary
+      errmsg: NotPrimaryOrSecondary
       code: 13436
   outcome:
     servers:
diff --git a/test/spec/server-discovery-and-monitoring/errors/pre-42-NotMasterNoSlaveOk.json b/test/spec/server-discovery-and-monitoring/errors/pre-42-NotWritablePrimary.json
similarity index 84%
rename from test/spec/server-discovery-and-monitoring/errors/pre-42-NotMasterNoSlaveOk.json
rename to test/spec/server-discovery-and-monitoring/errors/pre-42-NotWritablePrimary.json
index 1eb72bc033..d010da0a5b 100644
--- a/test/spec/server-discovery-and-monitoring/errors/pre-42-NotMasterNoSlaveOk.json
+++ b/test/spec/server-discovery-and-monitoring/errors/pre-42-NotWritablePrimary.json
@@ -1,5 +1,5 @@
 {
-  "description": "Pre-4.2 NotMasterNoSlaveOk error",
+  "description": "Pre-4.2 NotWritablePrimary error",
   "uri": "mongodb://a/?replicaSet=rs",
   "phases": [
     {
@@ -9,7 +9,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
@@ -36,7 +37,7 @@
       }
     },
     {
-      "description": "Pre-4.2 NotMasterNoSlaveOk error marks server Unknown and clears the pool",
+      "description": "Pre-4.2 NotWritablePrimary error marks server Unknown and clears the pool",
       "applicationErrors": [
         {
           "address": "a:27017",
@@ -45,8 +46,8 @@
           "type": "command",
           "response": {
             "ok": 0,
-            "errmsg": "NotMasterNoSlaveOk",
-            "code": 13435
+            "errmsg": "NotWritablePrimary",
+            "code": 10107
           }
         }
       ],
diff --git a/test/spec/server-discovery-and-monitoring/errors/pre-42-NotMasterNoSlaveOk.yml b/test/spec/server-discovery-and-monitoring/errors/pre-42-NotWritablePrimary.yml
similarity index 81%
rename from test/spec/server-discovery-and-monitoring/errors/pre-42-NotMasterNoSlaveOk.yml
rename to test/spec/server-discovery-and-monitoring/errors/pre-42-NotWritablePrimary.yml
index a07dd16489..29669ff336 100644
--- a/test/spec/server-discovery-and-monitoring/errors/pre-42-NotMasterNoSlaveOk.yml
+++ b/test/spec/server-discovery-and-monitoring/errors/pre-42-NotWritablePrimary.yml
@@ -1,12 +1,13 @@
 # Autogenerated tests for SDAM error handling, see generate-error-tests.py
-description: Pre-4.2 NotMasterNoSlaveOk error
+description: Pre-4.2 NotWritablePrimary error
 uri: mongodb://a/?replicaSet=rs
 phases:
 - description: Primary A is discovered
   responses:
   - - a:27017
     - ok: 1
-      ismaster: true
+      helloOk: true
+      isWritablePrimary: true
       hosts:
       - a:27017
       setName: rs
@@ -24,7 +25,7 @@ phases:
     logicalSessionTimeoutMinutes: null
     setName: rs
 
-- description: Pre-4.2 NotMasterNoSlaveOk error marks server Unknown and clears the pool
+- description: Pre-4.2 NotWritablePrimary error marks server Unknown and clears the pool
   applicationErrors:
   - address: a:27017
     when: afterHandshakeCompletes
@@ -32,8 +33,8 @@ phases:
     type: command
     response:
       ok: 0
-      errmsg: NotMasterNoSlaveOk
-      code: 13435
+      errmsg: NotWritablePrimary
+      code: 10107
   outcome:
     servers:
       a:27017:
diff --git a/test/spec/server-discovery-and-monitoring/errors/pre-42-PrimarySteppedDown.json b/test/spec/server-discovery-and-monitoring/errors/pre-42-PrimarySteppedDown.json
index e4c3228afc..02956d201d 100644
--- a/test/spec/server-discovery-and-monitoring/errors/pre-42-PrimarySteppedDown.json
+++ b/test/spec/server-discovery-and-monitoring/errors/pre-42-PrimarySteppedDown.json
@@ -9,7 +9,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
diff --git a/test/spec/server-discovery-and-monitoring/errors/pre-42-PrimarySteppedDown.yml b/test/spec/server-discovery-and-monitoring/errors/pre-42-PrimarySteppedDown.yml
index 7a9d1580ca..9176ee25c3 100644
--- a/test/spec/server-discovery-and-monitoring/errors/pre-42-PrimarySteppedDown.yml
+++ b/test/spec/server-discovery-and-monitoring/errors/pre-42-PrimarySteppedDown.yml
@@ -6,7 +6,8 @@ phases:
   responses:
   - - a:27017
     - ok: 1
-      ismaster: true
+      helloOk: true
+      isWritablePrimary: true
       hosts:
       - a:27017
       setName: rs
diff --git a/test/spec/server-discovery-and-monitoring/errors/pre-42-ShutdownInProgress.json b/test/spec/server-discovery-and-monitoring/errors/pre-42-ShutdownInProgress.json
index 00dc7c1b5b..fc3a5aa6fe 100644
--- a/test/spec/server-discovery-and-monitoring/errors/pre-42-ShutdownInProgress.json
+++ b/test/spec/server-discovery-and-monitoring/errors/pre-42-ShutdownInProgress.json
@@ -9,7 +9,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
diff --git a/test/spec/server-discovery-and-monitoring/errors/pre-42-ShutdownInProgress.yml b/test/spec/server-discovery-and-monitoring/errors/pre-42-ShutdownInProgress.yml
index 3110fbe5b8..5c64050e59 100644
--- a/test/spec/server-discovery-and-monitoring/errors/pre-42-ShutdownInProgress.yml
+++ b/test/spec/server-discovery-and-monitoring/errors/pre-42-ShutdownInProgress.yml
@@ -6,7 +6,8 @@ phases:
   responses:
   - - a:27017
     - ok: 1
-      ismaster: true
+      helloOk: true
+      isWritablePrimary: true
       hosts:
       - a:27017
       setName: rs
diff --git a/test/spec/server-discovery-and-monitoring/errors/pre-42.yml.template b/test/spec/server-discovery-and-monitoring/errors/pre-42.yml.template
index 5f91c4482d..7449f68c16 100644
--- a/test/spec/server-discovery-and-monitoring/errors/pre-42.yml.template
+++ b/test/spec/server-discovery-and-monitoring/errors/pre-42.yml.template
@@ -6,7 +6,8 @@ phases:
   responses:
   - - a:27017
     - ok: 1
-      ismaster: true
+      helloOk: true
+      isWritablePrimary: true
       hosts:
       - a:27017
       setName: rs
diff --git a/test/spec/server-discovery-and-monitoring/errors/prefer-error-code.json b/test/spec/server-discovery-and-monitoring/errors/prefer-error-code.json
new file mode 100644
index 0000000000..21d123f429
--- /dev/null
+++ b/test/spec/server-discovery-and-monitoring/errors/prefer-error-code.json
@@ -0,0 +1,131 @@
+{
+  "description": "Do not check errmsg when code exists",
+  "uri": "mongodb://a/?replicaSet=rs",
+  "phases": [
+    {
+      "description": "Primary A is discovered",
+      "responses": [
+        [
+          "a:27017",
+          {
+            "ok": 1,
+            "helloOk": true,
+            "isWritablePrimary": true,
+            "hosts": [
+              "a:27017"
+            ],
+            "setName": "rs",
+            "minWireVersion": 0,
+            "maxWireVersion": 9,
+            "topologyVersion": {
+              "processId": {
+                "$oid": "000000000000000000000001"
+              },
+              "counter": {
+                "$numberLong": "1"
+              }
+            }
+          }
+        ]
+      ],
+      "outcome": {
+        "servers": {
+          "a:27017": {
+            "type": "RSPrimary",
+            "setName": "rs",
+            "topologyVersion": {
+              "processId": {
+                "$oid": "000000000000000000000001"
+              },
+              "counter": {
+                "$numberLong": "1"
+              }
+            },
+            "pool": {
+              "generation": 0
+            }
+          }
+        },
+        "topologyType": "ReplicaSetWithPrimary",
+        "logicalSessionTimeoutMinutes": null,
+        "setName": "rs"
+      }
+    },
+    {
+      "description": "errmsg \"not writable primary\" gets ignored when error code exists",
+      "applicationErrors": [
+        {
+          "address": "a:27017",
+          "when": "afterHandshakeCompletes",
+          "maxWireVersion": 9,
+          "type": "command",
+          "response": {
+            "ok": 0,
+            "errmsg": "not writable primary",
+            "code": 1
+          }
+        }
+      ],
+      "outcome": {
+        "servers": {
+          "a:27017": {
+            "type": "RSPrimary",
+            "setName": "rs",
+            "topologyVersion": {
+              "processId": {
+                "$oid": "000000000000000000000001"
+              },
+              "counter": {
+                "$numberLong": "1"
+              }
+            },
+            "pool": {
+              "generation": 0
+            }
+          }
+        },
+        "topologyType": "ReplicaSetWithPrimary",
+        "logicalSessionTimeoutMinutes": null,
+        "setName": "rs"
+      }
+    },
+    {
+      "description": "errmsg \"node is recovering\" gets ignored when error code exists",
+      "applicationErrors": [
+        {
+          "address": "a:27017",
+          "when": "afterHandshakeCompletes",
+          "maxWireVersion": 9,
+          "type": "command",
+          "response": {
+            "ok": 0,
+            "errmsg": "node is recovering",
+            "code": 1
+          }
+        }
+      ],
+      "outcome": {
+        "servers": {
+          "a:27017": {
+            "type": "RSPrimary",
+            "setName": "rs",
+            "topologyVersion": {
+              "processId": {
+                "$oid": "000000000000000000000001"
+              },
+              "counter": {
+                "$numberLong": "1"
+              }
+            },
+            "pool": {
+              "generation": 0
+            }
+          }
+        },
+        "topologyType": "ReplicaSetWithPrimary",
+        "logicalSessionTimeoutMinutes": null,
+        "setName": "rs"
+      }
+    }
+  ]
+}
diff --git a/test/spec/server-discovery-and-monitoring/errors/prefer-error-code.yml b/test/spec/server-discovery-and-monitoring/errors/prefer-error-code.yml
new file mode 100644
index 0000000000..dcbe0da41a
--- /dev/null
+++ b/test/spec/server-discovery-and-monitoring/errors/prefer-error-code.yml
@@ -0,0 +1,54 @@
+description: Do not check errmsg when code exists
+uri: mongodb://a/?replicaSet=rs
+phases:
+- description: Primary A is discovered
+  responses:
+  - - a:27017
+    - ok: 1
+      helloOk: true
+      isWritablePrimary: true
+      hosts:
+      - a:27017
+      setName: rs
+      minWireVersion: 0
+      maxWireVersion: 9
+      topologyVersion: &topologyVersion_1_1
+        processId:
+          "$oid": '000000000000000000000001'
+        counter:
+          "$numberLong": '1'
+  outcome: &outcome
+    servers:
+      a:27017:
+        type: RSPrimary
+        setName: rs
+        topologyVersion: *topologyVersion_1_1
+        pool:
+          generation: 0
+    topologyType: ReplicaSetWithPrimary
+    logicalSessionTimeoutMinutes: null
+    setName: rs
+
+- description: errmsg "not writable primary" gets ignored when error code exists
+  applicationErrors:
+  - address: a:27017
+    when: afterHandshakeCompletes
+    maxWireVersion: 9
+    type: command
+    response:
+      ok: 0
+      errmsg: "not writable primary"
+      code: 1  # Not a "not writable primary" error code.
+  outcome: *outcome
+
+- description: errmsg "node is recovering" gets ignored when error code exists
+  applicationErrors:
+  - address: a:27017
+    when: afterHandshakeCompletes
+    maxWireVersion: 9
+    type: command
+    response:
+      ok: 0
+      errmsg: "node is recovering"
+      code: 1  # Not a "node is recovering" error code.
+  outcome: *outcome
diff --git a/test/spec/server-discovery-and-monitoring/errors/stale-generation-InterruptedAtShutdown.json b/test/spec/server-discovery-and-monitoring/errors/stale-generation-InterruptedAtShutdown.json
index f675f2651e..2f7c7fd13b 100644
--- a/test/spec/server-discovery-and-monitoring/errors/stale-generation-InterruptedAtShutdown.json
+++ b/test/spec/server-discovery-and-monitoring/errors/stale-generation-InterruptedAtShutdown.json
@@ -9,7 +9,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
@@ -82,7 +83,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
diff --git a/test/spec/server-discovery-and-monitoring/errors/stale-generation-InterruptedAtShutdown.yml b/test/spec/server-discovery-and-monitoring/errors/stale-generation-InterruptedAtShutdown.yml
index a32f6de2d9..37dddcead5 100644
--- a/test/spec/server-discovery-and-monitoring/errors/stale-generation-InterruptedAtShutdown.yml
+++ b/test/spec/server-discovery-and-monitoring/errors/stale-generation-InterruptedAtShutdown.yml
@@ -6,7 +6,8 @@ phases:
   responses:
   - - a:27017
     - ok: 1
-      ismaster: true
+      helloOk: true
+      isWritablePrimary: true
       hosts:
       - a:27017
       setName: rs
@@ -51,7 +52,8 @@ phases:
   responses:
   - - a:27017
     - ok: 1
-      ismaster: true
+      helloOk: true
+      isWritablePrimary: true
       hosts:
       - a:27017
       setName: rs
diff --git a/test/spec/server-discovery-and-monitoring/errors/stale-generation-InterruptedDueToReplStateChange.json b/test/spec/server-discovery-and-monitoring/errors/stale-generation-InterruptedDueToReplStateChange.json
index a4ae13ee78..b0b51ef676 100644
--- a/test/spec/server-discovery-and-monitoring/errors/stale-generation-InterruptedDueToReplStateChange.json
+++ b/test/spec/server-discovery-and-monitoring/errors/stale-generation-InterruptedDueToReplStateChange.json
@@ -9,7 +9,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
@@ -82,7 +83,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
diff --git a/test/spec/server-discovery-and-monitoring/errors/stale-generation-InterruptedDueToReplStateChange.yml b/test/spec/server-discovery-and-monitoring/errors/stale-generation-InterruptedDueToReplStateChange.yml
index b493952943..f83532e2c5 100644
--- a/test/spec/server-discovery-and-monitoring/errors/stale-generation-InterruptedDueToReplStateChange.yml
+++ b/test/spec/server-discovery-and-monitoring/errors/stale-generation-InterruptedDueToReplStateChange.yml
@@ -6,7 +6,8 @@ phases:
   responses:
   - - a:27017
     - ok: 1
-      ismaster: true
+      helloOk: true
+      isWritablePrimary: true
       hosts:
       - a:27017
       setName: rs
@@ -51,7 +52,8 @@ phases:
   responses:
   - - a:27017
     - ok: 1
-      ismaster: true
+      helloOk: true
+      isWritablePrimary: true
       hosts:
       - a:27017
       setName: rs
diff --git a/test/spec/server-discovery-and-monitoring/errors/stale-generation-NotMasterNoSlaveOk.json b/test/spec/server-discovery-and-monitoring/errors/stale-generation-NotPrimaryNoSecondaryOk.json
similarity index 92%
rename from test/spec/server-discovery-and-monitoring/errors/stale-generation-NotMasterNoSlaveOk.json
rename to test/spec/server-discovery-and-monitoring/errors/stale-generation-NotPrimaryNoSecondaryOk.json
index d58349b622..b68e23b7a7 100644
--- a/test/spec/server-discovery-and-monitoring/errors/stale-generation-NotMasterNoSlaveOk.json
+++ b/test/spec/server-discovery-and-monitoring/errors/stale-generation-NotPrimaryNoSecondaryOk.json
@@ -1,5 +1,5 @@
 {
-  "description": "Stale generation NotMasterNoSlaveOk error",
+  "description": "Stale generation NotPrimaryNoSecondaryOk error",
   "uri": "mongodb://a/?replicaSet=rs",
   "phases": [
     {
@@ -9,7 +9,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
@@ -82,7 +83,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
@@ -124,7 +126,7 @@
       }
     },
     {
-      "description": "Ignore stale NotMasterNoSlaveOk error (stale generation)",
+      "description": "Ignore stale NotPrimaryNoSecondaryOk error (stale generation)",
       "applicationErrors": [
         {
           "address": "a:27017",
@@ -134,7 +136,7 @@
           "type": "command",
           "response": {
             "ok": 0,
-            "errmsg": "NotMasterNoSlaveOk",
+            "errmsg": "NotPrimaryNoSecondaryOk",
             "code": 13435,
             "topologyVersion": {
               "processId": {
diff --git a/test/spec/server-discovery-and-monitoring/errors/stale-generation-NotMasterNoSlaveOk.yml b/test/spec/server-discovery-and-monitoring/errors/stale-generation-NotPrimaryNoSecondaryOk.yml
similarity index 87%
rename from test/spec/server-discovery-and-monitoring/errors/stale-generation-NotMasterNoSlaveOk.yml
rename to test/spec/server-discovery-and-monitoring/errors/stale-generation-NotPrimaryNoSecondaryOk.yml
index a39de00e04..43c7f57742 100644
--- a/test/spec/server-discovery-and-monitoring/errors/stale-generation-NotMasterNoSlaveOk.yml
+++ b/test/spec/server-discovery-and-monitoring/errors/stale-generation-NotPrimaryNoSecondaryOk.yml
@@ -1,12 +1,13 @@
 # Autogenerated tests for SDAM error handling, see generate-error-tests.py
-description: Stale generation NotMasterNoSlaveOk error
+description: Stale generation NotPrimaryNoSecondaryOk error
 uri: mongodb://a/?replicaSet=rs
 phases:
 - description: Primary A is discovered
   responses:
   - - a:27017
     - ok: 1
-      ismaster: true
+      helloOk: true
+      isWritablePrimary: true
       hosts:
       - a:27017
       setName: rs
@@ -51,7 +52,8 @@ phases:
   responses:
   - - a:27017
     - ok: 1
-      ismaster: true
+      helloOk: true
+      isWritablePrimary: true
       hosts:
       - a:27017
       setName: rs
@@ -70,7 +72,7 @@ phases:
     logicalSessionTimeoutMinutes: null
     setName: rs
 
-- description: Ignore stale NotMasterNoSlaveOk error (stale generation)
+- description: Ignore stale NotPrimaryNoSecondaryOk error (stale generation)
   applicationErrors:
   - address: a:27017
     generation: 0
@@ -79,7 +81,7 @@ phases:
     type: command
     response:
       ok: 0
-      errmsg: NotMasterNoSlaveOk
+      errmsg: NotPrimaryNoSecondaryOk
       code: 13435
       topologyVersion:
         processId:
diff --git a/test/spec/server-discovery-and-monitoring/errors/stale-generation-afterHandshakeCompletes-NotMasterOrSecondary.json b/test/spec/server-discovery-and-monitoring/errors/stale-generation-NotPrimaryOrSecondary.json
similarity index 92%
rename from test/spec/server-discovery-and-monitoring/errors/stale-generation-afterHandshakeCompletes-NotMasterOrSecondary.json
rename to test/spec/server-discovery-and-monitoring/errors/stale-generation-NotPrimaryOrSecondary.json
index 851bea0928..d9b3562654 100644
--- a/test/spec/server-discovery-and-monitoring/errors/stale-generation-afterHandshakeCompletes-NotMasterOrSecondary.json
+++ b/test/spec/server-discovery-and-monitoring/errors/stale-generation-NotPrimaryOrSecondary.json
@@ -1,5 +1,5 @@
 {
-  "description": "Stale generation NotMasterOrSecondary error afterHandshakeCompletes",
+  "description": "Stale generation NotPrimaryOrSecondary error",
   "uri": "mongodb://a/?replicaSet=rs",
   "phases": [
     {
@@ -9,7 +9,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
@@ -82,7 +83,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
@@ -124,7 +126,7 @@
       }
     },
     {
-      "description": "Ignore stale NotMasterOrSecondary error (stale generation)",
+      "description": "Ignore stale NotPrimaryOrSecondary error (stale generation)",
       "applicationErrors": [
         {
           "address": "a:27017",
@@ -134,7 +136,7 @@
           "type": "command",
           "response": {
             "ok": 0,
-            "errmsg": "NotMasterOrSecondary",
+            "errmsg": "NotPrimaryOrSecondary",
             "code": 13436,
             "topologyVersion": {
               "processId": {
diff --git a/test/spec/server-discovery-and-monitoring/errors/stale-generation-NotMasterOrSecondary.yml b/test/spec/server-discovery-and-monitoring/errors/stale-generation-NotPrimaryOrSecondary.yml
similarity index 88%
rename from test/spec/server-discovery-and-monitoring/errors/stale-generation-NotMasterOrSecondary.yml
rename to test/spec/server-discovery-and-monitoring/errors/stale-generation-NotPrimaryOrSecondary.yml
index a6cdd3f21a..1dc6a2319e 100644
--- a/test/spec/server-discovery-and-monitoring/errors/stale-generation-NotMasterOrSecondary.yml
+++ b/test/spec/server-discovery-and-monitoring/errors/stale-generation-NotPrimaryOrSecondary.yml
@@ -1,12 +1,13 @@
 # Autogenerated tests for SDAM error handling, see generate-error-tests.py
-description: Stale generation NotMasterOrSecondary error
+description: Stale generation NotPrimaryOrSecondary error
 uri: mongodb://a/?replicaSet=rs
 phases:
 - description: Primary A is discovered
   responses:
   - - a:27017
     - ok: 1
-      ismaster: true
+      helloOk: true
+      isWritablePrimary: true
       hosts:
       - a:27017
       setName: rs
@@ -51,7 +52,8 @@ phases:
   responses:
   - - a:27017
     - ok: 1
-      ismaster: true
+      helloOk: true
+      isWritablePrimary: true
       hosts:
       - a:27017
       setName: rs
@@ -70,7 +72,7 @@ phases:
     logicalSessionTimeoutMinutes: null
     setName: rs
 
-- description: Ignore stale NotMasterOrSecondary error (stale generation)
+- description: Ignore stale NotPrimaryOrSecondary error (stale generation)
   applicationErrors:
   - address: a:27017
     generation: 0
@@ -79,7 +81,7 @@ phases:
     type: command
     response:
       ok: 0
-      errmsg: NotMasterOrSecondary
+      errmsg: NotPrimaryOrSecondary
       code: 13436
       topologyVersion:
         processId:
diff --git a/test/spec/server-discovery-and-monitoring/errors/stale-generation-afterHandshakeCompletes-NotMaster.json b/test/spec/server-discovery-and-monitoring/errors/stale-generation-NotWritablePrimary.json
similarity index 92%
rename from test/spec/server-discovery-and-monitoring/errors/stale-generation-afterHandshakeCompletes-NotMaster.json
rename to test/spec/server-discovery-and-monitoring/errors/stale-generation-NotWritablePrimary.json
index dbdce1583a..90889356dd 100644
--- a/test/spec/server-discovery-and-monitoring/errors/stale-generation-afterHandshakeCompletes-NotMaster.json
+++ b/test/spec/server-discovery-and-monitoring/errors/stale-generation-NotWritablePrimary.json
@@ -1,5 +1,5 @@
 {
-  "description": "Stale generation NotMaster error afterHandshakeCompletes",
+  "description": "Stale generation NotWritablePrimary error",
   "uri": "mongodb://a/?replicaSet=rs",
   "phases": [
     {
@@ -9,7 +9,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
@@ -82,7 +83,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
@@ -124,7 +126,7 @@
       }
     },
     {
-      "description": "Ignore stale NotMaster error (stale generation)",
+      "description": "Ignore stale NotWritablePrimary error (stale generation)",
       "applicationErrors": [
         {
           "address": "a:27017",
@@ -134,7 +136,7 @@
           "type": "command",
           "response": {
             "ok": 0,
-            "errmsg": "NotMaster",
+            "errmsg": "NotWritablePrimary",
             "code": 10107,
             "topologyVersion": {
               "processId": {
diff --git a/test/spec/server-discovery-and-monitoring/errors/stale-generation-NotMaster.yml b/test/spec/server-discovery-and-monitoring/errors/stale-generation-NotWritablePrimary.yml
similarity index 88%
rename from test/spec/server-discovery-and-monitoring/errors/stale-generation-NotMaster.yml
rename to test/spec/server-discovery-and-monitoring/errors/stale-generation-NotWritablePrimary.yml
index 66493e2f58..488eaab4a5 100644
--- a/test/spec/server-discovery-and-monitoring/errors/stale-generation-NotMaster.yml
+++ b/test/spec/server-discovery-and-monitoring/errors/stale-generation-NotWritablePrimary.yml
@@ -1,12 +1,13 @@
 # Autogenerated tests for SDAM error handling, see generate-error-tests.py
-description: Stale generation NotMaster error
+description: Stale generation NotWritablePrimary error
 uri: mongodb://a/?replicaSet=rs
 phases:
 - description: Primary A is discovered
   responses:
   - - a:27017
     - ok: 1
-      ismaster: true
+      helloOk: true
+      isWritablePrimary: true
       hosts:
       - a:27017
       setName: rs
@@ -51,7 +52,8 @@ phases:
   responses:
   - - a:27017
     - ok: 1
-      ismaster: true
+      helloOk: true
+      isWritablePrimary: true
       hosts:
       - a:27017
       setName: rs
@@ -70,7 +72,7 @@ phases:
     logicalSessionTimeoutMinutes: null
     setName: rs
 
-- description: Ignore stale NotMaster error (stale generation)
+- description: Ignore stale NotWritablePrimary error (stale generation)
   applicationErrors:
   - address: a:27017
     generation: 0
@@ -79,7 +81,7 @@ phases:
     type: command
     response:
       ok: 0
-      errmsg: NotMaster
+      errmsg: NotWritablePrimary
       code: 10107
       topologyVersion:
         processId:
diff --git a/test/spec/server-discovery-and-monitoring/errors/stale-generation-PrimarySteppedDown.json b/test/spec/server-discovery-and-monitoring/errors/stale-generation-PrimarySteppedDown.json
index 2e80ba4949..0a707a1c07 100644
--- a/test/spec/server-discovery-and-monitoring/errors/stale-generation-PrimarySteppedDown.json
+++ b/test/spec/server-discovery-and-monitoring/errors/stale-generation-PrimarySteppedDown.json
@@ -9,7 +9,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
@@ -82,7 +83,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
diff --git a/test/spec/server-discovery-and-monitoring/errors/stale-generation-PrimarySteppedDown.yml b/test/spec/server-discovery-and-monitoring/errors/stale-generation-PrimarySteppedDown.yml
index f41440af60..2b45081087 100644
--- a/test/spec/server-discovery-and-monitoring/errors/stale-generation-PrimarySteppedDown.yml
+++ b/test/spec/server-discovery-and-monitoring/errors/stale-generation-PrimarySteppedDown.yml
@@ -6,7 +6,8 @@ phases:
   responses:
   - - a:27017
     - ok: 1
-      ismaster: true
+      helloOk: true
+      isWritablePrimary: true
       hosts:
       - a:27017
       setName: rs
@@ -51,7 +52,8 @@ phases:
   responses:
   - - a:27017
     - ok: 1
-      ismaster: true
+      helloOk: true
+      isWritablePrimary: true
       hosts:
       - a:27017
       setName: rs
diff --git a/test/spec/server-discovery-and-monitoring/errors/stale-generation-ShutdownInProgress.json b/test/spec/server-discovery-and-monitoring/errors/stale-generation-ShutdownInProgress.json
index 9b5656d48b..5da3413d5b 100644
--- a/test/spec/server-discovery-and-monitoring/errors/stale-generation-ShutdownInProgress.json
+++ b/test/spec/server-discovery-and-monitoring/errors/stale-generation-ShutdownInProgress.json
@@ -9,7 +9,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
@@ -82,7 +83,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
diff --git a/test/spec/server-discovery-and-monitoring/errors/stale-generation-ShutdownInProgress.yml b/test/spec/server-discovery-and-monitoring/errors/stale-generation-ShutdownInProgress.yml
index 0d7f978243..b9bd8212d9 100644
--- a/test/spec/server-discovery-and-monitoring/errors/stale-generation-ShutdownInProgress.yml
+++ b/test/spec/server-discovery-and-monitoring/errors/stale-generation-ShutdownInProgress.yml
@@ -6,7 +6,8 @@ phases:
   responses:
   - - a:27017
     - ok: 1
-      ismaster: true
+      helloOk: true
+      isWritablePrimary: true
       hosts:
       - a:27017
       setName: rs
@@ -51,7 +52,8 @@ phases:
   responses:
   - - a:27017
     - ok: 1
-      ismaster: true
+      helloOk: true
+      isWritablePrimary: true
       hosts:
       - a:27017
       setName: rs
diff --git a/test/spec/server-discovery-and-monitoring/errors/stale-generation-afterHandshakeCompletes-InterruptedAtShutdown.json b/test/spec/server-discovery-and-monitoring/errors/stale-generation-afterHandshakeCompletes-InterruptedAtShutdown.json
index 9da8b60fbb..d29310fb61 100644
--- a/test/spec/server-discovery-and-monitoring/errors/stale-generation-afterHandshakeCompletes-InterruptedAtShutdown.json
+++ b/test/spec/server-discovery-and-monitoring/errors/stale-generation-afterHandshakeCompletes-InterruptedAtShutdown.json
@@ -9,7 +9,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
@@ -82,7 +83,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
diff --git a/test/spec/server-discovery-and-monitoring/errors/stale-generation-afterHandshakeCompletes-InterruptedAtShutdown.yml b/test/spec/server-discovery-and-monitoring/errors/stale-generation-afterHandshakeCompletes-InterruptedAtShutdown.yml
index 654cff5d29..48dd257af9 100644
--- a/test/spec/server-discovery-and-monitoring/errors/stale-generation-afterHandshakeCompletes-InterruptedAtShutdown.yml
+++ b/test/spec/server-discovery-and-monitoring/errors/stale-generation-afterHandshakeCompletes-InterruptedAtShutdown.yml
@@ -6,7 +6,8 @@ phases:
   responses:
   - - a:27017
     - ok: 1
-      ismaster: true
+      helloOk: true
+      isWritablePrimary: true
       hosts:
       - a:27017
       setName: rs
@@ -51,7 +52,8 @@ phases:
   responses:
   - - a:27017
     - ok: 1
-      ismaster: true
+      helloOk: true
+      isWritablePrimary: true
       hosts:
       - a:27017
       setName: rs
diff --git a/test/spec/server-discovery-and-monitoring/errors/stale-generation-afterHandshakeCompletes-InterruptedDueToReplStateChange.json b/test/spec/server-discovery-and-monitoring/errors/stale-generation-afterHandshakeCompletes-InterruptedDueToReplStateChange.json
index f0a7df6170..376bb93770 100644
--- a/test/spec/server-discovery-and-monitoring/errors/stale-generation-afterHandshakeCompletes-InterruptedDueToReplStateChange.json
+++ b/test/spec/server-discovery-and-monitoring/errors/stale-generation-afterHandshakeCompletes-InterruptedDueToReplStateChange.json
@@ -9,7 +9,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
@@ -82,7 +83,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
diff --git a/test/spec/server-discovery-and-monitoring/errors/stale-generation-afterHandshakeCompletes-InterruptedDueToReplStateChange.yml b/test/spec/server-discovery-and-monitoring/errors/stale-generation-afterHandshakeCompletes-InterruptedDueToReplStateChange.yml
index f6d5e374a4..5e7ddeaa36 100644
--- a/test/spec/server-discovery-and-monitoring/errors/stale-generation-afterHandshakeCompletes-InterruptedDueToReplStateChange.yml
+++ b/test/spec/server-discovery-and-monitoring/errors/stale-generation-afterHandshakeCompletes-InterruptedDueToReplStateChange.yml
@@ -6,7 +6,8 @@ phases:
   responses:
   - - a:27017
     - ok: 1
-      ismaster: true
+      helloOk: true
+      isWritablePrimary: true
       hosts:
       - a:27017
       setName: rs
@@ -51,7 +52,8 @@ phases:
   responses:
   - - a:27017
     - ok: 1
-      ismaster: true
+      helloOk: true
+      isWritablePrimary: true
       hosts:
       - a:27017
       setName: rs
diff --git a/test/spec/server-discovery-and-monitoring/errors/stale-generation-NotMaster.json b/test/spec/server-discovery-and-monitoring/errors/stale-generation-afterHandshakeCompletes-LegacyNotPrimary.json
similarity index 91%
rename from test/spec/server-discovery-and-monitoring/errors/stale-generation-NotMaster.json
rename to test/spec/server-discovery-and-monitoring/errors/stale-generation-afterHandshakeCompletes-LegacyNotPrimary.json
index cfe779ee6f..990fc45e4e 100644
--- a/test/spec/server-discovery-and-monitoring/errors/stale-generation-NotMaster.json
+++ b/test/spec/server-discovery-and-monitoring/errors/stale-generation-afterHandshakeCompletes-LegacyNotPrimary.json
@@ -1,5 +1,5 @@
 {
-  "description": "Stale generation NotMaster error",
+  "description": "Stale generation LegacyNotPrimary error afterHandshakeCompletes",
   "uri": "mongodb://a/?replicaSet=rs",
   "phases": [
     {
@@ -9,7 +9,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
@@ -82,7 +83,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
@@ -124,7 +126,7 @@
       }
     },
     {
-      "description": "Ignore stale NotMaster error (stale generation)",
+      "description": "Ignore stale LegacyNotPrimary error (stale generation)",
       "applicationErrors": [
         {
           "address": "a:27017",
@@ -134,8 +136,8 @@
           "type": "command",
           "response": {
             "ok": 0,
-            "errmsg": "NotMaster",
-            "code": 10107,
+            "errmsg": "LegacyNotPrimary",
+            "code": 10058,
             "topologyVersion": {
               "processId": {
                 "$oid": "000000000000000000000001"
diff --git a/test/spec/server-discovery-and-monitoring/errors/stale-generation-afterHandshakeCompletes-NotMaster.yml b/test/spec/server-discovery-and-monitoring/errors/stale-generation-afterHandshakeCompletes-LegacyNotPrimary.yml
similarity index 86%
rename from test/spec/server-discovery-and-monitoring/errors/stale-generation-afterHandshakeCompletes-NotMaster.yml
rename to test/spec/server-discovery-and-monitoring/errors/stale-generation-afterHandshakeCompletes-LegacyNotPrimary.yml
index 352d016c59..8701f366ab 100644
--- a/test/spec/server-discovery-and-monitoring/errors/stale-generation-afterHandshakeCompletes-NotMaster.yml
+++ b/test/spec/server-discovery-and-monitoring/errors/stale-generation-afterHandshakeCompletes-LegacyNotPrimary.yml
@@ -1,12 +1,13 @@
 # Autogenerated tests for SDAM error handling, see generate-error-tests.py
-description: Stale generation NotMaster error afterHandshakeCompletes
+description: Stale generation LegacyNotPrimary error afterHandshakeCompletes
 uri: mongodb://a/?replicaSet=rs
 phases:
 - description: Primary A is discovered
   responses:
   - - a:27017
     - ok: 1
-      ismaster: true
+      helloOk: true
+      isWritablePrimary: true
       hosts:
       - a:27017
       setName: rs
@@ -51,7 +52,8 @@ phases:
   responses:
   - - a:27017
     - ok: 1
-      ismaster: true
+      helloOk: true
+      isWritablePrimary: true
       hosts:
       - a:27017
       setName: rs
@@ -70,7 +72,7 @@ phases:
     logicalSessionTimeoutMinutes: null
     setName: rs
 
-- description: Ignore stale NotMaster error (stale generation)
+- description: Ignore stale LegacyNotPrimary error (stale generation)
   applicationErrors:
   - address: a:27017
     generation: 0
@@ -79,8 +81,8 @@ phases:
     type: command
     response:
       ok: 0
-      errmsg: NotMaster
-      code: 10107
+      errmsg: LegacyNotPrimary
+      code: 10058
       topologyVersion:
         processId:
           "$oid": '000000000000000000000001'
diff --git a/test/spec/server-discovery-and-monitoring/errors/stale-generation-afterHandshakeCompletes-NotPrimaryNoSecondaryOk.json b/test/spec/server-discovery-and-monitoring/errors/stale-generation-afterHandshakeCompletes-NotPrimaryNoSecondaryOk.json
new file mode 100644
index 0000000000..1744a82f77
--- /dev/null
+++ b/test/spec/server-discovery-and-monitoring/errors/stale-generation-afterHandshakeCompletes-NotPrimaryNoSecondaryOk.json
@@ -0,0 +1,176 @@
+{
+  "description": "Stale generation NotPrimaryNoSecondaryOk error afterHandshakeCompletes",
+  "uri": "mongodb://a/?replicaSet=rs",
+  "phases": [
+    {
+      "description": "Primary A is discovered",
+      "responses": [
+        [
+          "a:27017",
+          {
+            "ok": 1,
+            "helloOk": true,
+            "isWritablePrimary": true,
+            "hosts": [
+              "a:27017"
+            ],
+            "setName": "rs",
+            "minWireVersion": 0,
+            "maxWireVersion": 9,
+            "topologyVersion": {
+              "processId": {
+                "$oid": "000000000000000000000001"
+              },
+              "counter": {
+                "$numberLong": "1"
+              }
+            }
+          }
+        ]
+      ],
+      "outcome": {
+        "servers": {
+          "a:27017": {
+            "type": "RSPrimary",
+            "setName": "rs",
+            "topologyVersion": {
+              "processId": {
+                "$oid": "000000000000000000000001"
+              },
+              "counter": {
+                "$numberLong": "1"
+              }
+            },
+            "pool": {
+              "generation": 0
+            }
+          }
+        },
+        "topologyType": "ReplicaSetWithPrimary",
+        "logicalSessionTimeoutMinutes": null,
+        "setName": "rs"
+      }
+    },
+    {
+      "description": "Non-stale application network error",
+      "applicationErrors": [
+        {
+          "address": "a:27017",
+          "when": "afterHandshakeCompletes",
+          "maxWireVersion": 9,
+          "type": "network"
+        }
+      ],
+      "outcome": {
+        "servers": {
+          "a:27017": {
+            "type": "Unknown",
+            "topologyVersion": null,
+            "pool": {
+              "generation": 1
+            }
+          }
+        },
+        "topologyType": "ReplicaSetNoPrimary",
+        "logicalSessionTimeoutMinutes": null,
+        "setName": "rs"
+      }
+    },
+    {
+      "description": "Primary A is rediscovered",
+      "responses": [
+        [
+          "a:27017",
+          {
+            "ok": 1,
+            "helloOk": true,
+            "isWritablePrimary": true,
+            "hosts": [
+              "a:27017"
+            ],
+            "setName": "rs",
+            "minWireVersion": 0,
+            "maxWireVersion": 9,
+            "topologyVersion": {
+              "processId": {
+                "$oid": "000000000000000000000001"
+              },
+              "counter": {
+                "$numberLong": "1"
+              }
+            }
+          }
+        ]
+      ],
+      "outcome": {
+        "servers": {
+          "a:27017": {
+            "type": "RSPrimary",
+            "setName": "rs",
+            "topologyVersion": {
+              "processId": {
+                "$oid": "000000000000000000000001"
+              },
+              "counter": {
+                "$numberLong": "1"
+              }
+            },
+            "pool": {
+              "generation": 1
+            }
+          }
+        },
+        "topologyType": "ReplicaSetWithPrimary",
+        "logicalSessionTimeoutMinutes": null,
+        "setName": "rs"
+      }
+    },
+    {
+      "description": "Ignore stale NotPrimaryNoSecondaryOk error (stale generation)",
+      "applicationErrors": [
+        {
+          "address": "a:27017",
+          "generation": 0,
+          "when": "afterHandshakeCompletes",
+          "maxWireVersion": 9,
+          "type": "command",
+          "response": {
+            "ok": 0,
+            "errmsg": "NotPrimaryNoSecondaryOk",
+            "code": 13435,
+            "topologyVersion": {
+              "processId": {
+                "$oid": "000000000000000000000001"
+              },
+              "counter": {
+                "$numberLong": "2"
+              }
+            }
+          }
+        }
+      ],
+      "outcome": {
+        "servers": {
+          "a:27017": {
+            "type": "RSPrimary",
+            "setName": "rs",
+            "topologyVersion": {
+              "processId": {
+                "$oid": "000000000000000000000001"
+              },
+              "counter": {
+                "$numberLong": "1"
+              }
+            },
+            "pool": {
+              "generation": 1
+            }
+          }
+        },
+        "topologyType": "ReplicaSetWithPrimary",
+        "logicalSessionTimeoutMinutes": null,
+        "setName": "rs"
+      }
+    }
+  ]
+}
diff --git a/test/spec/server-discovery-and-monitoring/errors/stale-generation-afterHandshakeCompletes-NotPrimaryNoSecondaryOk.yml b/test/spec/server-discovery-and-monitoring/errors/stale-generation-afterHandshakeCompletes-NotPrimaryNoSecondaryOk.yml
new file mode 100644
index 0000000000..70673e9fe6
--- /dev/null
+++ b/test/spec/server-discovery-and-monitoring/errors/stale-generation-afterHandshakeCompletes-NotPrimaryNoSecondaryOk.yml
@@ -0,0 +1,91 @@
+# Autogenerated tests for SDAM error handling, see generate-error-tests.py
+description: Stale generation NotPrimaryNoSecondaryOk error afterHandshakeCompletes
+uri: mongodb://a/?replicaSet=rs
+phases:
+- description: Primary A is discovered
+  responses:
+  - - a:27017
+    - ok: 1
+      helloOk: true
+      isWritablePrimary: true
+      hosts:
+      - a:27017
+      setName: rs
+      minWireVersion: 0
+      maxWireVersion: 9
+      topologyVersion: &topologyVersion_1_1
+        processId:
+          "$oid": '000000000000000000000001'
+        counter:
+          "$numberLong": '1'
+  outcome:
+    servers:
+      a:27017:
+        type: RSPrimary
+        setName: rs
+        topologyVersion: *topologyVersion_1_1
+        pool:
+          generation: 0
+    topologyType: ReplicaSetWithPrimary
+    logicalSessionTimeoutMinutes: null
+    setName: rs
+
+# Process a network error which increments the pool generation.
+- description: Non-stale application network error
+  applicationErrors:
+  - address: a:27017
+    when: afterHandshakeCompletes
+    maxWireVersion: 9
+    type: network
+  outcome:
+    servers:
+      a:27017:
+        type: Unknown
+        topologyVersion: null
+        pool:
+          generation: 1
+    topologyType: ReplicaSetNoPrimary
+    logicalSessionTimeoutMinutes: null
+    setName: rs
+
+- description: Primary A is rediscovered
+  responses:
+  - - a:27017
+    - ok: 1
+      helloOk: true
+      isWritablePrimary: true
+      hosts:
+      - a:27017
+      setName: rs
+      minWireVersion: 0
+      maxWireVersion: 9
+      topologyVersion: *topologyVersion_1_1
+  outcome: &outcome
+    servers:
+      a:27017:
+        type: RSPrimary
+        setName: rs
+        topologyVersion: *topologyVersion_1_1
+        pool:
+          generation: 1
+    topologyType: ReplicaSetWithPrimary
+    logicalSessionTimeoutMinutes: null
+    setName: rs
+
+- description: Ignore stale NotPrimaryNoSecondaryOk error (stale generation)
+  applicationErrors:
+  - address: a:27017
+    generation: 0
+    when: afterHandshakeCompletes
+    maxWireVersion: 9
+    type: command
+    response:
+      ok: 0
+      errmsg: NotPrimaryNoSecondaryOk
+      code: 13435
+      topologyVersion:
+        processId:
+          "$oid": '000000000000000000000001'
+        counter:
+          "$numberLong": "2"
+  outcome: *outcome
diff --git a/test/spec/server-discovery-and-monitoring/errors/stale-generation-NotMasterOrSecondary.json b/test/spec/server-discovery-and-monitoring/errors/stale-generation-afterHandshakeCompletes-NotPrimaryOrSecondary.json
similarity index 91%
rename from test/spec/server-discovery-and-monitoring/errors/stale-generation-NotMasterOrSecondary.json
rename to test/spec/server-discovery-and-monitoring/errors/stale-generation-afterHandshakeCompletes-NotPrimaryOrSecondary.json
index 11ee062589..57ca1cf158 100644
--- a/test/spec/server-discovery-and-monitoring/errors/stale-generation-NotMasterOrSecondary.json
+++ b/test/spec/server-discovery-and-monitoring/errors/stale-generation-afterHandshakeCompletes-NotPrimaryOrSecondary.json
@@ -1,5 +1,5 @@
 {
-  "description": "Stale generation NotMasterOrSecondary error",
+  "description": "Stale generation NotPrimaryOrSecondary error afterHandshakeCompletes",
   "uri": "mongodb://a/?replicaSet=rs",
   "phases": [
     {
@@ -9,7 +9,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
@@ -82,7 +83,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
@@ -124,7 +126,7 @@
       }
     },
     {
-      "description": "Ignore stale NotMasterOrSecondary error (stale generation)",
+      "description": "Ignore stale NotPrimaryOrSecondary error (stale generation)",
       "applicationErrors": [
         {
           "address": "a:27017",
@@ -134,7 +136,7 @@
           "type": "command",
           "response": {
             "ok": 0,
-            "errmsg": "NotMasterOrSecondary",
+            "errmsg": "NotPrimaryOrSecondary",
             "code": 13436,
             "topologyVersion": {
               "processId": {
diff --git a/test/spec/server-discovery-and-monitoring/errors/stale-generation-afterHandshakeCompletes-NotMasterOrSecondary.yml b/test/spec/server-discovery-and-monitoring/errors/stale-generation-afterHandshakeCompletes-NotPrimaryOrSecondary.yml
similarity index 87%
rename from test/spec/server-discovery-and-monitoring/errors/stale-generation-afterHandshakeCompletes-NotMasterOrSecondary.yml
rename to test/spec/server-discovery-and-monitoring/errors/stale-generation-afterHandshakeCompletes-NotPrimaryOrSecondary.yml
index 665d8b986b..4b036edd0d 100644
--- a/test/spec/server-discovery-and-monitoring/errors/stale-generation-afterHandshakeCompletes-NotMasterOrSecondary.yml
+++ b/test/spec/server-discovery-and-monitoring/errors/stale-generation-afterHandshakeCompletes-NotPrimaryOrSecondary.yml
@@ -1,12 +1,13 @@
 # Autogenerated tests for SDAM error handling, see generate-error-tests.py
-description: Stale generation NotMasterOrSecondary error afterHandshakeCompletes
+description: Stale generation NotPrimaryOrSecondary error afterHandshakeCompletes
 uri: mongodb://a/?replicaSet=rs
 phases:
 - description: Primary A is discovered
   responses:
   - - a:27017
     - ok: 1
-      ismaster: true
+      helloOk: true
+      isWritablePrimary: true
       hosts:
       - a:27017
       setName: rs
@@ -51,7 +52,8 @@ phases:
   responses:
   - - a:27017
     - ok: 1
-      ismaster: true
+      helloOk: true
+      isWritablePrimary: true
       hosts:
       - a:27017
       setName: rs
@@ -70,7 +72,7 @@ phases:
     logicalSessionTimeoutMinutes: null
     setName: rs
 
-- description: Ignore stale NotMasterOrSecondary error (stale generation)
+- description: Ignore stale NotPrimaryOrSecondary error (stale generation)
   applicationErrors:
   - address: a:27017
     generation: 0
@@ -79,7 +81,7 @@ phases:
     type: command
     response:
       ok: 0
-      errmsg: NotMasterOrSecondary
+      errmsg: NotPrimaryOrSecondary
       code: 13436
       topologyVersion:
         processId:
diff --git a/test/spec/server-discovery-and-monitoring/errors/stale-generation-afterHandshakeCompletes-NotMasterNoSlaveOk.json b/test/spec/server-discovery-and-monitoring/errors/stale-generation-afterHandshakeCompletes-NotWritablePrimary.json
similarity index 92%
rename from test/spec/server-discovery-and-monitoring/errors/stale-generation-afterHandshakeCompletes-NotMasterNoSlaveOk.json
rename to test/spec/server-discovery-and-monitoring/errors/stale-generation-afterHandshakeCompletes-NotWritablePrimary.json
index 707a58bcaf..995453c82b 100644
--- a/test/spec/server-discovery-and-monitoring/errors/stale-generation-afterHandshakeCompletes-NotMasterNoSlaveOk.json
+++ b/test/spec/server-discovery-and-monitoring/errors/stale-generation-afterHandshakeCompletes-NotWritablePrimary.json
@@ -1,5 +1,5 @@
 {
-  "description": "Stale generation NotMasterNoSlaveOk error afterHandshakeCompletes",
+  "description": "Stale generation NotWritablePrimary error afterHandshakeCompletes",
   "uri": "mongodb://a/?replicaSet=rs",
   "phases": [
     {
@@ -9,7 +9,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
@@ -82,7 +83,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
@@ -124,7 +126,7 @@
       }
     },
     {
-      "description": "Ignore stale NotMasterNoSlaveOk error (stale generation)",
+      "description": "Ignore stale NotWritablePrimary error (stale generation)",
       "applicationErrors": [
         {
           "address": "a:27017",
@@ -134,8 +136,8 @@
           "type": "command",
           "response": {
             "ok": 0,
-            "errmsg": "NotMasterNoSlaveOk",
-            "code": 13435,
+            "errmsg": "NotWritablePrimary",
+            "code": 10107,
             "topologyVersion": {
               "processId": {
                 "$oid": "000000000000000000000001"
diff --git a/test/spec/server-discovery-and-monitoring/errors/stale-generation-afterHandshakeCompletes-NotMasterNoSlaveOk.yml b/test/spec/server-discovery-and-monitoring/errors/stale-generation-afterHandshakeCompletes-NotWritablePrimary.yml
similarity index 87%
rename from test/spec/server-discovery-and-monitoring/errors/stale-generation-afterHandshakeCompletes-NotMasterNoSlaveOk.yml
rename to test/spec/server-discovery-and-monitoring/errors/stale-generation-afterHandshakeCompletes-NotWritablePrimary.yml
index 0dd1321d55..f9199ef48f 100644
--- a/test/spec/server-discovery-and-monitoring/errors/stale-generation-afterHandshakeCompletes-NotMasterNoSlaveOk.yml
+++ b/test/spec/server-discovery-and-monitoring/errors/stale-generation-afterHandshakeCompletes-NotWritablePrimary.yml
@@ -1,12 +1,13 @@
 # Autogenerated tests for SDAM error handling, see generate-error-tests.py
-description: Stale generation NotMasterNoSlaveOk error afterHandshakeCompletes
+description: Stale generation NotWritablePrimary error afterHandshakeCompletes
 uri: mongodb://a/?replicaSet=rs
 phases:
 - description: Primary A is discovered
   responses:
   - - a:27017
     - ok: 1
-      ismaster: true
+      helloOk: true
+      isWritablePrimary: true
       hosts:
       - a:27017
       setName: rs
@@ -51,7 +52,8 @@ phases:
   responses:
   - - a:27017
     - ok: 1
-      ismaster: true
+      helloOk: true
+      isWritablePrimary: true
       hosts:
       - a:27017
       setName: rs
@@ -70,7 +72,7 @@ phases:
     logicalSessionTimeoutMinutes: null
     setName: rs
 
-- description: Ignore stale NotMasterNoSlaveOk error (stale generation)
+- description: Ignore stale NotWritablePrimary error (stale generation)
   applicationErrors:
   - address: a:27017
     generation: 0
@@ -79,8 +81,8 @@ phases:
     type: command
     response:
       ok: 0
-      errmsg: NotMasterNoSlaveOk
-      code: 13435
+      errmsg: NotWritablePrimary
+      code: 10107
       topologyVersion:
         processId:
           "$oid": '000000000000000000000001'
diff --git a/test/spec/server-discovery-and-monitoring/errors/stale-generation-afterHandshakeCompletes-PrimarySteppedDown.json b/test/spec/server-discovery-and-monitoring/errors/stale-generation-afterHandshakeCompletes-PrimarySteppedDown.json
index 7ac8d2db24..bf4c85d24f 100644
--- a/test/spec/server-discovery-and-monitoring/errors/stale-generation-afterHandshakeCompletes-PrimarySteppedDown.json
+++ b/test/spec/server-discovery-and-monitoring/errors/stale-generation-afterHandshakeCompletes-PrimarySteppedDown.json
@@ -9,7 +9,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
@@ -82,7 +83,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
diff --git a/test/spec/server-discovery-and-monitoring/errors/stale-generation-afterHandshakeCompletes-PrimarySteppedDown.yml b/test/spec/server-discovery-and-monitoring/errors/stale-generation-afterHandshakeCompletes-PrimarySteppedDown.yml
index 897bac6f5b..032993e749 100644
--- a/test/spec/server-discovery-and-monitoring/errors/stale-generation-afterHandshakeCompletes-PrimarySteppedDown.yml
+++ b/test/spec/server-discovery-and-monitoring/errors/stale-generation-afterHandshakeCompletes-PrimarySteppedDown.yml
@@ -6,7 +6,8 @@ phases:
   responses:
   - - a:27017
     - ok: 1
-      ismaster: true
+      helloOk: true
+      isWritablePrimary: true
       hosts:
       - a:27017
       setName: rs
@@ -51,7 +52,8 @@ phases:
   responses:
   - - a:27017
     - ok: 1
-      ismaster: true
+      helloOk: true
+      isWritablePrimary: true
       hosts:
       - a:27017
       setName: rs
diff --git a/test/spec/server-discovery-and-monitoring/errors/stale-generation-afterHandshakeCompletes-ShutdownInProgress.json b/test/spec/server-discovery-and-monitoring/errors/stale-generation-afterHandshakeCompletes-ShutdownInProgress.json
index e250c448aa..9374900e06 100644
--- a/test/spec/server-discovery-and-monitoring/errors/stale-generation-afterHandshakeCompletes-ShutdownInProgress.json
+++ b/test/spec/server-discovery-and-monitoring/errors/stale-generation-afterHandshakeCompletes-ShutdownInProgress.json
@@ -9,7 +9,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
@@ -82,7 +83,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
diff --git a/test/spec/server-discovery-and-monitoring/errors/stale-generation-afterHandshakeCompletes-ShutdownInProgress.yml b/test/spec/server-discovery-and-monitoring/errors/stale-generation-afterHandshakeCompletes-ShutdownInProgress.yml
index c607f646a2..23659f729b 100644
--- a/test/spec/server-discovery-and-monitoring/errors/stale-generation-afterHandshakeCompletes-ShutdownInProgress.yml
+++ b/test/spec/server-discovery-and-monitoring/errors/stale-generation-afterHandshakeCompletes-ShutdownInProgress.yml
@@ -6,7 +6,8 @@ phases:
   responses:
   - - a:27017
     - ok: 1
-      ismaster: true
+      helloOk: true
+      isWritablePrimary: true
       hosts:
       - a:27017
       setName: rs
@@ -51,7 +52,8 @@ phases:
   responses:
   - - a:27017
     - ok: 1
-      ismaster: true
+      helloOk: true
+      isWritablePrimary: true
       hosts:
       - a:27017
       setName: rs
diff --git a/test/spec/server-discovery-and-monitoring/errors/stale-generation-afterHandshakeCompletes-network.json b/test/spec/server-discovery-and-monitoring/errors/stale-generation-afterHandshakeCompletes-network.json
index 4e11c48eb2..f5d01b6540 100644
--- a/test/spec/server-discovery-and-monitoring/errors/stale-generation-afterHandshakeCompletes-network.json
+++ b/test/spec/server-discovery-and-monitoring/errors/stale-generation-afterHandshakeCompletes-network.json
@@ -1,5 +1,5 @@
 {
-  "description": "Stale generation NotMasterNoSlaveOk error afterHandshakeCompletes",
+  "description": "Stale generation network error afterHandshakeCompletes",
   "uri": "mongodb://a/?replicaSet=rs",
   "phases": [
     {
@@ -9,7 +9,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
@@ -82,7 +83,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
@@ -124,7 +126,7 @@
       }
     },
     {
-      "description": "Ignore stale NotMasterNoSlaveOk error (stale generation)",
+      "description": "Ignore stale network error (stale generation)",
       "applicationErrors": [
         {
           "address": "a:27017",
diff --git a/test/spec/server-discovery-and-monitoring/errors/stale-generation-afterHandshakeCompletes-network.yml b/test/spec/server-discovery-and-monitoring/errors/stale-generation-afterHandshakeCompletes-network.yml
index ec06490f98..98cb9a44e1 100644
--- a/test/spec/server-discovery-and-monitoring/errors/stale-generation-afterHandshakeCompletes-network.yml
+++ b/test/spec/server-discovery-and-monitoring/errors/stale-generation-afterHandshakeCompletes-network.yml
@@ -1,12 +1,13 @@
 # Autogenerated tests for SDAM error handling, see generate-error-tests.py
-description: Stale generation NotMasterNoSlaveOk error afterHandshakeCompletes
+description: Stale generation network error afterHandshakeCompletes
 uri: mongodb://a/?replicaSet=rs
 phases:
 - description: Primary A is discovered
   responses:
   - - a:27017
     - ok: 1
-      ismaster: true
+      helloOk: true
+      isWritablePrimary: true
       hosts:
       - a:27017
       setName: rs
@@ -51,7 +52,8 @@ phases:
   responses:
   - - a:27017
     - ok: 1
-      ismaster: true
+      helloOk: true
+      isWritablePrimary: true
       hosts:
       - a:27017
       setName: rs
@@ -70,7 +72,7 @@ phases:
     logicalSessionTimeoutMinutes: null
     setName: rs
 
-- description: Ignore stale NotMasterNoSlaveOk error (stale generation)
+- description: Ignore stale network error (stale generation)
   applicationErrors:
   - address: a:27017
     generation: 0
diff --git a/test/spec/server-discovery-and-monitoring/errors/stale-generation-afterHandshakeCompletes-timeout.json b/test/spec/server-discovery-and-monitoring/errors/stale-generation-afterHandshakeCompletes-timeout.json
index 27bac32443..fa84343b0b 100644
--- a/test/spec/server-discovery-and-monitoring/errors/stale-generation-afterHandshakeCompletes-timeout.json
+++ b/test/spec/server-discovery-and-monitoring/errors/stale-generation-afterHandshakeCompletes-timeout.json
@@ -1,5 +1,5 @@
 {
-  "description": "Stale generation NotMasterNoSlaveOk error afterHandshakeCompletes",
+  "description": "Stale generation timeout error afterHandshakeCompletes",
   "uri": "mongodb://a/?replicaSet=rs",
   "phases": [
     {
@@ -9,7 +9,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
@@ -82,7 +83,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
@@ -124,7 +126,7 @@
       }
     },
     {
-      "description": "Ignore stale NotMasterNoSlaveOk error (stale generation)",
+      "description": "Ignore stale timeout error (stale generation)",
       "applicationErrors": [
         {
           "address": "a:27017",
diff --git a/test/spec/server-discovery-and-monitoring/errors/stale-generation-afterHandshakeCompletes-timeout.yml b/test/spec/server-discovery-and-monitoring/errors/stale-generation-afterHandshakeCompletes-timeout.yml
index a65304c282..37b8f71d8d 100644
--- a/test/spec/server-discovery-and-monitoring/errors/stale-generation-afterHandshakeCompletes-timeout.yml
+++ b/test/spec/server-discovery-and-monitoring/errors/stale-generation-afterHandshakeCompletes-timeout.yml
@@ -1,12 +1,13 @@
 # Autogenerated tests for SDAM error handling, see generate-error-tests.py
-description: Stale generation NotMasterNoSlaveOk error afterHandshakeCompletes
+description: Stale generation timeout error afterHandshakeCompletes
 uri: mongodb://a/?replicaSet=rs
 phases:
 - description: Primary A is discovered
   responses:
   - - a:27017
     - ok: 1
-      ismaster: true
+      helloOk: true
+      isWritablePrimary: true
       hosts:
       - a:27017
       setName: rs
@@ -51,7 +52,8 @@ phases:
   responses:
   - - a:27017
     - ok: 1
-      ismaster: true
+      helloOk: true
+      isWritablePrimary: true
       hosts:
       - a:27017
       setName: rs
@@ -70,7 +72,7 @@ phases:
     logicalSessionTimeoutMinutes: null
     setName: rs
 
-- description: Ignore stale NotMasterNoSlaveOk error (stale generation)
+- description: Ignore stale timeout error (stale generation)
   applicationErrors:
   - address: a:27017
     generation: 0
diff --git a/test/spec/server-discovery-and-monitoring/errors/stale-generation-beforeHandshakeCompletes-InterruptedAtShutdown.json b/test/spec/server-discovery-and-monitoring/errors/stale-generation-beforeHandshakeCompletes-InterruptedAtShutdown.json
index 8b10f5eb75..72fac9a86e 100644
--- a/test/spec/server-discovery-and-monitoring/errors/stale-generation-beforeHandshakeCompletes-InterruptedAtShutdown.json
+++ b/test/spec/server-discovery-and-monitoring/errors/stale-generation-beforeHandshakeCompletes-InterruptedAtShutdown.json
@@ -9,7 +9,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
@@ -82,7 +83,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
diff --git a/test/spec/server-discovery-and-monitoring/errors/stale-generation-beforeHandshakeCompletes-InterruptedAtShutdown.yml b/test/spec/server-discovery-and-monitoring/errors/stale-generation-beforeHandshakeCompletes-InterruptedAtShutdown.yml
index 9b3f9c11d7..c699c53ab1 100644
--- a/test/spec/server-discovery-and-monitoring/errors/stale-generation-beforeHandshakeCompletes-InterruptedAtShutdown.yml
+++ b/test/spec/server-discovery-and-monitoring/errors/stale-generation-beforeHandshakeCompletes-InterruptedAtShutdown.yml
@@ -6,7 +6,8 @@ phases:
   responses:
   - - a:27017
     - ok: 1
-      ismaster: true
+      helloOk: true
+      isWritablePrimary: true
       hosts:
       - a:27017
       setName: rs
@@ -51,7 +52,8 @@ phases:
   responses:
   - - a:27017
     - ok: 1
-      ismaster: true
+      helloOk: true
+      isWritablePrimary: true
       hosts:
       - a:27017
       setName: rs
diff --git a/test/spec/server-discovery-and-monitoring/errors/stale-generation-beforeHandshakeCompletes-InterruptedDueToReplStateChange.json b/test/spec/server-discovery-and-monitoring/errors/stale-generation-beforeHandshakeCompletes-InterruptedDueToReplStateChange.json
index ec78d667c2..3c713592a3 100644
--- a/test/spec/server-discovery-and-monitoring/errors/stale-generation-beforeHandshakeCompletes-InterruptedDueToReplStateChange.json
+++ b/test/spec/server-discovery-and-monitoring/errors/stale-generation-beforeHandshakeCompletes-InterruptedDueToReplStateChange.json
@@ -9,7 +9,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
@@ -82,7 +83,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
diff --git a/test/spec/server-discovery-and-monitoring/errors/stale-generation-beforeHandshakeCompletes-InterruptedDueToReplStateChange.yml b/test/spec/server-discovery-and-monitoring/errors/stale-generation-beforeHandshakeCompletes-InterruptedDueToReplStateChange.yml
index 8332db4fa4..a9826eb01a 100644
--- a/test/spec/server-discovery-and-monitoring/errors/stale-generation-beforeHandshakeCompletes-InterruptedDueToReplStateChange.yml
+++ b/test/spec/server-discovery-and-monitoring/errors/stale-generation-beforeHandshakeCompletes-InterruptedDueToReplStateChange.yml
@@ -6,7 +6,8 @@ phases:
   responses:
   - - a:27017
     - ok: 1
-      ismaster: true
+      helloOk: true
+      isWritablePrimary: true
       hosts:
       - a:27017
       setName: rs
@@ -51,7 +52,8 @@ phases:
   responses:
   - - a:27017
     - ok: 1
-      ismaster: true
+      helloOk: true
+      isWritablePrimary: true
       hosts:
       - a:27017
       setName: rs
diff --git a/test/spec/server-discovery-and-monitoring/errors/stale-generation-beforeHandshakeCompletes-NotMaster.json b/test/spec/server-discovery-and-monitoring/errors/stale-generation-beforeHandshakeCompletes-LegacyNotPrimary.json
similarity index 91%
rename from test/spec/server-discovery-and-monitoring/errors/stale-generation-beforeHandshakeCompletes-NotMaster.json
rename to test/spec/server-discovery-and-monitoring/errors/stale-generation-beforeHandshakeCompletes-LegacyNotPrimary.json
index 760f260d48..257b6ec6fb 100644
--- a/test/spec/server-discovery-and-monitoring/errors/stale-generation-beforeHandshakeCompletes-NotMaster.json
+++ b/test/spec/server-discovery-and-monitoring/errors/stale-generation-beforeHandshakeCompletes-LegacyNotPrimary.json
@@ -1,5 +1,5 @@
 {
-  "description": "Stale generation NotMaster error beforeHandshakeCompletes",
+  "description": "Stale generation LegacyNotPrimary error beforeHandshakeCompletes",
   "uri": "mongodb://a/?replicaSet=rs",
   "phases": [
     {
@@ -9,7 +9,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
@@ -82,7 +83,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
@@ -124,7 +126,7 @@
       }
     },
     {
-      "description": "Ignore stale NotMaster error (stale generation)",
+      "description": "Ignore stale LegacyNotPrimary error (stale generation)",
       "applicationErrors": [
         {
           "address": "a:27017",
@@ -134,8 +136,8 @@
           "type": "command",
           "response": {
             "ok": 0,
-            "errmsg": "NotMaster",
-            "code": 10107,
+            "errmsg": "LegacyNotPrimary",
+            "code": 10058,
             "topologyVersion": {
               "processId": {
                 "$oid": "000000000000000000000001"
diff --git a/test/spec/server-discovery-and-monitoring/errors/stale-generation-beforeHandshakeCompletes-NotMaster.yml b/test/spec/server-discovery-and-monitoring/errors/stale-generation-beforeHandshakeCompletes-LegacyNotPrimary.yml
similarity index 86%
rename from test/spec/server-discovery-and-monitoring/errors/stale-generation-beforeHandshakeCompletes-NotMaster.yml
rename to test/spec/server-discovery-and-monitoring/errors/stale-generation-beforeHandshakeCompletes-LegacyNotPrimary.yml
index 3f4321a0f2..f26d4d963f 100644
--- a/test/spec/server-discovery-and-monitoring/errors/stale-generation-beforeHandshakeCompletes-NotMaster.yml
+++ b/test/spec/server-discovery-and-monitoring/errors/stale-generation-beforeHandshakeCompletes-LegacyNotPrimary.yml
@@ -1,12 +1,13 @@
 # Autogenerated tests for SDAM error handling, see generate-error-tests.py
-description: Stale generation NotMaster error beforeHandshakeCompletes
+description: Stale generation LegacyNotPrimary error beforeHandshakeCompletes
 uri: mongodb://a/?replicaSet=rs
 phases:
 - description: Primary A is discovered
   responses:
   - - a:27017
     - ok: 1
-      ismaster: true
+      helloOk: true
+      isWritablePrimary: true
       hosts:
       - a:27017
       setName: rs
@@ -51,7 +52,8 @@ phases:
   responses:
   - - a:27017
     - ok: 1
-      ismaster: true
+      helloOk: true
+      isWritablePrimary: true
       hosts:
       - a:27017
       setName: rs
@@ -70,7 +72,7 @@ phases:
     logicalSessionTimeoutMinutes: null
     setName: rs
 
-- description: Ignore stale NotMaster error (stale generation)
+- description: Ignore stale LegacyNotPrimary error (stale generation)
   applicationErrors:
   - address: a:27017
     generation: 0
@@ -79,8 +81,8 @@ phases:
     type: command
     response:
       ok: 0
-      errmsg: NotMaster
-      code: 10107
+      errmsg: LegacyNotPrimary
+      code: 10058
       topologyVersion:
         processId:
           "$oid": '000000000000000000000001'
diff --git a/test/spec/server-discovery-and-monitoring/errors/stale-generation-beforeHandshakeCompletes-NotPrimaryNoSecondaryOk.json b/test/spec/server-discovery-and-monitoring/errors/stale-generation-beforeHandshakeCompletes-NotPrimaryNoSecondaryOk.json
new file mode 100644
index 0000000000..dcb5716f44
--- /dev/null
+++ b/test/spec/server-discovery-and-monitoring/errors/stale-generation-beforeHandshakeCompletes-NotPrimaryNoSecondaryOk.json
@@ -0,0 +1,176 @@
+{
+  "description": "Stale generation NotPrimaryNoSecondaryOk error beforeHandshakeCompletes",
+  "uri": "mongodb://a/?replicaSet=rs",
+  "phases": [
+    {
+      "description": "Primary A is discovered",
+      "responses": [
+        [
+          "a:27017",
+          {
+            "ok": 1,
+            "helloOk": true,
+            "isWritablePrimary": true,
+            "hosts": [
+              "a:27017"
+            ],
+            "setName": "rs",
+            "minWireVersion": 0,
+            "maxWireVersion": 9,
+            "topologyVersion": {
+              "processId": {
+                "$oid": "000000000000000000000001"
+              },
+              "counter": {
+                "$numberLong": "1"
+              }
+            }
+          }
+        ]
+      ],
+      "outcome": {
+        "servers": {
+          "a:27017": {
+            "type": "RSPrimary",
+            "setName": "rs",
+            "topologyVersion": {
+              "processId": {
+                "$oid": "000000000000000000000001"
+              },
+              "counter": {
+                "$numberLong": "1"
+              }
+            },
+            "pool": {
+              "generation": 0
+            }
+          }
+        },
+        "topologyType": "ReplicaSetWithPrimary",
+        "logicalSessionTimeoutMinutes": null,
+        "setName": "rs"
+      }
+    },
+    {
+      "description": "Non-stale application network error",
+      "applicationErrors": [
+        {
+          "address": "a:27017",
+          "when": "afterHandshakeCompletes",
+          "maxWireVersion": 9,
+          "type": "network"
+        }
+      ],
+      "outcome": {
+        "servers": {
+          "a:27017": {
+            "type": "Unknown",
+            "topologyVersion": null,
+            "pool": {
+              "generation": 1
+            }
+          }
+        },
+        "topologyType": "ReplicaSetNoPrimary",
+        "logicalSessionTimeoutMinutes": null,
+        "setName": "rs"
+      }
+    },
+    {
+      "description": "Primary A is rediscovered",
+      "responses": [
+        [
+          "a:27017",
+          {
+            "ok": 1,
+            "helloOk": true,
+            "isWritablePrimary": true,
+            "hosts": [
+              "a:27017"
+            ],
+            "setName": "rs",
+            "minWireVersion": 0,
+            "maxWireVersion": 9,
+            "topologyVersion": {
+              "processId": {
+                "$oid": "000000000000000000000001"
+              },
+              "counter": {
+                "$numberLong": "1"
+              }
+            }
+          }
+        ]
+      ],
+      "outcome": {
+        "servers": {
+          "a:27017": {
+            "type": "RSPrimary",
+            "setName": "rs",
+            "topologyVersion": {
+              "processId": {
+                "$oid": "000000000000000000000001"
+              },
+              "counter": {
+                "$numberLong": "1"
+              }
+            },
+            "pool": {
+              "generation": 1
+            }
+          }
+        },
+        "topologyType": "ReplicaSetWithPrimary",
+        "logicalSessionTimeoutMinutes": null,
+        "setName": "rs"
+      }
+    },
+    {
+      "description": "Ignore stale NotPrimaryNoSecondaryOk error (stale generation)",
+      "applicationErrors": [
+        {
+          "address": "a:27017",
+          "generation": 0,
+          "when": "beforeHandshakeCompletes",
+          "maxWireVersion": 9,
+          "type": "command",
+          "response": {
+            "ok": 0,
+            "errmsg": "NotPrimaryNoSecondaryOk",
+            "code": 13435,
+            "topologyVersion": {
+              "processId": {
+                "$oid": "000000000000000000000001"
+              },
+              "counter": {
+                "$numberLong": "2"
+              }
+            }
+          }
+        }
+      ],
+      "outcome": {
+        "servers": {
+          "a:27017": {
+            "type": "RSPrimary",
+            "setName": "rs",
+            "topologyVersion": {
+              "processId": {
+                "$oid": "000000000000000000000001"
+              },
+              "counter": {
+                "$numberLong": "1"
+              }
+            },
+            "pool": {
+              "generation": 1
+            }
+          }
+        },
+        "topologyType": "ReplicaSetWithPrimary",
+        "logicalSessionTimeoutMinutes": null,
+        "setName": "rs"
+      }
+    }
+  ]
+}
diff --git a/test/spec/server-discovery-and-monitoring/errors/stale-generation-beforeHandshakeCompletes-NotPrimaryNoSecondaryOk.yml b/test/spec/server-discovery-and-monitoring/errors/stale-generation-beforeHandshakeCompletes-NotPrimaryNoSecondaryOk.yml
new file mode 100644
index 0000000000..27187bae63
--- /dev/null
+++ b/test/spec/server-discovery-and-monitoring/errors/stale-generation-beforeHandshakeCompletes-NotPrimaryNoSecondaryOk.yml
@@ -0,0 +1,91 @@
+# Autogenerated tests for SDAM error handling, see generate-error-tests.py
+description: Stale generation NotPrimaryNoSecondaryOk error beforeHandshakeCompletes
+uri: mongodb://a/?replicaSet=rs
+phases:
+- description: Primary A is discovered
+  responses:
+  - - a:27017
+    - ok: 1
+      helloOk: true
+      isWritablePrimary: true
+      hosts:
+      - a:27017
+      setName: rs
+      minWireVersion: 0
+      maxWireVersion: 9
+      topologyVersion: &topologyVersion_1_1
+        processId:
+          "$oid": '000000000000000000000001'
+        counter:
+          "$numberLong": '1'
+  outcome:
+    servers:
+      a:27017:
+        type: RSPrimary
+        setName: rs
+        topologyVersion: *topologyVersion_1_1
+        pool:
+          generation: 0
+    topologyType: ReplicaSetWithPrimary
+    logicalSessionTimeoutMinutes: null
+    setName: rs
+
+# Process a network error which increments the pool generation.
+- description: Non-stale application network error
+  applicationErrors:
+  - address: a:27017
+    when: afterHandshakeCompletes
+    maxWireVersion: 9
+    type: network
+  outcome:
+    servers:
+      a:27017:
+        type: Unknown
+        topologyVersion: null
+        pool:
+          generation: 1
+    topologyType: ReplicaSetNoPrimary
+    logicalSessionTimeoutMinutes: null
+    setName: rs
+
+- description: Primary A is rediscovered
+  responses:
+  - - a:27017
+    - ok: 1
+      helloOk: true
+      isWritablePrimary: true
+      hosts:
+      - a:27017
+      setName: rs
+      minWireVersion: 0
+      maxWireVersion: 9
+      topologyVersion: *topologyVersion_1_1
+  outcome: &outcome
+    servers:
+      a:27017:
+        type: RSPrimary
+        setName: rs
+        topologyVersion: *topologyVersion_1_1
+        pool:
+          generation: 1
+    topologyType: ReplicaSetWithPrimary
+    logicalSessionTimeoutMinutes: null
+    setName: rs
+
+- description: Ignore stale NotPrimaryNoSecondaryOk error (stale generation)
+  applicationErrors:
+  - address: a:27017
+    generation: 0
+    when: beforeHandshakeCompletes
+    maxWireVersion: 9
+    type: command
+    response:
+      ok: 0
+      errmsg: NotPrimaryNoSecondaryOk
+      code: 13435
+      topologyVersion:
+        processId:
+          "$oid": '000000000000000000000001'
+        counter:
+          "$numberLong": "2"
+  outcome: *outcome
diff --git a/test/spec/server-discovery-and-monitoring/errors/stale-generation-beforeHandshakeCompletes-NotMasterOrSecondary.json b/test/spec/server-discovery-and-monitoring/errors/stale-generation-beforeHandshakeCompletes-NotPrimaryOrSecondary.json
similarity index 91%
rename from test/spec/server-discovery-and-monitoring/errors/stale-generation-beforeHandshakeCompletes-NotMasterOrSecondary.json
rename to test/spec/server-discovery-and-monitoring/errors/stale-generation-beforeHandshakeCompletes-NotPrimaryOrSecondary.json
index eced40c59c..58cefafae9 100644
--- a/test/spec/server-discovery-and-monitoring/errors/stale-generation-beforeHandshakeCompletes-NotMasterOrSecondary.json
+++ b/test/spec/server-discovery-and-monitoring/errors/stale-generation-beforeHandshakeCompletes-NotPrimaryOrSecondary.json
@@ -1,5 +1,5 @@
 {
-  "description": "Stale generation NotMasterOrSecondary error beforeHandshakeCompletes",
+  "description": "Stale generation NotPrimaryOrSecondary error beforeHandshakeCompletes",
   "uri": "mongodb://a/?replicaSet=rs",
   "phases": [
     {
@@ -9,7 +9,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
@@ -82,7 +83,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
@@ -124,7 +126,7 @@
       }
     },
     {
-      "description": "Ignore stale NotMasterOrSecondary error (stale generation)",
+      "description": "Ignore stale NotPrimaryOrSecondary error (stale generation)",
       "applicationErrors": [
         {
           "address": "a:27017",
@@ -134,7 +136,7 @@
           "type": "command",
           "response": {
             "ok": 0,
-            "errmsg": "NotMasterOrSecondary",
+            "errmsg": "NotPrimaryOrSecondary",
             "code": 13436,
             "topologyVersion": {
               "processId": {
diff --git a/test/spec/server-discovery-and-monitoring/errors/stale-generation-beforeHandshakeCompletes-NotMasterOrSecondary.yml b/test/spec/server-discovery-and-monitoring/errors/stale-generation-beforeHandshakeCompletes-NotPrimaryOrSecondary.yml
similarity index 87%
rename from test/spec/server-discovery-and-monitoring/errors/stale-generation-beforeHandshakeCompletes-NotMasterOrSecondary.yml
rename to test/spec/server-discovery-and-monitoring/errors/stale-generation-beforeHandshakeCompletes-NotPrimaryOrSecondary.yml
index 2462deba85..1b56fd2ab7 100644
--- a/test/spec/server-discovery-and-monitoring/errors/stale-generation-beforeHandshakeCompletes-NotMasterOrSecondary.yml
+++ b/test/spec/server-discovery-and-monitoring/errors/stale-generation-beforeHandshakeCompletes-NotPrimaryOrSecondary.yml
@@ -1,12 +1,13 @@
 # Autogenerated tests for SDAM error handling, see generate-error-tests.py
-description: Stale generation NotMasterOrSecondary error beforeHandshakeCompletes
+description: Stale generation NotPrimaryOrSecondary error beforeHandshakeCompletes
 uri: mongodb://a/?replicaSet=rs
 phases:
 - description: Primary A is discovered
   responses:
   - - a:27017
     - ok: 1
-      ismaster: true
+      helloOk: true
+      isWritablePrimary: true
       hosts:
       - a:27017
       setName: rs
@@ -51,7 +52,8 @@ phases:
   responses:
   - - a:27017
     - ok: 1
-      ismaster: true
+      helloOk: true
+      isWritablePrimary: true
       hosts:
       - a:27017
       setName: rs
@@ -70,7 +72,7 @@ phases:
     logicalSessionTimeoutMinutes: null
     setName: rs
 
-- description: Ignore stale NotMasterOrSecondary error (stale generation)
+- description: Ignore stale NotPrimaryOrSecondary error (stale generation)
   applicationErrors:
   - address: a:27017
     generation: 0
@@ -79,7 +81,7 @@ phases:
     type: command
     response:
       ok: 0
-      errmsg: NotMasterOrSecondary
+      errmsg: NotPrimaryOrSecondary
       code: 13436
       topologyVersion:
         processId:
diff --git a/test/spec/server-discovery-and-monitoring/errors/stale-generation-beforeHandshakeCompletes-NotMasterNoSlaveOk.json b/test/spec/server-discovery-and-monitoring/errors/stale-generation-beforeHandshakeCompletes-NotWritablePrimary.json
similarity index 92%
rename from test/spec/server-discovery-and-monitoring/errors/stale-generation-beforeHandshakeCompletes-NotMasterNoSlaveOk.json
rename to test/spec/server-discovery-and-monitoring/errors/stale-generation-beforeHandshakeCompletes-NotWritablePrimary.json
index bb7946aca3..c92b01e054 100644
--- a/test/spec/server-discovery-and-monitoring/errors/stale-generation-beforeHandshakeCompletes-NotMasterNoSlaveOk.json
+++ b/test/spec/server-discovery-and-monitoring/errors/stale-generation-beforeHandshakeCompletes-NotWritablePrimary.json
@@ -1,5 +1,5 @@
 {
-  "description": "Stale generation NotMasterNoSlaveOk error beforeHandshakeCompletes",
+  "description": "Stale generation NotWritablePrimary error beforeHandshakeCompletes",
   "uri": "mongodb://a/?replicaSet=rs",
   "phases": [
     {
@@ -9,7 +9,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
@@ -82,7 +83,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
@@ -124,7 +126,7 @@
       }
     },
     {
-      "description": "Ignore stale NotMasterNoSlaveOk error (stale generation)",
+      "description": "Ignore stale NotWritablePrimary error (stale generation)",
       "applicationErrors": [
         {
           "address": "a:27017",
@@ -134,8 +136,8 @@
           "type": "command",
           "response": {
             "ok": 0,
-            "errmsg": "NotMasterNoSlaveOk",
-            "code": 13435,
+            "errmsg": "NotWritablePrimary",
+            "code": 10107,
             "topologyVersion": {
               "processId": {
                 "$oid": "000000000000000000000001"
diff --git a/test/spec/server-discovery-and-monitoring/errors/stale-generation-beforeHandshakeCompletes-NotMasterNoSlaveOk.yml b/test/spec/server-discovery-and-monitoring/errors/stale-generation-beforeHandshakeCompletes-NotWritablePrimary.yml
similarity index 87%
rename from test/spec/server-discovery-and-monitoring/errors/stale-generation-beforeHandshakeCompletes-NotMasterNoSlaveOk.yml
rename to test/spec/server-discovery-and-monitoring/errors/stale-generation-beforeHandshakeCompletes-NotWritablePrimary.yml
index 98c1609a44..725dc172de 100644
--- a/test/spec/server-discovery-and-monitoring/errors/stale-generation-beforeHandshakeCompletes-NotMasterNoSlaveOk.yml
+++ b/test/spec/server-discovery-and-monitoring/errors/stale-generation-beforeHandshakeCompletes-NotWritablePrimary.yml
@@ -1,12 +1,13 @@
 # Autogenerated tests for SDAM error handling, see generate-error-tests.py
-description: Stale generation NotMasterNoSlaveOk error beforeHandshakeCompletes
+description: Stale generation NotWritablePrimary error beforeHandshakeCompletes
 uri: mongodb://a/?replicaSet=rs
 phases:
 - description: Primary A is discovered
   responses:
   - - a:27017
     - ok: 1
-      ismaster: true
+      helloOk: true
+      isWritablePrimary: true
       hosts:
       - a:27017
       setName: rs
@@ -51,7 +52,8 @@ phases:
   responses:
   - - a:27017
     - ok: 1
-      ismaster: true
+      helloOk: true
+      isWritablePrimary: true
       hosts:
       - a:27017
       setName: rs
@@ -70,7 +72,7 @@ phases:
     logicalSessionTimeoutMinutes: null
     setName: rs
 
-- description: Ignore stale NotMasterNoSlaveOk error (stale generation)
+- description: Ignore stale NotWritablePrimary error (stale generation)
   applicationErrors:
   - address: a:27017
     generation: 0
@@ -79,8 +81,8 @@ phases:
     type: command
     response:
       ok: 0
-      errmsg: NotMasterNoSlaveOk
-      code: 13435
+      errmsg: NotWritablePrimary
+      code: 10107
       topologyVersion:
         processId:
           "$oid": '000000000000000000000001'
diff --git a/test/spec/server-discovery-and-monitoring/errors/stale-generation-beforeHandshakeCompletes-PrimarySteppedDown.json b/test/spec/server-discovery-and-monitoring/errors/stale-generation-beforeHandshakeCompletes-PrimarySteppedDown.json
index d33dc98db3..62759b6ad9 100644
--- a/test/spec/server-discovery-and-monitoring/errors/stale-generation-beforeHandshakeCompletes-PrimarySteppedDown.json
+++ b/test/spec/server-discovery-and-monitoring/errors/stale-generation-beforeHandshakeCompletes-PrimarySteppedDown.json
@@ -9,7 +9,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
@@ -82,7 +83,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
diff --git a/test/spec/server-discovery-and-monitoring/errors/stale-generation-beforeHandshakeCompletes-PrimarySteppedDown.yml b/test/spec/server-discovery-and-monitoring/errors/stale-generation-beforeHandshakeCompletes-PrimarySteppedDown.yml
index 7327ffb8a9..cac86fa7ee 100644
--- a/test/spec/server-discovery-and-monitoring/errors/stale-generation-beforeHandshakeCompletes-PrimarySteppedDown.yml
+++ b/test/spec/server-discovery-and-monitoring/errors/stale-generation-beforeHandshakeCompletes-PrimarySteppedDown.yml
@@ -6,7 +6,8 @@ phases:
   responses:
   - - a:27017
     - ok: 1
-      ismaster: true
+      helloOk: true
+      isWritablePrimary: true
       hosts:
       - a:27017
       setName: rs
@@ -51,7 +52,8 @@ phases:
   responses:
   - - a:27017
     - ok: 1
-      ismaster: true
+      helloOk: true
+      isWritablePrimary: true
       hosts:
       - a:27017
       setName: rs
diff --git a/test/spec/server-discovery-and-monitoring/errors/stale-generation-beforeHandshakeCompletes-ShutdownInProgress.json b/test/spec/server-discovery-and-monitoring/errors/stale-generation-beforeHandshakeCompletes-ShutdownInProgress.json
index ee38cc8bbe..4661632c4f 100644
--- a/test/spec/server-discovery-and-monitoring/errors/stale-generation-beforeHandshakeCompletes-ShutdownInProgress.json
+++ b/test/spec/server-discovery-and-monitoring/errors/stale-generation-beforeHandshakeCompletes-ShutdownInProgress.json
@@ -9,7 +9,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
@@ -82,7 +83,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
diff --git a/test/spec/server-discovery-and-monitoring/errors/stale-generation-beforeHandshakeCompletes-ShutdownInProgress.yml b/test/spec/server-discovery-and-monitoring/errors/stale-generation-beforeHandshakeCompletes-ShutdownInProgress.yml
index fd7039ca9f..dd3ca671b3 100644
--- a/test/spec/server-discovery-and-monitoring/errors/stale-generation-beforeHandshakeCompletes-ShutdownInProgress.yml
+++ b/test/spec/server-discovery-and-monitoring/errors/stale-generation-beforeHandshakeCompletes-ShutdownInProgress.yml
@@ -6,7 +6,8 @@ phases:
   responses:
   - - a:27017
     - ok: 1
-      ismaster: true
+      helloOk: true
+      isWritablePrimary: true
       hosts:
       - a:27017
       setName: rs
@@ -51,7 +52,8 @@ phases:
   responses:
   - - a:27017
     - ok: 1
-      ismaster: true
+      helloOk: true
+      isWritablePrimary: true
       hosts:
       - a:27017
       setName: rs
diff --git a/test/spec/server-discovery-and-monitoring/errors/stale-generation-beforeHandshakeCompletes-network.json b/test/spec/server-discovery-and-monitoring/errors/stale-generation-beforeHandshakeCompletes-network.json
index 9734776f22..15b044fc73 100644
--- a/test/spec/server-discovery-and-monitoring/errors/stale-generation-beforeHandshakeCompletes-network.json
+++ b/test/spec/server-discovery-and-monitoring/errors/stale-generation-beforeHandshakeCompletes-network.json
@@ -1,5 +1,5 @@
 {
-  "description": "Stale generation NotMasterNoSlaveOk error beforeHandshakeCompletes",
+  "description": "Stale generation network error beforeHandshakeCompletes",
   "uri": "mongodb://a/?replicaSet=rs",
   "phases": [
     {
@@ -9,7 +9,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
@@ -82,7 +83,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
@@ -124,7 +126,7 @@
       }
     },
     {
-      "description": "Ignore stale NotMasterNoSlaveOk error (stale generation)",
+      "description": "Ignore stale network error (stale generation)",
       "applicationErrors": [
         {
           "address": "a:27017",
diff --git a/test/spec/server-discovery-and-monitoring/errors/stale-generation-beforeHandshakeCompletes-network.yml b/test/spec/server-discovery-and-monitoring/errors/stale-generation-beforeHandshakeCompletes-network.yml
index 1ef43508d7..b678534826 100644
--- a/test/spec/server-discovery-and-monitoring/errors/stale-generation-beforeHandshakeCompletes-network.yml
+++ b/test/spec/server-discovery-and-monitoring/errors/stale-generation-beforeHandshakeCompletes-network.yml
@@ -1,12 +1,13 @@
 # Autogenerated tests for SDAM error handling, see generate-error-tests.py
-description: Stale generation NotMasterNoSlaveOk error beforeHandshakeCompletes
+description: Stale generation network error beforeHandshakeCompletes
 uri: mongodb://a/?replicaSet=rs
 phases:
 - description: Primary A is discovered
   responses:
   - - a:27017
     - ok: 1
-      ismaster: true
+      helloOk: true
+      isWritablePrimary: true
       hosts:
       - a:27017
       setName: rs
@@ -51,7 +52,8 @@ phases:
   responses:
   - - a:27017
     - ok: 1
-      ismaster: true
+      helloOk: true
+      isWritablePrimary: true
       hosts:
       - a:27017
       setName: rs
@@ -70,7 +72,7 @@ phases:
     logicalSessionTimeoutMinutes: null
     setName: rs
 
-- description: Ignore stale NotMasterNoSlaveOk error (stale generation)
+- description: Ignore stale network error (stale generation)
   applicationErrors:
   - address: a:27017
     generation: 0
diff --git a/test/spec/server-discovery-and-monitoring/errors/stale-generation-beforeHandshakeCompletes-timeout.json b/test/spec/server-discovery-and-monitoring/errors/stale-generation-beforeHandshakeCompletes-timeout.json
index af8730e5ca..acbb9e581e 100644
--- a/test/spec/server-discovery-and-monitoring/errors/stale-generation-beforeHandshakeCompletes-timeout.json
+++ b/test/spec/server-discovery-and-monitoring/errors/stale-generation-beforeHandshakeCompletes-timeout.json
@@ -1,5 +1,5 @@
 {
-  "description": "Stale generation NotMasterNoSlaveOk error beforeHandshakeCompletes",
+  "description": "Stale generation timeout error beforeHandshakeCompletes",
   "uri": "mongodb://a/?replicaSet=rs",
   "phases": [
     {
@@ -9,7 +9,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
@@ -82,7 +83,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
@@ -124,7 +126,7 @@
       }
     },
     {
-      "description": "Ignore stale NotMasterNoSlaveOk error (stale generation)",
+      "description": "Ignore stale timeout error (stale generation)",
       "applicationErrors": [
         {
           "address": "a:27017",
diff --git a/test/spec/server-discovery-and-monitoring/errors/stale-generation-beforeHandshakeCompletes-timeout.yml b/test/spec/server-discovery-and-monitoring/errors/stale-generation-beforeHandshakeCompletes-timeout.yml
index 40471d9441..d1ba24ba3b 100644
--- a/test/spec/server-discovery-and-monitoring/errors/stale-generation-beforeHandshakeCompletes-timeout.yml
+++ b/test/spec/server-discovery-and-monitoring/errors/stale-generation-beforeHandshakeCompletes-timeout.yml
@@ -1,12 +1,13 @@
 # Autogenerated tests for SDAM error handling, see generate-error-tests.py
-description: Stale generation NotMasterNoSlaveOk error beforeHandshakeCompletes
+description: Stale generation timeout error beforeHandshakeCompletes
 uri: mongodb://a/?replicaSet=rs
 phases:
 - description: Primary A is discovered
   responses:
   - - a:27017
     - ok: 1
-      ismaster: true
+      helloOk: true
+      isWritablePrimary: true
       hosts:
       - a:27017
       setName: rs
@@ -51,7 +52,8 @@ phases:
   responses:
   - - a:27017
     - ok: 1
-      ismaster: true
+      helloOk: true
+      isWritablePrimary: true
       hosts:
       - a:27017
       setName: rs
@@ -70,7 +72,7 @@ phases:
     logicalSessionTimeoutMinutes: null
     setName: rs
 
-- description: Ignore stale NotMasterNoSlaveOk error (stale generation)
+- description: Ignore stale timeout error (stale generation)
   applicationErrors:
   - address: a:27017
     generation: 0
diff --git a/test/spec/server-discovery-and-monitoring/errors/stale-generation.yml.template b/test/spec/server-discovery-and-monitoring/errors/stale-generation.yml.template
index cd933e840a..1519796575 100644
--- a/test/spec/server-discovery-and-monitoring/errors/stale-generation.yml.template
+++ b/test/spec/server-discovery-and-monitoring/errors/stale-generation.yml.template
@@ -6,7 +6,8 @@ phases:
   responses:
   - - a:27017
     - ok: 1
-      ismaster: true
+      helloOk: true
+      isWritablePrimary: true
       hosts:
       - a:27017
       setName: rs
@@ -51,7 +52,8 @@ phases:
   responses:
   - - a:27017
     - ok: 1
-      ismaster: true
+      helloOk: true
+      isWritablePrimary: true
       hosts:
       - a:27017
       setName: rs
diff --git a/test/spec/server-discovery-and-monitoring/errors/stale-topologyVersion-InterruptedAtShutdown.json b/test/spec/server-discovery-and-monitoring/errors/stale-topologyVersion-InterruptedAtShutdown.json
index 8449ac63b2..f2207a04d5 100644
--- a/test/spec/server-discovery-and-monitoring/errors/stale-topologyVersion-InterruptedAtShutdown.json
+++ b/test/spec/server-discovery-and-monitoring/errors/stale-topologyVersion-InterruptedAtShutdown.json
@@ -9,7 +9,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
diff --git a/test/spec/server-discovery-and-monitoring/errors/stale-topologyVersion-InterruptedAtShutdown.yml b/test/spec/server-discovery-and-monitoring/errors/stale-topologyVersion-InterruptedAtShutdown.yml
index 4ed7cfdb50..483c48044d 100644
--- a/test/spec/server-discovery-and-monitoring/errors/stale-topologyVersion-InterruptedAtShutdown.yml
+++ b/test/spec/server-discovery-and-monitoring/errors/stale-topologyVersion-InterruptedAtShutdown.yml
@@ -6,7 +6,8 @@ phases:
   responses:
   - - a:27017
     - ok: 1
-      ismaster: true
+      helloOk: true
+      isWritablePrimary: true
       hosts:
       - a:27017
       setName: rs
diff --git a/test/spec/server-discovery-and-monitoring/errors/stale-topologyVersion-InterruptedDueToReplStateChange.json b/test/spec/server-discovery-and-monitoring/errors/stale-topologyVersion-InterruptedDueToReplStateChange.json
index 0cdd1727d3..4387451ce6 100644
--- a/test/spec/server-discovery-and-monitoring/errors/stale-topologyVersion-InterruptedDueToReplStateChange.json
+++ b/test/spec/server-discovery-and-monitoring/errors/stale-topologyVersion-InterruptedDueToReplStateChange.json
@@ -9,7 +9,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
diff --git a/test/spec/server-discovery-and-monitoring/errors/stale-topologyVersion-InterruptedDueToReplStateChange.yml b/test/spec/server-discovery-and-monitoring/errors/stale-topologyVersion-InterruptedDueToReplStateChange.yml
index 287b1aa51b..5bed83e3da 100644
--- a/test/spec/server-discovery-and-monitoring/errors/stale-topologyVersion-InterruptedDueToReplStateChange.yml
+++ b/test/spec/server-discovery-and-monitoring/errors/stale-topologyVersion-InterruptedDueToReplStateChange.yml
@@ -6,7 +6,8 @@ phases:
   responses:
   - - a:27017
     - ok: 1
-      ismaster: true
+      helloOk: true
+      isWritablePrimary: true
       hosts:
       - a:27017
       setName: rs
diff --git a/test/spec/server-discovery-and-monitoring/errors/stale-topologyVersion-LegacyNotPrimary.json b/test/spec/server-discovery-and-monitoring/errors/stale-topologyVersion-LegacyNotPrimary.json
new file mode 100644
index 0000000000..8c0cf00f22
--- /dev/null
+++ b/test/spec/server-discovery-and-monitoring/errors/stale-topologyVersion-LegacyNotPrimary.json
@@ -0,0 +1,147 @@
+{
+  "description": "Stale topologyVersion LegacyNotPrimary error",
+  "uri": "mongodb://a/?replicaSet=rs",
+  "phases": [
+    {
+      "description": "Primary A is discovered",
+      "responses": [
+        [
+          "a:27017",
+          {
+            "ok": 1,
+            "helloOk": true,
+            "isWritablePrimary": true,
+            "hosts": [
+              "a:27017"
+            ],
+            "setName": "rs",
+            "minWireVersion": 0,
+            "maxWireVersion": 9,
+            "topologyVersion": {
+              "processId": {
+                "$oid": "000000000000000000000001"
+              },
+              "counter": {
+                "$numberLong": "1"
+              }
+            }
+          }
+        ]
+      ],
+      "outcome": {
+        "servers": {
+          "a:27017": {
+            "type": "RSPrimary",
+            "setName": "rs",
+            "topologyVersion": {
+              "processId": {
+                "$oid": "000000000000000000000001"
+              },
+              "counter": {
+                "$numberLong": "1"
+              }
+            },
+            "pool": {
+              "generation": 0
+            }
+          }
+        },
+        "topologyType": "ReplicaSetWithPrimary",
+        "logicalSessionTimeoutMinutes": null,
+        "setName": "rs"
+      }
+    },
+    {
+      "description": "Ignore stale LegacyNotPrimary error (topologyVersion less)",
+      "applicationErrors": [
+        {
+          "address": "a:27017",
+          "when": "afterHandshakeCompletes",
+          "maxWireVersion": 9,
+          "type": "command",
+          "response": {
+            "ok": 0,
+            "errmsg": "LegacyNotPrimary",
+            "code": 10058,
+            "topologyVersion": {
+              "processId": {
+                "$oid": "000000000000000000000001"
+              },
+              "counter": {
+                "$numberLong": "0"
+              }
+            }
+          }
+        }
+      ],
+      "outcome": {
+        "servers": {
+          "a:27017": {
+            "type": "RSPrimary",
+            "setName": "rs",
+            "topologyVersion": {
+              "processId": {
+                "$oid": "000000000000000000000001"
+              },
+              "counter": {
+                "$numberLong": "1"
+              }
+            },
+            "pool": {
+              "generation": 0
+            }
+          }
+        },
+        "topologyType": "ReplicaSetWithPrimary",
+        "logicalSessionTimeoutMinutes": null,
+        "setName": "rs"
+      }
+    },
+    {
+      "description": "Ignore stale LegacyNotPrimary error (topologyVersion equal)",
+      "applicationErrors": [
+        {
+          "address": "a:27017",
+          "when": "afterHandshakeCompletes",
+          "maxWireVersion": 9,
+          "type": "command",
+          "response": {
+            "ok": 0,
+            "errmsg": "LegacyNotPrimary",
+            "code": 10058,
+            "topologyVersion": {
+              "processId": {
+                "$oid": "000000000000000000000001"
+              },
+              "counter": {
+                "$numberLong": "1"
+              }
+            }
+          }
+        }
+      ],
+      "outcome": {
+        "servers": {
+          "a:27017": {
+            "type": "RSPrimary",
+            "setName": "rs",
+            "topologyVersion": {
+              "processId": {
+                "$oid": "000000000000000000000001"
+              },
+              "counter": {
+                "$numberLong": "1"
+              }
+            },
+            "pool": {
+              "generation": 0
+            }
+          }
+        },
+        "topologyType": "ReplicaSetWithPrimary",
+        "logicalSessionTimeoutMinutes": null,
+        "setName": "rs"
+      }
+    }
+  ]
+}
diff --git a/test/spec/server-discovery-and-monitoring/errors/stale-topologyVersion-LegacyNotPrimary.yml b/test/spec/server-discovery-and-monitoring/errors/stale-topologyVersion-LegacyNotPrimary.yml
new file mode 100644
index 0000000000..483087a238
--- /dev/null
+++ b/test/spec/server-discovery-and-monitoring/errors/stale-topologyVersion-LegacyNotPrimary.yml
@@ -0,0 +1,65 @@
+# Autogenerated tests for SDAM error handling, see generate-error-tests.py
+description: Stale topologyVersion LegacyNotPrimary error
+uri: mongodb://a/?replicaSet=rs
+phases:
+- description: Primary A is discovered
+  responses:
+  - - a:27017
+    - ok: 1
+      helloOk: true
+      isWritablePrimary: true
+      hosts:
+      - a:27017
+      setName: rs
+      minWireVersion: 0
+      maxWireVersion: 9
+      topologyVersion: &topologyVersion_1_1
+        processId:
+          "$oid": '000000000000000000000001'
+        counter:
+          "$numberLong": '1'
+  outcome: &outcome
+    servers:
+      a:27017:
+        type: RSPrimary
+        setName: rs
+        topologyVersion: *topologyVersion_1_1
+        pool:
+          generation: 0
+    topologyType: ReplicaSetWithPrimary
+    logicalSessionTimeoutMinutes: null
+    setName: rs
+
+- description: Ignore stale LegacyNotPrimary error (topologyVersion less)
+  applicationErrors:
+  - address: a:27017
+    when: afterHandshakeCompletes
+    maxWireVersion: 9
+    type: command
+    response:
+      ok: 0
+      errmsg: LegacyNotPrimary
+      code: 10058
+      topologyVersion:
+        processId:
+          "$oid": '000000000000000000000001'
+        counter:
+          "$numberLong": '0'
+  outcome: *outcome
+
+- description: Ignore stale LegacyNotPrimary error (topologyVersion equal)
+  applicationErrors:
+  - address: a:27017
+    when: afterHandshakeCompletes
+    maxWireVersion: 9
+    type: command
+    response:
+      ok: 0
+      errmsg: LegacyNotPrimary
+      code: 10058
+      topologyVersion:
+        processId:
+          "$oid": '000000000000000000000001'
+        counter:
+          "$numberLong": '1'
+  outcome: *outcome
diff --git a/test/spec/server-discovery-and-monitoring/errors/stale-topologyVersion-NotMasterNoSlaveOk.json b/test/spec/server-discovery-and-monitoring/errors/stale-topologyVersion-NotPrimaryNoSecondaryOk.json
similarity index 88%
rename from test/spec/server-discovery-and-monitoring/errors/stale-topologyVersion-NotMasterNoSlaveOk.json
rename to test/spec/server-discovery-and-monitoring/errors/stale-topologyVersion-NotPrimaryNoSecondaryOk.json
index e894dae6d8..99a828326c 100644
--- a/test/spec/server-discovery-and-monitoring/errors/stale-topologyVersion-NotMasterNoSlaveOk.json
+++ b/test/spec/server-discovery-and-monitoring/errors/stale-topologyVersion-NotPrimaryNoSecondaryOk.json
@@ -1,5 +1,5 @@
 {
-  "description": "Stale topologyVersion NotMasterNoSlaveOk error",
+  "description": "Stale topologyVersion NotPrimaryNoSecondaryOk error",
   "uri": "mongodb://a/?replicaSet=rs",
   "phases": [
     {
@@ -9,7 +9,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
@@ -51,7 +52,7 @@
       }
     },
     {
-      "description": "Ignore stale NotMasterNoSlaveOk error (topologyVersion less)",
+      "description": "Ignore stale NotPrimaryNoSecondaryOk error (topologyVersion less)",
       "applicationErrors": [
         {
           "address": "a:27017",
@@ -60,7 +61,7 @@
           "type": "command",
           "response": {
             "ok": 0,
-            "errmsg": "NotMasterNoSlaveOk",
+            "errmsg": "NotPrimaryNoSecondaryOk",
             "code": 13435,
             "topologyVersion": {
               "processId": {
@@ -97,7 +98,7 @@
       }
     },
     {
-      "description": "Ignore stale NotMasterNoSlaveOk error (topologyVersion equal)",
+      "description": "Ignore stale NotPrimaryNoSecondaryOk error (topologyVersion equal)",
       "applicationErrors": [
         {
           "address": "a:27017",
@@ -106,7 +107,7 @@
           "type": "command",
           "response": {
             "ok": 0,
-            "errmsg": "NotMasterNoSlaveOk",
+            "errmsg": "NotPrimaryNoSecondaryOk",
             "code": 13435,
             "topologyVersion": {
               "processId": {
diff --git a/test/spec/server-discovery-and-monitoring/errors/stale-topologyVersion-NotMasterNoSlaveOk.yml b/test/spec/server-discovery-and-monitoring/errors/stale-topologyVersion-NotPrimaryNoSecondaryOk.yml
similarity index 79%
rename from test/spec/server-discovery-and-monitoring/errors/stale-topologyVersion-NotMasterNoSlaveOk.yml
rename to test/spec/server-discovery-and-monitoring/errors/stale-topologyVersion-NotPrimaryNoSecondaryOk.yml
index 6bc1c91303..823bf3ee8e 100644
--- a/test/spec/server-discovery-and-monitoring/errors/stale-topologyVersion-NotMasterNoSlaveOk.yml
+++ b/test/spec/server-discovery-and-monitoring/errors/stale-topologyVersion-NotPrimaryNoSecondaryOk.yml
@@ -1,12 +1,13 @@
 # Autogenerated tests for SDAM error handling, see generate-error-tests.py
-description: Stale topologyVersion NotMasterNoSlaveOk error
+description: Stale topologyVersion NotPrimaryNoSecondaryOk error
 uri: mongodb://a/?replicaSet=rs
 phases:
 - description: Primary A is discovered
   responses:
   - - a:27017
     - ok: 1
-      ismaster: true
+      helloOk: true
+      isWritablePrimary: true
       hosts:
       - a:27017
       setName: rs
@@ -29,7 +30,7 @@ phases:
     logicalSessionTimeoutMinutes: null
     setName: rs
 
-- description: Ignore stale NotMasterNoSlaveOk error (topologyVersion less)
+- description: Ignore stale NotPrimaryNoSecondaryOk error (topologyVersion less)
   applicationErrors:
   - address: a:27017
     when: afterHandshakeCompletes
@@ -37,7 +38,7 @@ phases:
     type: command
     response:
       ok: 0
-      errmsg: NotMasterNoSlaveOk
+      errmsg: NotPrimaryNoSecondaryOk
       code: 13435
       topologyVersion:
         processId:
@@ -46,7 +47,7 @@ phases:
           "$numberLong": '0'
   outcome: *outcome
 
-- description: Ignore stale NotMasterNoSlaveOk error (topologyVersion equal)
+- description: Ignore stale NotPrimaryNoSecondaryOk error (topologyVersion equal)
   applicationErrors:
   - address: a:27017
     when: afterHandshakeCompletes
@@ -54,7 +55,7 @@ phases:
     type: command
     response:
       ok: 0
-      errmsg: NotMasterNoSlaveOk
+      errmsg: NotPrimaryNoSecondaryOk
       code: 13435
       topologyVersion:
         processId:
diff --git a/test/spec/server-discovery-and-monitoring/errors/stale-topologyVersion-NotMasterOrSecondary.json b/test/spec/server-discovery-and-monitoring/errors/stale-topologyVersion-NotPrimaryOrSecondary.json
similarity index 89%
rename from test/spec/server-discovery-and-monitoring/errors/stale-topologyVersion-NotMasterOrSecondary.json
rename to test/spec/server-discovery-and-monitoring/errors/stale-topologyVersion-NotPrimaryOrSecondary.json
index 17243c9022..ba2ea87106 100644
--- a/test/spec/server-discovery-and-monitoring/errors/stale-topologyVersion-NotMasterOrSecondary.json
+++ b/test/spec/server-discovery-and-monitoring/errors/stale-topologyVersion-NotPrimaryOrSecondary.json
@@ -1,5 +1,5 @@
 {
-  "description": "Stale topologyVersion NotMasterOrSecondary error",
+  "description": "Stale topologyVersion NotPrimaryOrSecondary error",
   "uri": "mongodb://a/?replicaSet=rs",
   "phases": [
     {
@@ -9,7 +9,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
@@ -51,7 +52,7 @@
       }
     },
     {
-      "description": "Ignore stale NotMasterOrSecondary error (topologyVersion less)",
+      "description": "Ignore stale NotPrimaryOrSecondary error (topologyVersion less)",
       "applicationErrors": [
         {
           "address": "a:27017",
@@ -60,7 +61,7 @@
           "type": "command",
           "response": {
             "ok": 0,
-            "errmsg": "NotMasterOrSecondary",
+            "errmsg": "NotPrimaryOrSecondary",
             "code": 13436,
             "topologyVersion": {
               "processId": {
@@ -97,7 +98,7 @@
       }
     },
     {
-      "description": "Ignore stale NotMasterOrSecondary error (topologyVersion equal)",
+      "description": "Ignore stale NotPrimaryOrSecondary error (topologyVersion equal)",
       "applicationErrors": [
         {
           "address": "a:27017",
@@ -106,7 +107,7 @@
           "type": "command",
           "response": {
             "ok": 0,
-            "errmsg": "NotMasterOrSecondary",
+            "errmsg": "NotPrimaryOrSecondary",
             "code": 13436,
             "topologyVersion": {
               "processId": {
diff --git a/test/spec/server-discovery-and-monitoring/errors/stale-topologyVersion-NotMasterOrSecondary.yml b/test/spec/server-discovery-and-monitoring/errors/stale-topologyVersion-NotPrimaryOrSecondary.yml
similarity index 79%
rename from test/spec/server-discovery-and-monitoring/errors/stale-topologyVersion-NotMasterOrSecondary.yml
rename to test/spec/server-discovery-and-monitoring/errors/stale-topologyVersion-NotPrimaryOrSecondary.yml
index 2754014bd2..acee1ec566 100644
--- a/test/spec/server-discovery-and-monitoring/errors/stale-topologyVersion-NotMasterOrSecondary.yml
+++ b/test/spec/server-discovery-and-monitoring/errors/stale-topologyVersion-NotPrimaryOrSecondary.yml
@@ -1,12 +1,13 @@
 # Autogenerated tests for SDAM error handling, see generate-error-tests.py
-description: Stale topologyVersion NotMasterOrSecondary error
+description: Stale topologyVersion NotPrimaryOrSecondary error
 uri: mongodb://a/?replicaSet=rs
 phases:
 - description: Primary A is discovered
   responses:
   - - a:27017
     - ok: 1
-      ismaster: true
+      helloOk: true
+      isWritablePrimary: true
       hosts:
       - a:27017
       setName: rs
@@ -29,7 +30,7 @@ phases:
     logicalSessionTimeoutMinutes: null
     setName: rs
 
-- description: Ignore stale NotMasterOrSecondary error (topologyVersion less)
+- description: Ignore stale NotPrimaryOrSecondary error (topologyVersion less)
   applicationErrors:
   - address: a:27017
     when: afterHandshakeCompletes
@@ -37,7 +38,7 @@ phases:
     type: command
     response:
       ok: 0
-      errmsg: NotMasterOrSecondary
+      errmsg: NotPrimaryOrSecondary
       code: 13436
       topologyVersion:
         processId:
@@ -46,7 +47,7 @@ phases:
           "$numberLong": '0'
   outcome: *outcome
 
-- description: Ignore stale NotMasterOrSecondary error (topologyVersion equal)
+- description: Ignore stale NotPrimaryOrSecondary error (topologyVersion equal)
   applicationErrors:
   - address: a:27017
     when: afterHandshakeCompletes
@@ -54,7 +55,7 @@ phases:
     type: command
     response:
       ok: 0
-      errmsg: NotMasterOrSecondary
+      errmsg: NotPrimaryOrSecondary
       code: 13436
       topologyVersion:
         processId:
diff --git a/test/spec/server-discovery-and-monitoring/errors/stale-topologyVersion-NotMaster.json b/test/spec/server-discovery-and-monitoring/errors/stale-topologyVersion-NotWritablePrimary.json
similarity index 89%
rename from test/spec/server-discovery-and-monitoring/errors/stale-topologyVersion-NotMaster.json
rename to test/spec/server-discovery-and-monitoring/errors/stale-topologyVersion-NotWritablePrimary.json
index 5823d0446f..8edd317a73 100644
--- a/test/spec/server-discovery-and-monitoring/errors/stale-topologyVersion-NotMaster.json
+++ b/test/spec/server-discovery-and-monitoring/errors/stale-topologyVersion-NotWritablePrimary.json
@@ -1,5 +1,5 @@
 {
-  "description": "Stale topologyVersion NotMaster error",
+  "description": "Stale topologyVersion NotWritablePrimary error",
   "uri": "mongodb://a/?replicaSet=rs",
   "phases": [
     {
@@ -9,7 +9,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
@@ -51,7 +52,7 @@
       }
     },
     {
-      "description": "Ignore stale NotMaster error (topologyVersion less)",
+      "description": "Ignore stale NotWritablePrimary error (topologyVersion less)",
       "applicationErrors": [
         {
           "address": "a:27017",
@@ -60,7 +61,7 @@
           "type": "command",
           "response": {
             "ok": 0,
-            "errmsg": "NotMaster",
+            "errmsg": "NotWritablePrimary",
             "code": 10107,
             "topologyVersion": {
               "processId": {
@@ -97,7 +98,7 @@
       }
     },
     {
-      "description": "Ignore stale NotMaster error (topologyVersion equal)",
+      "description": "Ignore stale NotWritablePrimary error (topologyVersion equal)",
       "applicationErrors": [
         {
           "address": "a:27017",
@@ -106,7 +107,7 @@
           "type": "command",
           "response": {
             "ok": 0,
-            "errmsg": "NotMaster",
+            "errmsg": "NotWritablePrimary",
             "code": 10107,
             "topologyVersion": {
               "processId": {
diff --git a/test/spec/server-discovery-and-monitoring/errors/stale-topologyVersion-NotMaster.yml b/test/spec/server-discovery-and-monitoring/errors/stale-topologyVersion-NotWritablePrimary.yml
similarity index 80%
rename from test/spec/server-discovery-and-monitoring/errors/stale-topologyVersion-NotMaster.yml
rename to test/spec/server-discovery-and-monitoring/errors/stale-topologyVersion-NotWritablePrimary.yml
index 82cd97c4ee..8e126b0cb0 100644
--- a/test/spec/server-discovery-and-monitoring/errors/stale-topologyVersion-NotMaster.yml
+++ b/test/spec/server-discovery-and-monitoring/errors/stale-topologyVersion-NotWritablePrimary.yml
@@ -1,12 +1,13 @@
 # Autogenerated tests for SDAM error handling, see generate-error-tests.py
-description: Stale topologyVersion NotMaster error
+description: Stale topologyVersion NotWritablePrimary error
 uri: mongodb://a/?replicaSet=rs
 phases:
 - description: Primary A is discovered
   responses:
   - - a:27017
     - ok: 1
-      ismaster: true
+      helloOk: true
+      isWritablePrimary: true
       hosts:
       - a:27017
       setName: rs
@@ -29,7 +30,7 @@ phases:
     logicalSessionTimeoutMinutes: null
     setName: rs
 
-- description: Ignore stale NotMaster error (topologyVersion less)
+- description: Ignore stale NotWritablePrimary error (topologyVersion less)
   applicationErrors:
   - address: a:27017
     when: afterHandshakeCompletes
@@ -37,7 +38,7 @@ phases:
     type: command
     response:
       ok: 0
-      errmsg: NotMaster
+      errmsg: NotWritablePrimary
       code: 10107
       topologyVersion:
         processId:
@@ -46,7 +47,7 @@ phases:
           "$numberLong": '0'
   outcome: *outcome
 
-- description: Ignore stale NotMaster error (topologyVersion equal)
+- description: Ignore stale NotWritablePrimary error (topologyVersion equal)
   applicationErrors:
   - address: a:27017
     when: afterHandshakeCompletes
@@ -54,7 +55,7 @@ phases:
     type: command
     response:
       ok: 0
-      errmsg: NotMaster
+      errmsg: NotWritablePrimary
       code: 10107
       topologyVersion:
         processId:
diff --git a/test/spec/server-discovery-and-monitoring/errors/stale-topologyVersion-PrimarySteppedDown.json b/test/spec/server-discovery-and-monitoring/errors/stale-topologyVersion-PrimarySteppedDown.json
index 93d9678419..da8e4755eb 100644
--- a/test/spec/server-discovery-and-monitoring/errors/stale-topologyVersion-PrimarySteppedDown.json
+++ b/test/spec/server-discovery-and-monitoring/errors/stale-topologyVersion-PrimarySteppedDown.json
@@ -9,7 +9,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
diff --git a/test/spec/server-discovery-and-monitoring/errors/stale-topologyVersion-PrimarySteppedDown.yml b/test/spec/server-discovery-and-monitoring/errors/stale-topologyVersion-PrimarySteppedDown.yml
index 011eb500b8..c5e8a403b1 100644
--- a/test/spec/server-discovery-and-monitoring/errors/stale-topologyVersion-PrimarySteppedDown.yml
+++ b/test/spec/server-discovery-and-monitoring/errors/stale-topologyVersion-PrimarySteppedDown.yml
@@ -6,7 +6,8 @@ phases:
   responses:
   - - a:27017
     - ok: 1
-      ismaster: true
+      helloOk: true
+      isWritablePrimary: true
       hosts:
       - a:27017
       setName: rs
diff --git a/test/spec/server-discovery-and-monitoring/errors/stale-topologyVersion-ShutdownInProgress.json b/test/spec/server-discovery-and-monitoring/errors/stale-topologyVersion-ShutdownInProgress.json
index 563eb60d9f..aa252e1dc4 100644
--- a/test/spec/server-discovery-and-monitoring/errors/stale-topologyVersion-ShutdownInProgress.json
+++ b/test/spec/server-discovery-and-monitoring/errors/stale-topologyVersion-ShutdownInProgress.json
@@ -9,7 +9,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
diff --git a/test/spec/server-discovery-and-monitoring/errors/stale-topologyVersion-ShutdownInProgress.yml b/test/spec/server-discovery-and-monitoring/errors/stale-topologyVersion-ShutdownInProgress.yml
index 494384da13..6ad7677cf0 100644
--- a/test/spec/server-discovery-and-monitoring/errors/stale-topologyVersion-ShutdownInProgress.yml
+++ b/test/spec/server-discovery-and-monitoring/errors/stale-topologyVersion-ShutdownInProgress.yml
@@ -6,7 +6,8 @@ phases:
   responses:
   - - a:27017
     - ok: 1
-      ismaster: true
+      helloOk: true
+      isWritablePrimary: true
       hosts:
       - a:27017
       setName: rs
diff --git a/test/spec/server-discovery-and-monitoring/errors/stale-topologyVersion.yml.template b/test/spec/server-discovery-and-monitoring/errors/stale-topologyVersion.yml.template
index 40f5ad7774..f69d440da0 100644
--- a/test/spec/server-discovery-and-monitoring/errors/stale-topologyVersion.yml.template
+++ b/test/spec/server-discovery-and-monitoring/errors/stale-topologyVersion.yml.template
@@ -6,7 +6,8 @@ phases:
   responses:
   - - a:27017
     - ok: 1
-      ismaster: true
+      helloOk: true
+      isWritablePrimary: true
       hosts:
       - a:27017
       setName: rs
diff --git a/test/spec/server-discovery-and-monitoring/errors/write_errors_ignored.json b/test/spec/server-discovery-and-monitoring/errors/write_errors_ignored.json
index 6b80673c12..b588807e08 100644
--- a/test/spec/server-discovery-and-monitoring/errors/write_errors_ignored.json
+++ b/test/spec/server-discovery-and-monitoring/errors/write_errors_ignored.json
@@ -9,7 +9,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
@@ -62,8 +63,9 @@
             "ok": 1,
             "writeErrors": [
               {
-                "errmsg": "NotMasterNoSlaveOk",
-                "code": 13435
+                "errmsg": "NotPrimaryNoSecondaryOk",
+                "code": 13435,
+                "index": 0
               }
             ]
           }
diff --git a/test/spec/server-discovery-and-monitoring/errors/write_errors_ignored.yml b/test/spec/server-discovery-and-monitoring/errors/write_errors_ignored.yml
index e5eaf09651..85f59d97d4 100644
--- a/test/spec/server-discovery-and-monitoring/errors/write_errors_ignored.yml
+++ b/test/spec/server-discovery-and-monitoring/errors/write_errors_ignored.yml
@@ -5,7 +5,8 @@ phases:
   responses:
   - - a:27017
     - ok: 1
-      ismaster: true
+      helloOk: true
+      isWritablePrimary: true
       hosts:
       - a:27017
       setName: rs
@@ -37,5 +38,5 @@ phases:
     response:
       ok: 1
       writeErrors:
-      - { errmsg: NotMasterNoSlaveOk, code: 13435 }
+      - { errmsg: NotPrimaryNoSecondaryOk, code: 13435, index: 0 }
   outcome: *outcome
diff --git a/test/spec/server-discovery-and-monitoring/integration/auth-error.json b/test/spec/server-discovery-and-monitoring/integration/auth-error.json
new file mode 100644
index 0000000000..064d660e32
--- /dev/null
+++ b/test/spec/server-discovery-and-monitoring/integration/auth-error.json
@@ -0,0 +1,140 @@
+{
+  "runOn": [
+    {
+      "minServerVersion": "4.4",
+      "authEnabled": true
+    }
+  ],
+  "database_name": "sdam-tests",
+  "collection_name": "auth-error",
+  "data": [
+    {
+      "_id": 1
+    },
+    {
+      "_id": 2
+    }
+  ],
+  "tests": [
+    {
+      "description": "Reset server and pool after AuthenticationFailure error",
+      "failPoint": {
+        "configureFailPoint": "failCommand",
+        "mode": {
+          "times": 1
+        },
+        "data": {
+          "failCommands": [
+            "saslContinue"
+          ],
+          "appName": "authErrorTest",
+          "errorCode": 18
+        }
+      },
+      "clientOptions": {
+        "retryWrites": false,
+        "appname": "authErrorTest"
+      },
+      "operations": [
+        {
+          "name": "insertMany",
+          "object": "collection",
+          "arguments": {
+            "documents": [
+              {
+                "_id": 3
+              },
+              {
+                "_id": 4
+              }
+            ]
+          },
+          "error": true
+        },
+        {
+          "name": "waitForEvent",
+          "object": "testRunner",
+          "arguments": {
+            "event": "ServerMarkedUnknownEvent",
+            "count": 1
+          }
+        },
+        {
+          "name": "waitForEvent",
+          "object": "testRunner",
+          "arguments": {
+            "event": "PoolClearedEvent",
+            "count": 1
+          }
+        },
+        {
+          "name": "insertMany",
+          "object": "collection",
+          "arguments": {
+            "documents": [
+              {
+                "_id": 5
+              },
+              {
+                "_id": 6
+              }
+            ]
+          }
+        },
+        {
+          "name": "assertEventCount",
+          "object": "testRunner",
+          "arguments": {
+            "event": "ServerMarkedUnknownEvent",
+            "count": 1
+          }
+        },
+        {
+          "name": "assertEventCount",
+          "object": "testRunner",
+          "arguments": {
+            "event": "PoolClearedEvent",
+            "count": 1
+          }
+        }
+      ],
+      "expectations": [
+        {
+          "command_started_event": {
+            "command": {
+              "insert": "auth-error",
+              "documents": [
+                {
+                  "_id": 5
+                },
+                {
+                  "_id": 6
+                }
+              ]
+            },
+            "command_name": "insert",
+            "database_name": "sdam-tests"
+          }
+        }
+      ],
+      "outcome": {
+        "collection": {
+          "data": [
+            {
+              "_id": 1
+            },
+            {
+              "_id": 2
+            },
+            {
+              "_id": 5
+            },
+            {
+              "_id": 6
+            }
+          ]
+        }
+      }
+    }
+  ]
+}
diff --git a/test/spec/server-discovery-and-monitoring/integration/auth-error.yml b/test/spec/server-discovery-and-monitoring/integration/auth-error.yml
new file mode 100644
index 0000000000..9c646543e0
--- /dev/null
+++ b/test/spec/server-discovery-and-monitoring/integration/auth-error.yml
@@ -0,0 +1,81 @@
+# Test SDAM error handling.
+runOn:
+    # failCommand appName requirements
+    - minServerVersion: "4.4"
+      authEnabled: true
+
+database_name: &database_name "sdam-tests"
+collection_name: &collection_name "auth-error"
+
+data: &data
+  - {_id: 1}
+  - {_id: 2}
+
+tests:
+  - description: Reset server and pool after AuthenticationFailure error
+    failPoint:
+      configureFailPoint: failCommand
+      mode: { times: 1 }
+      data:
+          failCommands: ["saslContinue"]
+          appName: authErrorTest
+          errorCode: 18  # AuthenticationFailure
+    clientOptions:
+      retryWrites: false
+      appname: authErrorTest
+    operations:
+      - name: insertMany
+        object: collection
+        arguments:
+          documents:
+            - _id: 3
+            - _id: 4
+        error: true
+      - name: waitForEvent
+        object: testRunner
+        arguments:
+          event: ServerMarkedUnknownEvent
+          count: 1
+      - name: waitForEvent
+        object: testRunner
+        arguments:
+          event: PoolClearedEvent
+          count: 1
+      # Perform another operation to ensure the node is rediscovered.
+      - name: insertMany
+        object: collection
+        arguments:
+          documents:
+            - _id: 5
+            - _id: 6
+      # Assert the server was marked Unknown and pool was cleared exactly once.
+      - name: assertEventCount
+        object: testRunner
+        arguments:
+          event: ServerMarkedUnknownEvent
+          count: 1
+      - name: assertEventCount
+        object: testRunner
+        arguments:
+          event: PoolClearedEvent
+          count: 1
+
+    expectations:
+      # Note: The first insert command is never attempted because connection
+      # checkout fails.
+      - command_started_event:
+          command:
+            insert: *collection_name
+            documents:
+              - _id: 5
+              - _id: 6
+          command_name: insert
+          database_name: *database_name
+
+    outcome:
+      collection:
+        data:
+          - {_id: 1}
+          - {_id: 2}
+          - {_id: 5}
+          - {_id: 6}
diff --git a/test/spec/server-discovery-and-monitoring/integration/auth-misc-command-error.json b/test/spec/server-discovery-and-monitoring/integration/auth-misc-command-error.json
new file mode 100644
index 0000000000..70dd59251d
--- /dev/null
+++ b/test/spec/server-discovery-and-monitoring/integration/auth-misc-command-error.json
@@ -0,0 +1,140 @@
+{
+  "runOn": [
+    {
+      "minServerVersion": "4.4",
+      "authEnabled": true
+    }
+  ],
+  "database_name": "sdam-tests",
+  "collection_name": "auth-misc-error",
+  "data": [
+    {
+      "_id": 1
+    },
+    {
+      "_id": 2
+    }
+  ],
+  "tests": [
+    {
+      "description": "Reset server and pool after misc command error",
+      "failPoint": {
+        "configureFailPoint": "failCommand",
+        "mode": {
+          "times": 1
+        },
+        "data": {
+          "failCommands": [
+            "saslContinue"
+          ],
+          "appName": "authMiscErrorTest",
+          "errorCode": 1
+        }
+      },
+      "clientOptions": {
+        "retryWrites": false,
+        "appname": "authMiscErrorTest"
+      },
+      "operations": [
+        {
+          "name": "insertMany",
+          "object": "collection",
+          "arguments": {
+            "documents": [
+              {
+                "_id": 3
+              },
+              {
+                "_id": 4
+              }
+            ]
+          },
+          "error": true
+        },
+        {
+          "name": "waitForEvent",
+          "object": "testRunner",
+          "arguments": {
+            "event": "ServerMarkedUnknownEvent",
+            "count": 1
+          }
+        },
+        {
+          "name": "waitForEvent",
+          "object": "testRunner",
+          "arguments": {
+            "event": "PoolClearedEvent",
+            "count": 1
+          }
+        },
+        {
+          "name": "insertMany",
+          "object": "collection",
+          "arguments": {
+            "documents": [
+              {
+                "_id": 5
+              },
+              {
+                "_id": 6
+              }
+            ]
+          }
+        },
+        {
+          "name": "assertEventCount",
+          "object": "testRunner",
+          "arguments": {
+            "event": "ServerMarkedUnknownEvent",
+            "count": 1
+          }
+        },
+        {
+          "name": "assertEventCount",
+          "object": "testRunner",
+          "arguments": {
+            "event": "PoolClearedEvent",
+            "count": 1
+          }
+        }
+      ],
+      "expectations": [
+        {
+          "command_started_event": {
+            "command": {
+              "insert": "auth-misc-error",
+              "documents": [
+                {
+                  "_id": 5
+                },
+                {
+                  "_id": 6
+                }
+              ]
+            },
+            "command_name": "insert",
+            "database_name": "sdam-tests"
+          }
+        }
+      ],
+      "outcome": {
+        "collection": {
+          "data": [
+            {
+              "_id": 1
+            },
+            {
+              "_id": 2
+            },
+            {
+              "_id": 5
+            },
+            {
+              "_id": 6
+            }
+          ]
+        }
+      }
+    }
+  ]
+}
diff --git a/test/spec/server-discovery-and-monitoring/integration/auth-misc-command-error.yml b/test/spec/server-discovery-and-monitoring/integration/auth-misc-command-error.yml
new file mode 100644
index 0000000000..20eae4533e
--- /dev/null
+++ b/test/spec/server-discovery-and-monitoring/integration/auth-misc-command-error.yml
@@ -0,0 +1,81 @@
+# Test SDAM error handling.
+runOn:
+    # failCommand appName requirements
+    - minServerVersion: "4.4"
+      authEnabled: true
+
+database_name: &database_name "sdam-tests"
+collection_name: &collection_name "auth-misc-error"
+
+data: &data
+  - {_id: 1}
+  - {_id: 2}
+
+tests:
+  - description: Reset server and pool after misc command error
+    failPoint:
+      configureFailPoint: failCommand
+      mode: { times: 1 }
+      data:
+          failCommands: ["saslContinue"]
+          appName: authMiscErrorTest
+          errorCode: 1  # InternalError
+    clientOptions:
+      retryWrites: false
+      appname: authMiscErrorTest
+    operations:
+      - name: insertMany
+        object: collection
+        arguments:
+          documents:
+            - _id: 3
+            - _id: 4
+        error: true
+      - name: waitForEvent
+        object: testRunner
+        arguments:
+          event: ServerMarkedUnknownEvent
+          count: 1
+      - name: waitForEvent
+        object: testRunner
+        arguments:
+          event: PoolClearedEvent
+          count: 1
+      # Perform another operation to ensure the node is rediscovered.
+      - name: insertMany
+        object: collection
+        arguments:
+          documents:
+            - _id: 5
+            - _id: 6
+      # Assert the server was marked Unknown and pool was cleared exactly once.
+      - name: assertEventCount
+        object: testRunner
+        arguments:
+          event: ServerMarkedUnknownEvent
+          count: 1
+      - name: assertEventCount
+        object: testRunner
+        arguments:
+          event: PoolClearedEvent
+          count: 1
+
+    expectations:
+      # Note: The first insert command is never attempted because connection
+      # checkout fails.
+      - command_started_event:
+          command:
+            insert: *collection_name
+            documents:
+              - _id: 5
+              - _id: 6
+          command_name: insert
+          database_name: *database_name
+
+    outcome:
+      collection:
+        data:
+          - {_id: 1}
+          - {_id: 2}
+          - {_id: 5}
+          - {_id: 6}
diff --git a/test/spec/server-discovery-and-monitoring/integration/auth-network-error.json b/test/spec/server-discovery-and-monitoring/integration/auth-network-error.json
new file mode 100644
index 0000000000..a75a398c5e
--- /dev/null
+++ b/test/spec/server-discovery-and-monitoring/integration/auth-network-error.json
@@ -0,0 +1,140 @@
+{
+  "runOn": [
+    {
+      "minServerVersion": "4.4",
+      "authEnabled": true
+    }
+  ],
+  "database_name": "sdam-tests",
+  "collection_name": "auth-network-error",
+  "data": [
+    {
+      "_id": 1
+    },
+    {
+      "_id": 2
+    }
+  ],
+  "tests": [
+    {
+      "description": "Reset server and pool after network error during authentication",
+      "failPoint": {
+        "configureFailPoint": "failCommand",
+        "mode": {
+          "times": 1
+        },
+        "data": {
+          "failCommands": [
+            "saslContinue"
+          ],
+          "closeConnection": true,
+          "appName": "authNetworkErrorTest"
+        }
+      },
+      "clientOptions": {
+        "retryWrites": false,
+        "appname": "authNetworkErrorTest"
+      },
+      "operations": [
+        {
+          "name": "insertMany",
+          "object": "collection",
+          "arguments": {
+            "documents": [
+              {
+                "_id": 3
+              },
+              {
+                "_id": 4
+              }
+            ]
+          },
+          "error": true
+        },
+        {
+          "name": "waitForEvent",
+          "object": "testRunner",
+          "arguments": {
+            "event": "ServerMarkedUnknownEvent",
+            "count": 1
+          }
+        },
+        {
+          "name": "waitForEvent",
+          "object": "testRunner",
+          "arguments": {
+            "event": "PoolClearedEvent",
+            "count": 1
+          }
+        },
+        {
+          "name": "insertMany",
+          "object": "collection",
+          "arguments": {
+            "documents": [
+              {
+                "_id": 5
+              },
+              {
+                "_id": 6
+              }
+            ]
+          }
+        },
+        {
+          "name": "assertEventCount",
+          "object": "testRunner",
+          "arguments": {
+            "event": "ServerMarkedUnknownEvent",
+            "count": 1
+          }
+        },
+        {
+          "name": "assertEventCount",
+          "object": "testRunner",
+          "arguments": {
+            "event": "PoolClearedEvent",
+            "count": 1
+          }
+        }
+      ],
+      "expectations": [
+        {
+          "command_started_event": {
+            "command": {
+              "insert": "auth-network-error",
+              "documents": [
+                {
+                  "_id": 5
+                },
+                {
+                  "_id": 6
+                }
+              ]
+            },
+            "command_name": "insert",
+            "database_name": "sdam-tests"
+          }
+        }
+      ],
+      "outcome": {
+        "collection": {
+          "data": [
+            {
+              "_id": 1
+            },
+            {
+              "_id": 2
+            },
+            {
+              "_id": 5
+            },
+            {
+              "_id": 6
+            }
+          ]
+        }
+      }
+    }
+  ]
+}
diff --git a/test/spec/server-discovery-and-monitoring/integration/auth-network-error.yml b/test/spec/server-discovery-and-monitoring/integration/auth-network-error.yml
new file mode 100644
index 0000000000..abb2b1471e
--- /dev/null
+++ b/test/spec/server-discovery-and-monitoring/integration/auth-network-error.yml
@@ -0,0 +1,81 @@
+# Test SDAM error handling.
+runOn:
+    # failCommand appName requirements
+    - minServerVersion: "4.4"
+      authEnabled: true
+
+database_name: &database_name "sdam-tests"
+collection_name: &collection_name "auth-network-error"
+
+data: &data
+  - {_id: 1}
+  - {_id: 2}
+
+tests:
+  - description: Reset server and pool after network error during authentication
+    failPoint:
+      configureFailPoint: failCommand
+      mode: { times: 1 }
+      data:
+          failCommands: ["saslContinue"]
+          closeConnection: true
+          appName: authNetworkErrorTest
+    clientOptions:
+      retryWrites: false
+      appname: authNetworkErrorTest
+    operations:
+      - name: insertMany
+        object: collection
+        arguments:
+          documents:
+            - _id: 3
+            - _id: 4
+        error: true
+      - name: waitForEvent
+        object: testRunner
+        arguments:
+          event: ServerMarkedUnknownEvent
+          count: 1
+      - name: waitForEvent
+        object: testRunner
+        arguments:
+          event: PoolClearedEvent
+          count: 1
+      # Perform another operation to ensure the node is rediscovered.
+      - name: insertMany
+        object: collection
+        arguments:
+          documents:
+            - _id: 5
+            - _id: 6
+      # Assert the server was marked Unknown and pool was cleared exactly once.
+      - name: assertEventCount
+        object: testRunner
+        arguments:
+          event: ServerMarkedUnknownEvent
+          count: 1
+      - name: assertEventCount
+        object: testRunner
+        arguments:
+          event: PoolClearedEvent
+          count: 1
+
+    expectations:
+      # Note: The first insert command is never attempted because connection
+      # checkout fails.
+      - command_started_event:
+          command:
+            insert: *collection_name
+            documents:
+              - _id: 5
+              - _id: 6
+          command_name: insert
+          database_name: *database_name
+
+    outcome:
+      collection:
+        data:
+          - {_id: 1}
+          - {_id: 2}
+          - {_id: 5}
+          - {_id: 6}
diff --git a/test/spec/server-discovery-and-monitoring/integration/auth-network-timeout-error.json b/test/spec/server-discovery-and-monitoring/integration/auth-network-timeout-error.json
new file mode 100644
index 0000000000..a4ee7d9eff
--- /dev/null
+++ b/test/spec/server-discovery-and-monitoring/integration/auth-network-timeout-error.json
@@ -0,0 +1,143 @@
+{
+  "runOn": [
+    {
+      "minServerVersion": "4.4",
+      "authEnabled": true
+    }
+  ],
+  "database_name": "sdam-tests",
+  "collection_name": "auth-network-timeout-error",
+  "data": [
+    {
+      "_id": 1
+    },
+    {
+      "_id": 2
+    }
+  ],
+  "tests": [
+    {
+      "description": "Reset server and pool after network timeout error during authentication",
+      "failPoint": {
+        "configureFailPoint": "failCommand",
+        "mode": {
+          "times": 1
+        },
+        "data": {
+          "failCommands": [
+            "saslContinue"
+          ],
+          "blockConnection": true,
+          "blockTimeMS": 500,
+          "appName": "authNetworkTimeoutErrorTest"
+        }
+      },
+      "clientOptions": {
+        "retryWrites": false,
+        "appname": "authNetworkTimeoutErrorTest",
+        "connectTimeoutMS": 250,
+        "socketTimeoutMS": 250
+      },
+      "operations": [
+        {
+          "name": "insertMany",
+          "object": "collection",
+          "arguments": {
+            "documents": [
+              {
+                "_id": 3
+              },
+              {
+                "_id": 4
+              }
+            ]
+          },
+          "error": true
+        },
+        {
+          "name": "waitForEvent",
+          "object": "testRunner",
+          "arguments": {
+            "event": "ServerMarkedUnknownEvent",
+            "count": 1
+          }
+        },
+        {
+          "name": "waitForEvent",
+          "object": "testRunner",
+          "arguments": {
+            "event": "PoolClearedEvent",
+            "count": 1
+          }
+        },
+        {
+          "name": "insertMany",
+          "object": "collection",
+          "arguments": {
+            "documents": [
+              {
+                "_id": 5
+              },
+              {
+                "_id": 6
+              }
+            ]
+          }
+        },
+        {
+          "name": "assertEventCount",
+          "object": "testRunner",
+          "arguments": {
+            "event": "ServerMarkedUnknownEvent",
+            "count": 1
+          }
+        },
+        {
+          "name": "assertEventCount",
+          "object": "testRunner",
+          "arguments": {
+            "event": "PoolClearedEvent",
+            "count": 1
+          }
+        }
+      ],
+      "expectations": [
+        {
+          "command_started_event": {
+            "command": {
+              "insert": "auth-network-timeout-error",
+              "documents": [
+                {
+                  "_id": 5
+                },
+                {
+                  "_id": 6
+                }
+              ]
+            },
+            "command_name": "insert",
+            "database_name": "sdam-tests"
+          }
+        }
+      ],
+      "outcome": {
+        "collection": {
+          "data": [
+            {
+              "_id": 1
+            },
+            {
+              "_id": 2
+            },
+            {
+              "_id": 5
+            },
+            {
+              "_id": 6
+            }
+          ]
+        }
+      }
+    }
+  ]
+}
diff --git a/test/spec/server-discovery-and-monitoring/integration/auth-network-timeout-error.yml b/test/spec/server-discovery-and-monitoring/integration/auth-network-timeout-error.yml
new file mode 100644
index 0000000000..e065ec5abf
--- /dev/null
+++ b/test/spec/server-discovery-and-monitoring/integration/auth-network-timeout-error.yml
@@ -0,0 +1,86 @@
+# Test SDAM error handling.
+runOn:
+    # failCommand appName requirements
+    - minServerVersion: "4.4"
+      authEnabled: true
+
+database_name: &database_name "sdam-tests"
+collection_name: &collection_name "auth-network-timeout-error"
+
+data: &data
+  - {_id: 1}
+  - {_id: 2}
+
+tests:
+  - description: Reset server and pool after network timeout error during authentication
+    failPoint:
+      configureFailPoint: failCommand
+      mode: { times: 1 }
+      data:
+          failCommands: ["saslContinue"]
+          blockConnection: true
+          blockTimeMS: 500
+          appName: authNetworkTimeoutErrorTest
+    clientOptions:
+      retryWrites: false
+      appname: authNetworkTimeoutErrorTest
+      # Set a short connect/socket timeout to ensure the fail point causes the
+      # connection establishment to timeout.
+      connectTimeoutMS: 250
+      socketTimeoutMS: 250
+    operations:
+      - name: insertMany
+        object: collection
+        arguments:
+          documents:
+            - _id: 3
+            - _id: 4
+        error: true
+      - name: waitForEvent
+        object: testRunner
+        arguments:
+          event: ServerMarkedUnknownEvent
+          count: 1
+      - name: waitForEvent
+        object: testRunner
+        arguments:
+          event: PoolClearedEvent
+          count: 1
+      # Perform another operation to ensure the node is rediscovered.
+      - name: insertMany
+        object: collection
+        arguments:
+          documents:
+            - _id: 5
+            - _id: 6
+      # Assert the server was marked Unknown and pool was cleared exactly once.
+      - name: assertEventCount
+        object: testRunner
+        arguments:
+          event: ServerMarkedUnknownEvent
+          count: 1
+      - name: assertEventCount
+        object: testRunner
+        arguments:
+          event: PoolClearedEvent
+          count: 1
+
+    expectations:
+      # Note: The first insert command is never attempted because connection
+      # checkout fails.
+      - command_started_event:
+          command:
+            insert: *collection_name
+            documents:
+              - _id: 5
+              - _id: 6
+          command_name: insert
+          database_name: *database_name
+
+    outcome:
+      collection:
+        data:
+          - {_id: 1}
+          - {_id: 2}
+          - {_id: 5}
+          - {_id: 6}
diff --git a/test/spec/server-discovery-and-monitoring/integration/auth-shutdown-error.json b/test/spec/server-discovery-and-monitoring/integration/auth-shutdown-error.json
new file mode 100644
index 0000000000..2dab90e1c5
--- /dev/null
+++ b/test/spec/server-discovery-and-monitoring/integration/auth-shutdown-error.json
@@ -0,0 +1,140 @@
+{
+  "runOn": [
+    {
+      "minServerVersion": "4.4",
+      "authEnabled": true
+    }
+  ],
+  "database_name": "sdam-tests",
+  "collection_name": "auth-shutdown-error",
+  "data": [
+    {
+      "_id": 1
+    },
+    {
+      "_id": 2
+    }
+  ],
+  "tests": [
+    {
+      "description": "Reset server and pool after shutdown error during authentication",
+      "failPoint": {
+        "configureFailPoint": "failCommand",
+        "mode": {
+          "times": 1
+        },
+        "data": {
+          "failCommands": [
+            "saslContinue"
+          ],
+          "appName": "authShutdownErrorTest",
+          "errorCode": 91
+        }
+      },
+      "clientOptions": {
+        "retryWrites": false,
+        "appname": "authShutdownErrorTest"
+      },
+      "operations": [
+        {
+          "name": "insertMany",
+          "object": "collection",
+          "arguments": {
+            "documents": [
+              {
+                "_id": 3
+              },
+              {
+                "_id": 4
+              }
+            ]
+          },
+          "error": true
+        },
+        {
+          "name": "waitForEvent",
+          "object": "testRunner",
+          "arguments": {
+            "event": "ServerMarkedUnknownEvent",
+            "count": 1
+          }
+        },
+        {
+          "name": "waitForEvent",
+          "object": "testRunner",
+          "arguments": {
+            "event": "PoolClearedEvent",
+            "count": 1
+          }
+        },
+        {
+          "name": "insertMany",
+          "object": "collection",
+          "arguments": {
+            "documents": [
+              {
+                "_id": 5
+              },
+              {
+                "_id": 6
+              }
+            ]
+          }
+        },
+        {
+          "name": "assertEventCount",
+          "object": "testRunner",
+          "arguments": {
+            "event": "ServerMarkedUnknownEvent",
+            "count": 1
+          }
+        },
+        {
+          "name": "assertEventCount",
+          "object": "testRunner",
+          "arguments": {
+            "event": "PoolClearedEvent",
+            "count": 1
+          }
+        }
+      ],
+      "expectations": [
+        {
+          "command_started_event": {
+            "command": {
+              "insert": "auth-shutdown-error",
+              "documents": [
+                {
+                  "_id": 5
+                },
+                {
+                  "_id": 6
+                }
+              ]
+            },
+            "command_name": "insert",
+            "database_name": "sdam-tests"
+          }
+        }
+      ],
+      "outcome": {
+        "collection": {
+          "data": [
+            {
+              "_id": 1
+            },
+            {
+              "_id": 2
+            },
+            {
+              "_id": 5
+            },
+            {
+              "_id": 6
+            }
+          ]
+        }
+      }
+    }
+  ]
+}
diff --git a/test/spec/server-discovery-and-monitoring/integration/auth-shutdown-error.yml b/test/spec/server-discovery-and-monitoring/integration/auth-shutdown-error.yml
new file mode 100644
index 0000000000..4efe25f3be
--- /dev/null
+++ b/test/spec/server-discovery-and-monitoring/integration/auth-shutdown-error.yml
@@ -0,0 +1,81 @@
+# Test SDAM error handling.
+runOn:
+    # failCommand appName requirements
+    - minServerVersion: "4.4"
+      authEnabled: true
+
+database_name: &database_name "sdam-tests"
+collection_name: &collection_name "auth-shutdown-error"
+
+data: &data
+  - {_id: 1}
+  - {_id: 2}
+
+tests:
+  - description: Reset server and pool after shutdown error during authentication
+    failPoint:
+      configureFailPoint: failCommand
+      mode: { times: 1 }
+      data:
+          failCommands: ["saslContinue"]
+          appName: authShutdownErrorTest
+          errorCode: 91
+    clientOptions:
+      retryWrites: false
+      appname: authShutdownErrorTest
+    operations:
+      - name: insertMany
+        object: collection
+        arguments:
+          documents:
+            - _id: 3
+            - _id: 4
+        error: true
+      - name: waitForEvent
+        object: testRunner
+        arguments:
+          event: ServerMarkedUnknownEvent
+          count: 1
+      - name: waitForEvent
+        object: testRunner
+        arguments:
+          event: PoolClearedEvent
+          count: 1
+      # Perform another operation to ensure the node is rediscovered.
+      - name: insertMany
+        object: collection
+        arguments:
+          documents:
+            - _id: 5
+            - _id: 6
+      # Assert the server was marked Unknown and pool was cleared exactly once.
+      - name: assertEventCount
+        object: testRunner
+        arguments:
+          event: ServerMarkedUnknownEvent
+          count: 1
+      - name: assertEventCount
+        object: testRunner
+        arguments:
+          event: PoolClearedEvent
+          count: 1
+
+    expectations:
+      # Note: The first insert command is never attempted because connection
+      # checkout fails.
+      - command_started_event:
+          command:
+            insert: *collection_name
+            documents:
+              - _id: 5
+              - _id: 6
+          command_name: insert
+          database_name: *database_name
+
+    outcome:
+      collection:
+        data:
+          - {_id: 1}
+          - {_id: 2}
+          - {_id: 5}
+          - {_id: 6}
diff --git a/test/spec/server-discovery-and-monitoring/integration/cancel-server-check.yml b/test/spec/server-discovery-and-monitoring/integration/cancel-server-check.yml
index a52d1bea9e..2a759a8452 100644
--- a/test/spec/server-discovery-and-monitoring/integration/cancel-server-check.yml
+++ b/test/spec/server-discovery-and-monitoring/integration/cancel-server-check.yml
@@ -34,7 +34,7 @@ tests:
       # This should:
       # 1) Mark the server Unknown
       # 2) Clear the connection pool
-      # 3) Cancel the in progress isMaster check and close the Monitor
+      # 3) Cancel the in progress hello or legacy hello check and close the Monitor
       #    connection
       # 4) The write will be then we retried, server selection will request an
       #    immediate check, and block for ~500ms until the next Monitor check
diff --git a/test/spec/server-discovery-and-monitoring/integration/connectTimeoutMS.json b/test/spec/server-discovery-and-monitoring/integration/connectTimeoutMS.json
index b75eb58536..36a6dc4507 100644
--- a/test/spec/server-discovery-and-monitoring/integration/connectTimeoutMS.json
+++ b/test/spec/server-discovery-and-monitoring/integration/connectTimeoutMS.json
@@ -42,8 +42,8 @@
               },
               "data": {
                 "failCommands": [
-                  "isMaster",
-                  "hello"
+                  "hello",
+                  "isMaster"
                 ],
                 "appName": "connectTimeoutMS=0",
                 "blockConnection": true,
diff --git a/test/spec/server-discovery-and-monitoring/integration/connectTimeoutMS.yml b/test/spec/server-discovery-and-monitoring/integration/connectTimeoutMS.yml
index e32aa6b587..3ee4d32926 100644
--- a/test/spec/server-discovery-and-monitoring/integration/connectTimeoutMS.yml
+++ b/test/spec/server-discovery-and-monitoring/integration/connectTimeoutMS.yml
@@ -23,7 +23,7 @@ tests:
           documents:
             - _id: 1
             - _id: 2
-      # Block the next streaming isMaster check for longer than
+      # Block the next streaming hello check for longer than
       # heartbeatFrequencyMS to ensure that the connection timeout remains
       # unlimited.
       - name: configureFailPoint
@@ -33,7 +33,7 @@ tests:
             configureFailPoint: failCommand
             mode: { times: 2 }
             data:
-                failCommands: ["isMaster", "hello"]
+                failCommands: ["hello", "isMaster"]
                 appName: connectTimeoutMS=0
                 blockConnection: true
                 blockTimeMS: 550
diff --git a/test/spec/server-discovery-and-monitoring/integration/find-network-timeout-error.json b/test/spec/server-discovery-and-monitoring/integration/find-network-timeout-error.json
new file mode 100644
index 0000000000..c4e10b3a76
--- /dev/null
+++ b/test/spec/server-discovery-and-monitoring/integration/find-network-timeout-error.json
@@ -0,0 +1,119 @@
+{
+  "runOn": [
+    {
+      "minServerVersion": "4.4"
+    }
+  ],
+  "database_name": "sdam-tests",
+  "collection_name": "find-network-timeout-error",
+  "data": [
+    {
+      "_id": 1
+    },
+    {
+      "_id": 2
+    }
+  ],
+  "tests": [
+    {
+      "description": "Ignore network timeout error on find",
+      "failPoint": {
+        "configureFailPoint": "failCommand",
+        "mode": {
+          "times": 1
+        },
+        "data": {
+          "failCommands": [
+            "find"
+          ],
+          "blockConnection": true,
+          "blockTimeMS": 500,
+          "appName": "findNetworkTimeoutErrorTest"
+        }
+      },
+      "clientOptions": {
+        "retryWrites": false,
+        "retryReads": false,
+        "appname": "findNetworkTimeoutErrorTest",
+        "socketTimeoutMS": 250
+      },
+      "operations": [
+        {
+          "name": "find",
+          "object": "collection",
+          "arguments": {
+            "filter": {
+              "_id": 1
+            }
+          },
+          "error": true
+        },
+        {
+          "name": "insertOne",
+          "object": "collection",
+          "arguments": {
+            "document": {
+              "_id": 3
+            }
+          }
+        },
+        {
+          "name": "assertEventCount",
+          "object": "testRunner",
+          "arguments": {
+            "event": "ServerMarkedUnknownEvent",
+            "count": 0
+          }
+        },
+        {
+          "name": "assertEventCount",
+          "object": "testRunner",
+          "arguments": {
+            "event": "PoolClearedEvent",
+            "count": 0
+          }
+        }
+      ],
+      "expectations": [
+        {
+          "command_started_event": {
+            "command": {
+              "find": "find-network-timeout-error"
+            },
+            "command_name": "find",
+            "database_name": "sdam-tests"
+          }
+        },
+        {
+          "command_started_event": {
+            "command": {
+              "insert": "find-network-timeout-error",
+              "documents": [
+                {
+                  "_id": 3
+                }
+              ]
+            },
+            "command_name": "insert",
+            "database_name": "sdam-tests"
+          }
+        }
+      ],
+      "outcome": {
+        "collection": {
+          "data": [
+            {
+              "_id": 1
+            },
+            {
+              "_id": 2
+            },
+            {
+              "_id": 3
+            }
+          ]
+        }
+      }
+    }
+  ]
+}
diff --git a/test/spec/server-discovery-and-monitoring/integration/find-network-timeout-error.yml b/test/spec/server-discovery-and-monitoring/integration/find-network-timeout-error.yml
new file mode 100644
index 0000000000..d4ce8e39a7
--- /dev/null
+++ b/test/spec/server-discovery-and-monitoring/integration/find-network-timeout-error.yml
@@ -0,0 +1,73 @@
+# Test SDAM error handling.
+runOn:
+    # failCommand appName requirements
+    - minServerVersion: "4.4"
+
+database_name: &database_name "sdam-tests"
+collection_name: &collection_name "find-network-timeout-error"
+
+data: &data
+  - {_id: 1}
+  - {_id: 2}
+
+tests:
+  - description: Ignore network timeout error on find
+    failPoint:
+      configureFailPoint: failCommand
+      mode: { times: 1 }
+      data:
+          failCommands: ["find"]
+          blockConnection: true
+          blockTimeMS: 500
+          appName: findNetworkTimeoutErrorTest
+    clientOptions:
+      retryWrites: false
+      retryReads: false
+      appname: findNetworkTimeoutErrorTest
+      # Set a short socket timeout to ensure the find command times out.
+      socketTimeoutMS: 250
+    operations:
+      - name: find
+        object: collection
+        arguments:
+          filter:
+            _id: 1
+        error: true
+      # Perform another operation to ensure the node is still usable.
+      - name: insertOne
+        object: collection
+        arguments:
+          document:
+            _id: 3
+      # Assert the server was not marked Unknown and the pool was not cleared.
+      - name: assertEventCount
+        object: testRunner
+        arguments:
+          event: ServerMarkedUnknownEvent
+          count: 0
+      - name: assertEventCount
+        object: testRunner
+        arguments:
+          event: PoolClearedEvent
+          count: 0
+
+    expectations:
+      - command_started_event:
+          command:
+            find: *collection_name
+          command_name: find
+          database_name: *database_name
+      - command_started_event:
+          command:
+            insert: *collection_name
+            documents:
+              - _id: 3
+          command_name: insert
+          database_name: *database_name
+
+    outcome:
+      collection:
+        data:
+          - {_id: 1}
+          - {_id: 2}
+          - {_id: 3}
diff --git a/test/spec/server-discovery-and-monitoring/integration/isMaster-command-error.json b/test/spec/server-discovery-and-monitoring/integration/hello-command-error.json
similarity index 94%
rename from test/spec/server-discovery-and-monitoring/integration/isMaster-command-error.json
rename to test/spec/server-discovery-and-monitoring/integration/hello-command-error.json
index 0567dd3323..05a93e751c 100644
--- a/test/spec/server-discovery-and-monitoring/integration/isMaster-command-error.json
+++ b/test/spec/server-discovery-and-monitoring/integration/hello-command-error.json
@@ -5,7 +5,7 @@
     }
   ],
   "database_name": "sdam-tests",
-  "collection_name": "isMaster-command-error",
+  "collection_name": "hello-command-error",
   "data": [],
   "tests": [
     {
@@ -17,8 +17,8 @@
         },
         "data": {
           "failCommands": [
-            "isMaster",
-            "hello"
+            "hello",
+            "isMaster"
           ],
           "appName": "commandErrorHandshakeTest",
           "closeConnection": false,
@@ -59,7 +59,7 @@
         {
           "command_started_event": {
             "command": {
-              "insert": "isMaster-command-error",
+              "insert": "hello-command-error",
               "documents": [
                 {
                   "_id": 1
@@ -121,8 +121,8 @@
               },
               "data": {
                 "failCommands": [
-                  "isMaster",
-                  "hello"
+                  "hello",
+                  "isMaster"
                 ],
                 "appName": "commandErrorCheckTest",
                 "closeConnection": false,
@@ -184,7 +184,7 @@
         {
           "command_started_event": {
             "command": {
-              "insert": "isMaster-command-error",
+              "insert": "hello-command-error",
               "documents": [
                 {
                   "_id": 1
@@ -201,7 +201,7 @@
         {
           "command_started_event": {
             "command": {
-              "insert": "isMaster-command-error",
+              "insert": "hello-command-error",
               "documents": [
                 {
                   "_id": 3
diff --git a/test/spec/server-discovery-and-monitoring/integration/isMaster-command-error.yml b/test/spec/server-discovery-and-monitoring/integration/hello-command-error.yml
similarity index 90%
rename from test/spec/server-discovery-and-monitoring/integration/isMaster-command-error.yml
rename to test/spec/server-discovery-and-monitoring/integration/hello-command-error.yml
index d376b5c133..ae25e4946c 100644
--- a/test/spec/server-discovery-and-monitoring/integration/isMaster-command-error.yml
+++ b/test/spec/server-discovery-and-monitoring/integration/hello-command-error.yml
@@ -4,19 +4,19 @@ runOn:
     - minServerVersion: "4.9"
 
 database_name: &database_name "sdam-tests"
-collection_name: &collection_name "isMaster-command-error"
+collection_name: &collection_name "hello-command-error"
 
 data: []
 
 tests:
   - description: Command error on Monitor handshake
     # Configure the initial handshake to fail with a command error.
-    # Use times: 2 so that the RTT isMaster fails as well.
+    # Use times: 2 so that the RTT hello fails as well.
     failPoint:
       configureFailPoint: failCommand
       mode: { times: 2 }
       data:
-          failCommands: ["isMaster", "hello"]
+          failCommands: ["hello", "isMaster"]
           appName: commandErrorHandshakeTest
           closeConnection: false
           errorCode: 91 # ShutdownInProgress
@@ -41,7 +41,7 @@ tests:
             - _id: 1
             - _id: 2
       # We cannot assert the server was marked Unknown and pool was cleared an
-      # exact number of times because the RTT isMaster may or may not have
+      # exact number of times because the RTT hello may or may not have
       # triggered this failpoint as well.
       # - name: assertEventCount
       #   object: testRunner
@@ -84,9 +84,9 @@ tests:
           documents:
             - _id: 1
             - _id: 2
-      # Configure the next streaming isMaster check to fail with a command
+      # Configure the next streaming hello check to fail with a command
       # error.
-      # Use times: 2 so that the RTT isMaster is blocked as well.
+      # Use times: 2 so that the RTT hello is blocked as well.
       - name: configureFailPoint
         object: testRunner
         arguments:
@@ -94,7 +94,7 @@ tests:
             configureFailPoint: failCommand
             mode: { times: 2 }
             data:
-                failCommands: ["isMaster", "hello"]
+                failCommands: ["hello", "isMaster"]
                 appName: commandErrorCheckTest
                 closeConnection: false
                 blockConnection: true
diff --git a/test/spec/server-discovery-and-monitoring/integration/isMaster-network-error.json b/test/spec/server-discovery-and-monitoring/integration/hello-network-error.json
similarity index 93%
rename from test/spec/server-discovery-and-monitoring/integration/isMaster-network-error.json
rename to test/spec/server-discovery-and-monitoring/integration/hello-network-error.json
index 617fc74dbc..b699363923 100644
--- a/test/spec/server-discovery-and-monitoring/integration/isMaster-network-error.json
+++ b/test/spec/server-discovery-and-monitoring/integration/hello-network-error.json
@@ -5,7 +5,7 @@
     }
   ],
   "database_name": "sdam-tests",
-  "collection_name": "isMaster-network-error",
+  "collection_name": "hello-network-error",
   "data": [],
   "tests": [
     {
@@ -17,8 +17,8 @@
         },
         "data": {
           "failCommands": [
-            "isMaster",
-            "hello"
+            "hello",
+            "isMaster"
           ],
           "appName": "networkErrorHandshakeTest",
           "closeConnection": true
@@ -58,7 +58,7 @@
         {
           "command_started_event": {
             "command": {
-              "insert": "isMaster-network-error",
+              "insert": "hello-network-error",
               "documents": [
                 {
                   "_id": 1
@@ -120,8 +120,8 @@
               },
               "data": {
                 "failCommands": [
-                  "isMaster",
-                  "hello"
+                  "hello",
+                  "isMaster"
                 ],
                 "appName": "networkErrorCheckTest",
                 "closeConnection": true
@@ -164,7 +164,7 @@
         {
           "command_started_event": {
             "command": {
-              "insert": "isMaster-network-error",
+              "insert": "hello-network-error",
               "documents": [
                 {
                   "_id": 1
@@ -181,7 +181,7 @@
         {
           "command_started_event": {
             "command": {
-              "insert": "isMaster-network-error",
+              "insert": "hello-network-error",
               "documents": [
                 {
                   "_id": 3
diff --git a/test/spec/server-discovery-and-monitoring/integration/isMaster-network-error.yml b/test/spec/server-discovery-and-monitoring/integration/hello-network-error.yml
similarity index 88%
rename from test/spec/server-discovery-and-monitoring/integration/isMaster-network-error.yml
rename to test/spec/server-discovery-and-monitoring/integration/hello-network-error.yml
index 5796560b81..54c6a3bac3 100644
--- a/test/spec/server-discovery-and-monitoring/integration/isMaster-network-error.yml
+++ b/test/spec/server-discovery-and-monitoring/integration/hello-network-error.yml
@@ -1,22 +1,22 @@
-# Test SDAM error handling.
+#hello Test SDAM error handling.
 runOn:
     # failCommand appName requirements
     - minServerVersion: "4.9"
 
 database_name: &database_name "sdam-tests"
-collection_name: &collection_name "isMaster-network-error"
+collection_name: &collection_name "hello-network-error"
 
 data: []
 
 tests:
   - description: Network error on Monitor handshake
     # Configure the initial handshake to fail with a network error.
-    # Use times: 2 so that the RTT isMaster fails as well.
+    # Use times: 2 so that the RTT hello fails as well.
     failPoint:
       configureFailPoint: failCommand
       mode: { times: 2 }
       data:
-          failCommands: ["isMaster", "hello"]
+          failCommands: ["hello", "isMaster"]
           appName: networkErrorHandshakeTest
           closeConnection: true
     clientOptions:
@@ -40,7 +40,7 @@ tests:
             - _id: 1
             - _id: 2
       # We cannot assert the server was marked Unknown and pool was cleared an
-      # exact number of times because the RTT isMaster may or may not have
+      # exact number of times because the RTT hello may or may not have
       # triggered this failpoint as well.
       # - name: assertEventCount
       #   object: testRunner
@@ -83,9 +83,9 @@ tests:
           documents:
             - _id: 1
             - _id: 2
-      # Configure the next streaming isMaster check to fail with a non-timeout
+      # Configure the next streaming hello check to fail with a non-timeout
       # network error. Use times: 2 to ensure that the the Monitor check fails
-      # since the RTT isMaster may trigger this failpoint as well.
+      # since the RTT hello may trigger this failpoint as well.
       - name: configureFailPoint
         object: testRunner
         arguments:
@@ -93,7 +93,7 @@ tests:
             configureFailPoint: failCommand
             mode: { times: 2 }
             data:
-                failCommands: ["isMaster", "hello"]
+                failCommands: ["hello", "isMaster"]
                 appName: networkErrorCheckTest
                 closeConnection: true
       # The network error on the next check should mark the server Unknown and
@@ -116,7 +116,7 @@ tests:
             - _id: 3
             - _id: 4
       # We cannot assert the server was marked Unknown and pool was cleared an
-      # exact number of times because the RTT isMaster may or may not have
+      # exact number of times because the RTT hello may or may not have
       # triggered this failpoint as well.
       # - name: assertEventCount
       #   object: testRunner
diff --git a/test/spec/server-discovery-and-monitoring/integration/isMaster-timeout.json b/test/spec/server-discovery-and-monitoring/integration/hello-timeout.json
similarity index 95%
rename from test/spec/server-discovery-and-monitoring/integration/isMaster-timeout.json
rename to test/spec/server-discovery-and-monitoring/integration/hello-timeout.json
index d37e7ee687..7bdc61a912 100644
--- a/test/spec/server-discovery-and-monitoring/integration/isMaster-timeout.json
+++ b/test/spec/server-discovery-and-monitoring/integration/hello-timeout.json
@@ -5,7 +5,7 @@
     }
   ],
   "database_name": "sdam-tests",
-  "collection_name": "isMaster-timeout",
+  "collection_name": "hello-timeout",
   "data": [],
   "tests": [
     {
@@ -17,8 +17,8 @@
         },
         "data": {
           "failCommands": [
-            "isMaster",
-            "hello"
+            "hello",
+            "isMaster"
           ],
           "appName": "timeoutMonitorHandshakeTest",
           "blockConnection": true,
@@ -59,7 +59,7 @@
         {
           "command_started_event": {
             "command": {
-              "insert": "isMaster-timeout",
+              "insert": "hello-timeout",
               "documents": [
                 {
                   "_id": 1
@@ -121,8 +121,8 @@
               },
               "data": {
                 "failCommands": [
-                  "isMaster",
-                  "hello"
+                  "hello",
+                  "isMaster"
                 ],
                 "appName": "timeoutMonitorCheckTest",
                 "blockConnection": true,
@@ -182,7 +182,7 @@
         {
           "command_started_event": {
             "command": {
-              "insert": "isMaster-timeout",
+              "insert": "hello-timeout",
               "documents": [
                 {
                   "_id": 1
@@ -199,7 +199,7 @@
         {
           "command_started_event": {
             "command": {
-              "insert": "isMaster-timeout",
+              "insert": "hello-timeout",
               "documents": [
                 {
                   "_id": 3
@@ -298,7 +298,7 @@
         {
           "command_started_event": {
             "command": {
-              "insert": "isMaster-timeout",
+              "insert": "hello-timeout",
               "documents": [
                 {
                   "_id": 1
@@ -315,7 +315,7 @@
         {
           "command_started_event": {
             "command": {
-              "insert": "isMaster-timeout",
+              "insert": "hello-timeout",
               "documents": [
                 {
                   "_id": 3
diff --git a/test/spec/server-discovery-and-monitoring/integration/isMaster-timeout.yml b/test/spec/server-discovery-and-monitoring/integration/hello-timeout.yml
similarity index 93%
rename from test/spec/server-discovery-and-monitoring/integration/isMaster-timeout.yml
rename to test/spec/server-discovery-and-monitoring/integration/hello-timeout.yml
index b77e37ba12..6c91ca9a72 100644
--- a/test/spec/server-discovery-and-monitoring/integration/isMaster-timeout.yml
+++ b/test/spec/server-discovery-and-monitoring/integration/hello-timeout.yml
@@ -4,19 +4,19 @@ runOn:
     - minServerVersion: "4.4"
 
 database_name: &database_name "sdam-tests"
-collection_name: &collection_name "isMaster-timeout"
+collection_name: &collection_name "hello-timeout"
 
 data: []
 
 tests:
   - description: Network timeout on Monitor handshake
     # Configure the initial handshake to fail with a timeout.
-    # Use times: 2 so that the RTT isMaster is blocked as well.
+    # Use times: 2 so that the RTT hello is blocked as well.
     failPoint:
       configureFailPoint: failCommand
       mode: { times: 2 }
       data:
-          failCommands: ["isMaster", "hello"]
+          failCommands: ["hello", "isMaster"]
           appName: timeoutMonitorHandshakeTest
           blockConnection: true
           blockTimeMS: 1000
@@ -41,7 +41,7 @@ tests:
             - _id: 1
             - _id: 2
       # We cannot assert the server was marked Unknown and pool was cleared an
-      # exact number of times because the RTT isMaster may or may not have
+      # exact number of times because the RTT hello may or may not have
       # triggered this failpoint as well.
       # - name: assertEventCount
       #   object: testRunner
@@ -84,8 +84,8 @@ tests:
           documents:
             - _id: 1
             - _id: 2
-      # Configure the next streaming isMaster check to fail with a timeout
-      # Use times: 2 so that the RTT isMaster is blocked as well.
+      # Configure the next streaming hello check to fail with a timeout
+      # Use times: 2 so that the RTT hello is blocked as well.
       - name: configureFailPoint
         object: testRunner
         arguments:
@@ -93,7 +93,7 @@ tests:
             configureFailPoint: failCommand
             mode: { times: 2 }
             data:
-                failCommands: ["isMaster", "hello"]
+                failCommands: ["hello", "isMaster"]
                 appName: timeoutMonitorCheckTest
                 blockConnection: true
                 # blockTimeMS is evaluated after the waiting for heartbeatFrequencyMS server-side, so this value only
diff --git a/test/spec/server-discovery-and-monitoring/integration/minPoolSize-error.json b/test/spec/server-discovery-and-monitoring/integration/minPoolSize-error.json
new file mode 100644
index 0000000000..9f8e4f6f8b
--- /dev/null
+++ b/test/spec/server-discovery-and-monitoring/integration/minPoolSize-error.json
@@ -0,0 +1,102 @@
+{
+  "runOn": [
+    {
+      "minServerVersion": "4.9"
+    }
+  ],
+  "database_name": "sdam-tests",
+  "collection_name": "sdam-minPoolSize-error",
+  "data": [],
+  "tests": [
+    {
+      "description": "Network error on minPoolSize background creation",
+      "failPoint": {
+        "configureFailPoint": "failCommand",
+        "mode": {
+          "skip": 3
+        },
+        "data": {
+          "failCommands": [
+            "hello",
+            "isMaster"
+          ],
+          "appName": "SDAMminPoolSizeError",
+          "closeConnection": true
+        }
+      },
+      "clientOptions": {
+        "heartbeatFrequencyMS": 10000,
+        "appname": "SDAMminPoolSizeError",
+        "minPoolSize": 10,
+        "serverSelectionTimeoutMS": 1000,
+        "directConnection": true
+      },
+      "operations": [
+        {
+          "name": "waitForEvent",
+          "object": "testRunner",
+          "arguments": {
+            "event": "PoolReadyEvent",
+            "count": 1
+          }
+        },
+        {
+          "name": "waitForEvent",
+          "object": "testRunner",
+          "arguments": {
+            "event": "PoolClearedEvent",
+            "count": 1
+          }
+        },
+        {
+          "name": "waitForEvent",
+          "object": "testRunner",
+          "arguments": {
+            "event": "ServerMarkedUnknownEvent",
+            "count": 1
+          }
+        },
+        {
+          "name": "runCommand",
+          "object": "database",
+          "command_name": "ping",
+          "arguments": {
+            "command": {
+              "ping": {}
+            }
+          },
+          "error": true
+        },
+        {
+          "name": "configureFailPoint",
+          "object": "testRunner",
+          "arguments": {
+            "failPoint": {
+              "configureFailPoint": "failCommand",
+              "mode": "off"
+            }
+          }
+        },
+        {
+          "name": "runCommand",
+          "object": "database",
+          "command_name": "ping",
+          "arguments": {
+            "command": {
+              "ping": 1
+            }
+          },
+          "error": false
+        },
+        {
+          "name": "assertEventCount",
+          "object": "testRunner",
+          "arguments": {
+            "event": "PoolReadyEvent",
+            "count": 2
+          }
+        }
+      ]
+    }
+  ]
+}
diff --git a/test/spec/server-discovery-and-monitoring/integration/minPoolSize-error.yml b/test/spec/server-discovery-and-monitoring/integration/minPoolSize-error.yml
new file mode 100644
index 0000000000..3272728893
--- /dev/null
+++ b/test/spec/server-discovery-and-monitoring/integration/minPoolSize-error.yml
@@ -0,0 +1,77 @@
+# Test SDAM error handling.
+runOn:
+    # failCommand appName requirements
+    - minServerVersion: "4.9"
+
+database_name: &database_name "sdam-tests"
+collection_name: &collection_name "sdam-minPoolSize-error"
+
+data: []
+
+tests:
+  - description: Network error on minPoolSize background creation
+    # Configure the initial monitor handshake to succeed but the
+    # first or second background minPoolSize establishments to fail.
+    failPoint:
+      configureFailPoint: failCommand
+      mode: { skip: 3 }
+      data:
+        failCommands: ["hello", "isMaster"]
+        appName: SDAMminPoolSizeError
+        closeConnection: true
+    clientOptions:
+      heartbeatFrequencyMS: 10000
+      appname: SDAMminPoolSizeError
+      minPoolSize: 10
+      serverSelectionTimeoutMS: 1000
+      directConnection: true
+    operations:
+      # Wait for monitor to succeed handshake and mark the pool as ready.
+      - name: waitForEvent
+        object: testRunner
+        arguments:
+          event: PoolReadyEvent
+          count: 1
+      # Background connection establishment ensuring minPoolSize should fail,
+      # causing the pool to be cleared.
+      - name: waitForEvent
+        object: testRunner
+        arguments:
+          event: PoolClearedEvent
+          count: 1
+      # The server should be marked as Unknown as part of this.
+      - name: waitForEvent
+        object: testRunner
+        arguments:
+          event: ServerMarkedUnknownEvent
+          count: 1
+      # Executing a command should fail server selection due to not being able
+      # to find the primary.
+      - name: runCommand
+        object: database
+        command_name: ping
+        arguments:
+          command:
+            ping: {}
+        error: true
+      # Disable the failpoint, allowing the monitor to discover the primary again.
+      - name: configureFailPoint
+        object: testRunner
+        arguments:
+          failPoint:
+            configureFailPoint: failCommand
+            mode: off
+      # Perform an operation to ensure the node is discovered.
+      - name: runCommand
+        object: database
+        command_name: ping
+        arguments:
+          command:
+            ping: 1
+        error: false
+      # Assert that the monitor discovered the primary and mark the pool as ready again.
+      - name: assertEventCount
+        object: testRunner
+        arguments:
+          event: PoolReadyEvent
+          count: 2
diff --git a/test/spec/server-discovery-and-monitoring/integration/pool-cleared-error.json b/test/spec/server-discovery-and-monitoring/integration/pool-cleared-error.json
new file mode 100644
index 0000000000..52456f9e13
--- /dev/null
+++ b/test/spec/server-discovery-and-monitoring/integration/pool-cleared-error.json
@@ -0,0 +1,307 @@
+{
+  "runOn": [
+    {
+      "minServerVersion": "4.9",
+      "topology": [
+        "replicaset",
+        "sharded"
+      ]
+    }
+  ],
+  "database_name": "sdam-tests",
+  "collection_name": "pool-cleared-error",
+  "data": [],
+  "tests": [
+    {
+      "description": "PoolClearedError does not mark server unknown",
+      "clientOptions": {
+        "retryWrites": true,
+        "maxPoolSize": 1,
+        "appname": "poolClearedErrorTest"
+      },
+      "operations": [
+        {
+          "name": "insertOne",
+          "object": "collection",
+          "arguments": {
+            "document": {
+              "_id": 1
+            }
+          }
+        },
+        {
+          "name": "configureFailPoint",
+          "object": "testRunner",
+          "arguments": {
+            "failPoint": {
+              "configureFailPoint": "failCommand",
+              "mode": {
+                "times": 1
+              },
+              "data": {
+                "failCommands": [
+                  "insert"
+                ],
+                "blockConnection": true,
+                "blockTimeMS": 100,
+                "closeConnection": true,
+                "appName": "poolClearedErrorTest"
+              }
+            }
+          }
+        },
+        {
+          "name": "startThread",
+          "object": "testRunner",
+          "arguments": {
+            "name": "thread1"
+          }
+        },
+        {
+          "name": "startThread",
+          "object": "testRunner",
+          "arguments": {
+            "name": "thread2"
+          }
+        },
+        {
+          "name": "startThread",
+          "object": "testRunner",
+          "arguments": {
+            "name": "thread3"
+          }
+        },
+        {
+          "name": "startThread",
+          "object": "testRunner",
+          "arguments": {
+            "name": "thread4"
+          }
+        },
+        {
+          "name": "startThread",
+          "object": "testRunner",
+          "arguments": {
+            "name": "thread5"
+          }
+        },
+        {
+          "name": "startThread",
+          "object": "testRunner",
+          "arguments": {
+            "name": "thread6"
+          }
+        },
+        {
+          "name": "runOnThread",
+          "object": "testRunner",
+          "arguments": {
+            "name": "thread1",
+            "operation": {
+              "name": "insertOne",
+              "object": "collection",
+              "arguments": {
+                "document": {
+                  "_id": 2
+                }
+              }
+            }
+          }
+        },
+        {
+          "name": "runOnThread",
+          "object": "testRunner",
+          "arguments": {
+            "name": "thread2",
+            "operation": {
+              "name": "insertOne",
+              "object": "collection",
+              "arguments": {
+                "document": {
+                  "_id": 3
+                }
+              }
+            }
+          }
+        },
+        {
+          "name": "runOnThread",
+          "object": "testRunner",
+          "arguments": {
+            "name": "thread3",
+            "operation": {
+              "name": "insertOne",
+              "object": "collection",
+              "arguments": {
+                "document": {
+                  "_id": 4
+                }
+              }
+            }
+          }
+        },
+        {
+          "name": "runOnThread",
+          "object": "testRunner",
+          "arguments": {
+            "name": "thread4",
+            "operation": {
+              "name": "insertOne",
+              "object": "collection",
+              "arguments": {
+                "document": {
+                  "_id": 5
+                }
+              }
+            }
+          }
+        },
+        {
+          "name": "runOnThread",
+          "object": "testRunner",
+          "arguments": {
+            "name": "thread5",
+            "operation": {
+              "name": "insertOne",
+              "object": "collection",
+              "arguments": {
+                "document": {
+                  "_id": 6
+                }
+              }
+            }
+          }
+        },
+        {
+          "name": "runOnThread",
+          "object": "testRunner",
+          "arguments": {
+            "name": "thread6",
+            "operation": {
+              "name": "insertOne",
+              "object": "collection",
+              "arguments": {
+                "document": {
+                  "_id": 7
+                }
+              }
+            }
+          }
+        },
+        {
+          "name": "waitForThread",
+          "object": "testRunner",
+          "arguments": {
+            "name": "thread1"
+          }
+        },
+        {
+          "name": "waitForThread",
+          "object": "testRunner",
+          "arguments": {
+            "name": "thread2"
+          }
+        },
+        {
+          "name": "waitForThread",
+          "object": "testRunner",
+          "arguments": {
+            "name": "thread3"
+          }
+        },
+        {
+          "name": "waitForThread",
+          "object": "testRunner",
+          "arguments": {
+            "name": "thread4"
+          }
+        },
+        {
+          "name": "waitForThread",
+          "object": "testRunner",
+          "arguments": {
+            "name": "thread5"
+          }
+        },
+        {
+          "name": "waitForThread",
+          "object": "testRunner",
+          "arguments": {
+            "name": "thread6"
+          }
+        },
+        {
+          "name": "waitForEvent",
+          "object": "testRunner",
+          "arguments": {
+            "event": "ServerMarkedUnknownEvent",
+            "count": 1
+          }
+        },
+        {
+          "name": "waitForEvent",
+          "object": "testRunner",
+          "arguments": {
+            "event": "PoolClearedEvent",
+            "count": 1
+          }
+        },
+        {
+          "name": "insertOne",
+          "object": "collection",
+          "arguments": {
+            "document": {
+              "_id": 8
+            }
+          }
+        },
+        {
+          "name": "assertEventCount",
+          "object": "testRunner",
+          "arguments": {
+            "event": "ServerMarkedUnknownEvent",
+            "count": 1
+          }
+        },
+        {
+          "name": "assertEventCount",
+          "object": "testRunner",
+          "arguments": {
+            "event": "PoolClearedEvent",
+            "count": 1
+          }
+        }
+      ],
+      "outcome": {
+        "collection": {
+          "data": [
+            {
+              "_id": 1
+            },
+            {
+              "_id": 2
+            },
+            {
+              "_id": 3
+            },
+            {
+              "_id": 4
+            },
+            {
+              "_id": 5
+            },
+            {
+              "_id": 6
+            },
+            {
+              "_id": 7
+            },
+            {
+              "_id": 8
+            }
+          ]
+        }
+      }
+    }
+  ]
+}
diff --git a/test/spec/server-discovery-and-monitoring/integration/pool-cleared-error.yml b/test/spec/server-discovery-and-monitoring/integration/pool-cleared-error.yml
new file mode 100644
index 0000000000..f2e1e04b79
--- /dev/null
+++ b/test/spec/server-discovery-and-monitoring/integration/pool-cleared-error.yml
@@ -0,0 +1,201 @@
+# Test SDAM error handling.
+runOn:
+    # This test requires retryable writes, failCommand appName, and
+    # failCommand blockConnection with closeConnection:true (SERVER-53512).
+    - minServerVersion: "4.9"
+      topology: ["replicaset", "sharded"]
+
+database_name: &database_name "sdam-tests"
+collection_name: &collection_name "pool-cleared-error"
+
+data: []
+
+tests:
+  - description: PoolClearedError does not mark server unknown
+    clientOptions:
+      retryWrites: true
+      maxPoolSize: 1
+      appname: poolClearedErrorTest
+    operations:
+      # Perform an operation to ensure the node is discovered.
+      - name: insertOne
+        object: collection
+        arguments:
+          document:
+            _id: 1
+      # Configure the next insert to fail with a network error which will
+      # clear the pool leaving it paused until the server is rediscovered.
+      - name: configureFailPoint
+        object: testRunner
+        arguments:
+          failPoint:
+            configureFailPoint: failCommand
+            mode: { times: 1 }
+            data:
+                failCommands: ["insert"]
+                blockConnection: true
+                blockTimeMS: 100
+                closeConnection: true
+                appName: poolClearedErrorTest
+      # Start threads.
+      - name: startThread
+        object: testRunner
+        arguments:
+          name: thread1
+      - name: startThread
+        object: testRunner
+        arguments:
+          name: thread2
+      - name: startThread
+        object: testRunner
+        arguments:
+          name: thread3
+      - name: startThread
+        object: testRunner
+        arguments:
+          name: thread4
+      - name: startThread
+        object: testRunner
+        arguments:
+          name: thread5
+      - name: startThread
+        object: testRunner
+        arguments:
+          name: thread6
+      # Perform concurrent insert operations. The first one to execute will
+      # fail with a network error, mark the server Unknown, clear the pool,
+      # and retry.
+      # The other operations will either:
+      # - Notice the pool is paused, fail with a PoolClearedError, and retry.
+      # - Or block waiting in server selection until the server is
+      #   rediscovered.
+      #
+      # Note that this test does not guarantee that a PoolClearedError will be
+      # raised but it is likely since the initial insert is delayed.
+      - name: runOnThread
+        object: testRunner
+        arguments:
+          name: thread1
+          operation:
+            name: insertOne
+            object: collection
+            arguments:
+              document:
+                _id: 2
+      - name: runOnThread
+        object: testRunner
+        arguments:
+          name: thread2
+          operation:
+            name: insertOne
+            object: collection
+            arguments:
+              document:
+                _id: 3
+      - name: runOnThread
+        object: testRunner
+        arguments:
+          name: thread3
+          operation:
+            name: insertOne
+            object: collection
+            arguments:
+              document:
+                _id: 4
+      - name: runOnThread
+        object: testRunner
+        arguments:
+          name: thread4
+          operation:
+            name: insertOne
+            object: collection
+            arguments:
+              document:
+                _id: 5
+      - name: runOnThread
+        object: testRunner
+        arguments:
+          name: thread5
+          operation:
+            name: insertOne
+            object: collection
+            arguments:
+              document:
+                _id: 6
+      - name: runOnThread
+        object: testRunner
+        arguments:
+          name: thread6
+          operation:
+            name: insertOne
+            object: collection
+            arguments:
+              document:
+                _id: 7
+      # Stop threads.
+      - name: waitForThread
+        object: testRunner
+        arguments:
+          name: thread1
+      - name: waitForThread
+        object: testRunner
+        arguments:
+          name: thread2
+      - name: waitForThread
+        object: testRunner
+        arguments:
+          name: thread3
+      - name: waitForThread
+        object: testRunner
+        arguments:
+          name: thread4
+      - name: waitForThread
+        object: testRunner
+        arguments:
+          name: thread5
+      - name: waitForThread
+        object: testRunner
+        arguments:
+          name: thread6
+      # The first shutdown error should mark the server Unknown and then clear
+      # the pool.
+      - name: waitForEvent
+        object: testRunner
+        arguments:
+          event: ServerMarkedUnknownEvent
+          count: 1
+      - name: waitForEvent
+        object: testRunner
+        arguments:
+          event: PoolClearedEvent
+          count: 1
+      # Perform an operation to ensure the node still useable.
+      - name: insertOne
+        object: collection
+        arguments:
+          document:
+            _id: 8
+      # Assert the server was marked Unknown and pool was cleared exactly once.
+      - name: assertEventCount
+        object: testRunner
+        arguments:
+          event: ServerMarkedUnknownEvent
+          count: 1
+      - name: assertEventCount
+        object: testRunner
+        arguments:
+          event: PoolClearedEvent
+          count: 1
+
+    # Order of operations is non-deterministic so we cannot check events.
+    outcome:
+      collection:
+        data:
+          - {_id: 1}
+          - {_id: 2}
+          - {_id: 3}
+          - {_id: 4}
+          - {_id: 5}
+          - {_id: 6}
+          - {_id: 7}
+          - {_id: 8}
diff --git a/test/spec/server-discovery-and-monitoring/load-balanced/discover_load_balancer.json b/test/spec/server-discovery-and-monitoring/load-balanced/discover_load_balancer.json
new file mode 100644
index 0000000000..d2e34478e6
--- /dev/null
+++ b/test/spec/server-discovery-and-monitoring/load-balanced/discover_load_balancer.json
@@ -0,0 +1,28 @@
+{
+  "description": "Load balancer can be discovered and only has the address property set",
+  "uri": "mongodb://a/?loadBalanced=true",
+  "phases": [
+    {
+      "outcome": {
+        "servers": {
+          "a:27017": {
+            "type": "LoadBalancer",
+            "setName": null,
+            "setVersion": null,
+            "electionId": null,
+            "logicalSessionTimeoutMinutes": null,
+            "minWireVersion": null,
+            "maxWireVersion": null,
+            "topologyVersion": null
+          }
+        },
+        "topologyType": "LoadBalanced",
+        "setName": null,
+        "logicalSessionTimeoutMinutes": null,
+        "maxSetVersion": null,
+        "maxElectionId": null,
+        "compatible": true
+      }
+    }
+  ]
+}
diff --git a/test/spec/server-discovery-and-monitoring/load-balanced/discover_load_balancer.yml b/test/spec/server-discovery-and-monitoring/load-balanced/discover_load_balancer.yml
new file mode 100644
index 0000000000..20083d98be
--- /dev/null
+++ b/test/spec/server-discovery-and-monitoring/load-balanced/discover_load_balancer.yml
@@ -0,0 +1,25 @@
+description: "Load balancer can be discovered and only has the address property set"
+
+uri: "mongodb://a/?loadBalanced=true"
+
+phases:
+
+  # There should be no monitoring in LoadBalanced mode, so no responses are necessary to get the topology into the
+  # correct state.
+  - outcome:
+      servers:
+        a:27017:
+          type: LoadBalancer
+          setName: null
+          setVersion: null
+          electionId: null
+          logicalSessionTimeoutMinutes: null
+          minWireVersion: null
+          maxWireVersion: null
+          topologyVersion: null
+      topologyType: LoadBalanced
+      setName: null
+      logicalSessionTimeoutMinutes: null
+      maxSetVersion: null
+      maxElectionId: null
+      compatible: true
diff --git a/test/spec/server-discovery-and-monitoring/monitoring/discovered_standalone.json b/test/spec/server-discovery-and-monitoring/monitoring/discovered_standalone.json
index c3ab59834f..dd8f7fc51e 100644
--- a/test/spec/server-discovery-and-monitoring/monitoring/discovered_standalone.json
+++ b/test/spec/server-discovery-and-monitoring/monitoring/discovered_standalone.json
@@ -8,9 +8,10 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "minWireVersion": 0,
-            "maxWireVersion": 4
+            "maxWireVersion": 6
           }
         ]
       ],
diff --git a/test/spec/server-discovery-and-monitoring/monitoring/discovered_standalone.yml b/test/spec/server-discovery-and-monitoring/monitoring/discovered_standalone.yml
index ad4ab14c31..5d808f2600 100644
--- a/test/spec/server-discovery-and-monitoring/monitoring/discovered_standalone.yml
+++ b/test/spec/server-discovery-and-monitoring/monitoring/discovered_standalone.yml
@@ -5,7 +5,7 @@ phases:
     responses:
       -
         - "a:27017"
-        - { ok: 1, ismaster: true, minWireVersion: 0, maxWireVersion: 4 }
+        - { ok: 1, helloOk: true, isWritablePrimary: true, minWireVersion: 0, maxWireVersion: 6 }
 
     outcome:
       events:
diff --git a/test/spec/server-discovery-and-monitoring/monitoring/load_balancer.json b/test/spec/server-discovery-and-monitoring/monitoring/load_balancer.json
new file mode 100644
index 0000000000..09b1537193
--- /dev/null
+++ b/test/spec/server-discovery-and-monitoring/monitoring/load_balancer.json
@@ -0,0 +1,93 @@
+{
+  "description": "Monitoring a load balancer",
+  "uri": "mongodb://a:27017/?loadBalanced=true",
+  "phases": [
+    {
+      "outcome": {
+        "events": [
+          {
+            "topology_opening_event": {
+              "topologyId": "42"
+            }
+          },
+          {
+            "topology_description_changed_event": {
+              "topologyId": "42",
+              "previousDescription": {
+                "topologyType": "Unknown",
+                "servers": []
+              },
+              "newDescription": {
+                "topologyType": "LoadBalanced",
+                "servers": [
+                  {
+                    "address": "a:27017",
+                    "arbiters": [],
+                    "hosts": [],
+                    "passives": [],
+                    "type": "Unknown"
+                  }
+                ]
+              }
+            }
+          },
+          {
+            "server_opening_event": {
+              "topologyId": "42",
+              "address": "a:27017"
+            }
+          },
+          {
+            "server_description_changed_event": {
+              "topologyId": "42",
+              "address": "a:27017",
+              "previousDescription": {
+                "address": "a:27017",
+                "arbiters": [],
+                "hosts": [],
+                "passives": [],
+                "type": "Unknown"
+              },
+              "newDescription": {
+                "address": "a:27017",
+                "arbiters": [],
+                "hosts": [],
+                "passives": [],
+                "type": "LoadBalancer"
+              }
+            }
+          },
+          {
+            "topology_description_changed_event": {
+              "topologyId": "42",
+              "previousDescription": {
+                "topologyType": "LoadBalanced",
+                "servers": [
+                  {
+                    "address": "a:27017",
+                    "arbiters": [],
+                    "hosts": [],
+                    "passives": [],
+                    "type": "Unknown"
+                  }
+                ]
+              },
+              "newDescription": {
+                "topologyType": "LoadBalanced",
+                "servers": [
+                  {
+                    "address": "a:27017",
+                    "arbiters": [],
+                    "hosts": [],
+                    "passives": [],
+                    "type": "LoadBalancer"
+                  }
+                ]
+              }
+            }
+          }
+        ]
+      }
+    }
+  ]
+}
diff --git a/test/spec/server-discovery-and-monitoring/monitoring/load_balancer.yml b/test/spec/server-discovery-and-monitoring/monitoring/load_balancer.yml
new file mode 100644
index 0000000000..b4eec2d2c6
--- /dev/null
+++ b/test/spec/server-discovery-and-monitoring/monitoring/load_balancer.yml
@@ -0,0 +1,65 @@
+description: "Monitoring a load balancer"
+uri: "mongodb://a:27017/?loadBalanced=true"
+phases:
+  -
+    outcome:
+      events:
+        -
+          topology_opening_event:
+            topologyId: "42"
+        -
+          topology_description_changed_event:
+            topologyId: "42"
+            previousDescription:
+              topologyType: "Unknown"
+              servers: []
+            newDescription:
+              topologyType: "LoadBalanced"
+              servers:
+                -
+                  address: "a:27017"
+                  arbiters: []
+                  hosts: []
+                  passives: []
+                  type: "Unknown"
+        -
+          server_opening_event:
+            topologyId: "42"
+            address: "a:27017"
+        -
+          server_description_changed_event:
+            topologyId: "42"
+            address: "a:27017"
+            previousDescription:
+              address: "a:27017"
+              arbiters: []
+              hosts: []
+              passives: []
+              type: "Unknown"
+            newDescription:
+              address: "a:27017"
+              arbiters: []
+              hosts: []
+              passives: []
+              type: "LoadBalancer"
+        -
+          topology_description_changed_event:
+            topologyId: "42"
+            previousDescription:
+              topologyType: "LoadBalanced"
+              servers:
+                -
+                  address: "a:27017"
+                  arbiters: []
+                  hosts: []
+                  passives: []
+                  type: "Unknown"
+            newDescription:
+              topologyType: "LoadBalanced"
+              servers:
+                -
+                  address: "a:27017"
+                  arbiters: []
+                  hosts: []
+                  passives: []
+                  type: "LoadBalancer"
diff --git a/test/spec/server-discovery-and-monitoring/monitoring/replica_set_with_no_primary.json b/test/spec/server-discovery-and-monitoring/monitoring/replica_set_with_no_primary.json
index 33010d49fb..950e32efe1 100644
--- a/test/spec/server-discovery-and-monitoring/monitoring/replica_set_with_no_primary.json
+++ b/test/spec/server-discovery-and-monitoring/monitoring/replica_set_with_no_primary.json
@@ -8,7 +8,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": false,
+            "helloOk": true,
+            "isWritablePrimary": false,
             "secondary": true,
             "setName": "rs",
             "setVersion": 1,
@@ -18,7 +19,7 @@
               "b:27017"
             ],
             "minWireVersion": 0,
-            "maxWireVersion": 4
+            "maxWireVersion": 6
           }
         ]
       ],
diff --git a/test/spec/server-discovery-and-monitoring/monitoring/replica_set_with_no_primary.yml b/test/spec/server-discovery-and-monitoring/monitoring/replica_set_with_no_primary.yml
index ed992f849c..ce9cdf46e6 100644
--- a/test/spec/server-discovery-and-monitoring/monitoring/replica_set_with_no_primary.yml
+++ b/test/spec/server-discovery-and-monitoring/monitoring/replica_set_with_no_primary.yml
@@ -1,112 +1,112 @@
 description: "Monitoring a topology that is a replica set with no primary connected"
 uri: "mongodb://a,b"
-phases: 
-  - 
-    responses: 
-      - 
+phases:
+  -
+    responses:
+      -
         - "a:27017"
-        - 
+        -
           ok: 1
-          ismaster: false
+          helloOk: true
+          isWritablePrimary: false
           secondary: true
           setName: "rs"
           setVersion: 1
           primary: "b:27017"
-          hosts: 
+          hosts:
             - "a:27017"
             - "b:27017"
           minWireVersion: 0
-          maxWireVersion: 4
-    outcome: 
-      events: 
-        - 
-          topology_opening_event: 
+          maxWireVersion: 6
+    outcome:
+      events:
+        -
+          topology_opening_event:
             topologyId: "42"
-        - 
-          topology_description_changed_event: 
+        -
+          topology_description_changed_event:
             topologyId: "42"
-            previousDescription: 
+            previousDescription:
               topologyType: "Unknown"
               servers: []
-            newDescription: 
+            newDescription:
               topologyType: "Unknown"
-              servers: 
-                - 
+              servers:
+                -
                   address: "a:27017"
                   arbiters: []
                   hosts: []
                   passives: []
                   type: "Unknown"
-                - 
+                -
                   address: "b:27017"
                   arbiters: []
                   hosts: []
                   passives: []
                   type: "Unknown"
-        - 
-          server_opening_event: 
+        -
+          server_opening_event:
             topologyId: "42"
             address: "a:27017"
-        - 
-          server_opening_event: 
+        -
+          server_opening_event:
             topologyId: "42"
             address: "b:27017"
-        - 
-          server_description_changed_event: 
+        -
+          server_description_changed_event:
             topologyId: "42"
             address: "a:27017"
-            previousDescription: 
+            previousDescription:
               address: "a:27017"
               arbiters: []
               hosts: []
               passives: []
               type: "Unknown"
-            newDescription: 
+            newDescription:
               address: "a:27017"
               arbiters: []
-              hosts: 
+              hosts:
                 - "a:27017"
                 - "b:27017"
               passives: []
               primary: "b:27017"
               setName: "rs"
               type: "RSSecondary"
-        - 
-          topology_description_changed_event: 
+        -
+          topology_description_changed_event:
             topologyId: "42"
-            previousDescription: 
+            previousDescription:
               topologyType: "Unknown"
-              servers: 
-                - 
+              servers:
+                -
                   address: "a:27017"
                   arbiters: []
                   hosts: []
                   passives: []
                   type: "Unknown"
-                - 
+                -
                   address: "b:27017"
                   arbiters: []
                   hosts: []
                   passives: []
                   type: "Unknown"
-            newDescription: 
+            newDescription:
               topologyType: "ReplicaSetNoPrimary"
               setName: "rs"
-              servers: 
-                - 
+              servers:
+                -
                   address: "a:27017"
                   arbiters: []
-                  hosts: 
+                  hosts:
                     - "a:27017"
                     - "b:27017"
                   passives: []
                   primary: "b:27017"
                   setName: "rs"
                   type: "RSSecondary"
-                - 
+                -
                   address: "b:27017"
                   arbiters: []
                   hosts: []
                   passives: []
                   type: "PossiblePrimary"
-
diff --git a/test/spec/server-discovery-and-monitoring/monitoring/replica_set_with_primary.json b/test/spec/server-discovery-and-monitoring/monitoring/replica_set_with_primary.json
index 04caeba652..2ad94d6e6a 100644
--- a/test/spec/server-discovery-and-monitoring/monitoring/replica_set_with_primary.json
+++ b/test/spec/server-discovery-and-monitoring/monitoring/replica_set_with_primary.json
@@ -8,7 +8,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "setName": "rs",
             "setVersion": 1,
             "primary": "a:27017",
@@ -17,7 +18,7 @@
               "b:27017"
             ],
             "minWireVersion": 0,
-            "maxWireVersion": 4
+            "maxWireVersion": 6
           }
         ]
       ],
diff --git a/test/spec/server-discovery-and-monitoring/monitoring/replica_set_with_primary.yml b/test/spec/server-discovery-and-monitoring/monitoring/replica_set_with_primary.yml
index e42735d41c..2c78919063 100644
--- a/test/spec/server-discovery-and-monitoring/monitoring/replica_set_with_primary.yml
+++ b/test/spec/server-discovery-and-monitoring/monitoring/replica_set_with_primary.yml
@@ -1,111 +1,111 @@
 description: "Monitoring a topology that is a replica set with a primary connected"
 uri: "mongodb://a,b"
-phases: 
-  - 
-    responses: 
-      - 
+phases:
+  -
+    responses:
+      -
         - "a:27017"
-        - 
+        -
           ok: 1
-          ismaster: true
+          helloOk: true
+          isWritablePrimary: true
           setName: "rs"
           setVersion: 1
           primary: "a:27017"
-          hosts: 
+          hosts:
             - "a:27017"
             - "b:27017"
           minWireVersion: 0
-          maxWireVersion: 4
-    outcome: 
-      events: 
-        - 
-          topology_opening_event: 
+          maxWireVersion: 6
+    outcome:
+      events:
+        -
+          topology_opening_event:
             topologyId: "42"
-        - 
-          topology_description_changed_event: 
+        -
+          topology_description_changed_event:
             topologyId: "42"
-            previousDescription: 
+            previousDescription:
               topologyType: "Unknown"
               servers: []
-            newDescription: 
+            newDescription:
               topologyType: "Unknown"
-              servers: 
-                - 
+              servers:
+                -
                   address: "a:27017"
                   arbiters: []
                   hosts: []
                   passives: []
                   type: "Unknown"
-                - 
+                -
                   address: "b:27017"
                   arbiters: []
                   hosts: []
                   passives: []
                   type: "Unknown"
-        - 
-          server_opening_event: 
+        -
+          server_opening_event:
             topologyId: "42"
             address: "a:27017"
-        - 
-          server_opening_event: 
+        -
+          server_opening_event:
             topologyId: "42"
             address: "b:27017"
-        - 
-          server_description_changed_event: 
+        -
+          server_description_changed_event:
             topologyId: "42"
             address: "a:27017"
-            previousDescription: 
+            previousDescription:
               address: "a:27017"
               arbiters: []
               hosts: []
               passives: []
               type: "Unknown"
-            newDescription: 
+            newDescription:
               address: "a:27017"
               arbiters: []
-              hosts: 
+              hosts:
                 - "a:27017"
                 - "b:27017"
               passives: []
               primary: "a:27017"
               setName: "rs"
               type: "RSPrimary"
-        - 
-          topology_description_changed_event: 
+        -
+          topology_description_changed_event:
             topologyId: "42"
-            previousDescription: 
+            previousDescription:
               topologyType: "Unknown"
-              servers: 
-                - 
+              servers:
+                -
                   address: "a:27017"
                   arbiters: []
                   hosts: []
                   passives: []
                   type: "Unknown"
-                - 
+                -
                   address: "b:27017"
                   arbiters: []
                   hosts: []
                   passives: []
                   type: "Unknown"
-            newDescription: 
+            newDescription:
               topologyType: "ReplicaSetWithPrimary"
               setName: "rs"
-              servers: 
-                - 
+              servers:
+                -
                   address: "a:27017"
                   arbiters: []
-                  hosts: 
+                  hosts:
                     - "a:27017"
                     - "b:27017"
                   passives: []
                   primary: "a:27017"
                   setName: "rs"
                   type: "RSPrimary"
-                - 
+                -
                   address: "b:27017"
                   arbiters: []
                   hosts: []
                   passives: []
                   type: "Unknown"
-
diff --git a/test/spec/server-discovery-and-monitoring/monitoring/replica_set_with_removal.json b/test/spec/server-discovery-and-monitoring/monitoring/replica_set_with_removal.json
index 3cad92d6b8..ae28faa30c 100644
--- a/test/spec/server-discovery-and-monitoring/monitoring/replica_set_with_removal.json
+++ b/test/spec/server-discovery-and-monitoring/monitoring/replica_set_with_removal.json
@@ -60,7 +60,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "setName": "rs",
             "setVersion": 1,
             "primary": "a:27017",
@@ -68,14 +69,15 @@
               "a:27017"
             ],
             "minWireVersion": 0,
-            "maxWireVersion": 4
+            "maxWireVersion": 6
           }
         ],
         [
           "b:27017",
           {
             "ok": 1,
-            "ismaster": true
+            "helloOk": true,
+            "isWritablePrimary": true
           }
         ]
       ],
diff --git a/test/spec/server-discovery-and-monitoring/monitoring/replica_set_with_removal.yml b/test/spec/server-discovery-and-monitoring/monitoring/replica_set_with_removal.yml
index 754d8270e6..2471f47680 100644
--- a/test/spec/server-discovery-and-monitoring/monitoring/replica_set_with_removal.yml
+++ b/test/spec/server-discovery-and-monitoring/monitoring/replica_set_with_removal.yml
@@ -43,17 +43,18 @@ phases:
         - "a:27017"
         - {
             ok: 1,
-            ismaster: true,
+            helloOk: true,
+            isWritablePrimary: true,
             setName: "rs",
             setVersion: 1.0,
             primary: "a:27017",
             hosts: [ "a:27017" ],
             minWireVersion: 0,
-            maxWireVersion: 4
+            maxWireVersion: 6
           }
       -
         - "b:27017"
-        - { ok: 1, ismaster: true }
+        - { ok: 1, helloOk: true, isWritablePrimary: true }
     outcome:
       events:
         -
diff --git a/test/spec/server-discovery-and-monitoring/monitoring/required_replica_set.json b/test/spec/server-discovery-and-monitoring/monitoring/required_replica_set.json
index 0f64bde118..401c5d99c5 100644
--- a/test/spec/server-discovery-and-monitoring/monitoring/required_replica_set.json
+++ b/test/spec/server-discovery-and-monitoring/monitoring/required_replica_set.json
@@ -8,7 +8,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "setName": "rs",
             "setVersion": 1,
             "primary": "a:27017",
@@ -17,7 +18,7 @@
               "b:27017"
             ],
             "minWireVersion": 0,
-            "maxWireVersion": 4
+            "maxWireVersion": 6
           }
         ]
       ],
diff --git a/test/spec/server-discovery-and-monitoring/monitoring/required_replica_set.yml b/test/spec/server-discovery-and-monitoring/monitoring/required_replica_set.yml
index 32678a6bbe..7a060128f3 100644
--- a/test/spec/server-discovery-and-monitoring/monitoring/required_replica_set.yml
+++ b/test/spec/server-discovery-and-monitoring/monitoring/required_replica_set.yml
@@ -7,13 +7,14 @@ phases:
         - "a:27017"
         - {
             ok: 1,
-            ismaster: true,
+            helloOk: true,
+            isWritablePrimary: true,
             setName: "rs",
             setVersion: 1.0,
             primary: "a:27017",
             hosts: [ "a:27017", "b:27017" ],
             minWireVersion: 0,
-            maxWireVersion: 4
+            maxWireVersion: 6
           }
     outcome:
       events:
diff --git a/test/spec/server-discovery-and-monitoring/monitoring/standalone.json b/test/spec/server-discovery-and-monitoring/monitoring/standalone.json
index 3ff10f820f..821a1525d4 100644
--- a/test/spec/server-discovery-and-monitoring/monitoring/standalone.json
+++ b/test/spec/server-discovery-and-monitoring/monitoring/standalone.json
@@ -8,9 +8,10 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "minWireVersion": 0,
-            "maxWireVersion": 4
+            "maxWireVersion": 6
           }
         ]
       ],
diff --git a/test/spec/server-discovery-and-monitoring/monitoring/standalone.yml b/test/spec/server-discovery-and-monitoring/monitoring/standalone.yml
index 8787edce34..d9f6bcfaf3 100644
--- a/test/spec/server-discovery-and-monitoring/monitoring/standalone.yml
+++ b/test/spec/server-discovery-and-monitoring/monitoring/standalone.yml
@@ -5,7 +5,7 @@ phases:
     responses:
       -
         - "a:27017"
-        - { ok: 1, ismaster: true, minWireVersion: 0, maxWireVersion: 4 }
+        - { ok: 1, helloOk: true, isWritablePrimary: true, minWireVersion: 0, maxWireVersion: 6 }
 
     outcome:
       events:
diff --git a/test/spec/server-discovery-and-monitoring/monitoring/standalone_suppress_equal_description_changes.json b/test/spec/server-discovery-and-monitoring/monitoring/standalone_suppress_equal_description_changes.json
index ceab1449cc..5958e2d26c 100644
--- a/test/spec/server-discovery-and-monitoring/monitoring/standalone_suppress_equal_description_changes.json
+++ b/test/spec/server-discovery-and-monitoring/monitoring/standalone_suppress_equal_description_changes.json
@@ -8,18 +8,20 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "minWireVersion": 0,
-            "maxWireVersion": 4
+            "maxWireVersion": 6
           }
         ],
         [
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "minWireVersion": 0,
-            "maxWireVersion": 4
+            "maxWireVersion": 6
           }
         ]
       ],
diff --git a/test/spec/server-discovery-and-monitoring/monitoring/standalone_suppress_equal_description_changes.yml b/test/spec/server-discovery-and-monitoring/monitoring/standalone_suppress_equal_description_changes.yml
index 229f8d7c69..f2f83ffbac 100644
--- a/test/spec/server-discovery-and-monitoring/monitoring/standalone_suppress_equal_description_changes.yml
+++ b/test/spec/server-discovery-and-monitoring/monitoring/standalone_suppress_equal_description_changes.yml
@@ -5,10 +5,10 @@ phases:
     responses:
       -
         - "a:27017"
-        - { ok: 1, ismaster: true, minWireVersion: 0, maxWireVersion: 4 }
+        - { ok: 1, helloOk: true, isWritablePrimary: true, minWireVersion: 0, maxWireVersion: 6 }
       -
         - "a:27017"
-        - { ok: 1, ismaster: true, minWireVersion: 0, maxWireVersion: 4 }
+        - { ok: 1, helloOk: true, isWritablePrimary: true, minWireVersion: 0, maxWireVersion: 6 }
 
     outcome:
       events:
diff --git a/test/spec/server-discovery-and-monitoring/rs/compatible.json b/test/spec/server-discovery-and-monitoring/rs/compatible.json
index d670770f6d..444b13e9d5 100644
--- a/test/spec/server-discovery-and-monitoring/rs/compatible.json
+++ b/test/spec/server-discovery-and-monitoring/rs/compatible.json
@@ -8,7 +8,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "setName": "rs",
             "hosts": [
               "a:27017",
@@ -22,7 +23,8 @@
           "b:27017",
           {
             "ok": 1,
-            "ismaster": false,
+            "helloOk": true,
+            "isWritablePrimary": false,
             "secondary": true,
             "setName": "rs",
             "hosts": [
diff --git a/test/spec/server-discovery-and-monitoring/rs/compatible.yml b/test/spec/server-discovery-and-monitoring/rs/compatible.yml
index 6fade62db9..8b5d9f456a 100644
--- a/test/spec/server-discovery-and-monitoring/rs/compatible.yml
+++ b/test/spec/server-discovery-and-monitoring/rs/compatible.yml
@@ -7,7 +7,8 @@ phases: [
         responses: [
                 ["a:27017", {
                     ok: 1,
-                    ismaster: true,
+                    helloOk: true,
+                    isWritablePrimary: true,
                     setName: "rs",
                     hosts: ["a:27017", "b:27017"],
                     minWireVersion: 0,
@@ -15,7 +16,8 @@ phases: [
                 }],
                 ["b:27017", {
                     ok: 1,
-                    ismaster: false,
+                    helloOk: true,
+                    isWritablePrimary: false,
                     secondary: true,
                     setName: "rs",
                     hosts: ["a:27017", "b:27017"],
diff --git a/test/spec/server-discovery-and-monitoring/rs/compatible_unknown.json b/test/spec/server-discovery-and-monitoring/rs/compatible_unknown.json
index 1105da8764..cf92dd1ed3 100644
--- a/test/spec/server-discovery-and-monitoring/rs/compatible_unknown.json
+++ b/test/spec/server-discovery-and-monitoring/rs/compatible_unknown.json
@@ -8,7 +8,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "setName": "rs",
             "hosts": [
               "a:27017",
diff --git a/test/spec/server-discovery-and-monitoring/rs/compatible_unknown.yml b/test/spec/server-discovery-and-monitoring/rs/compatible_unknown.yml
index b36b69dd4a..643e849819 100644
--- a/test/spec/server-discovery-and-monitoring/rs/compatible_unknown.yml
+++ b/test/spec/server-discovery-and-monitoring/rs/compatible_unknown.yml
@@ -7,7 +7,8 @@ phases: [
         responses: [
                 ["a:27017", {
                     ok: 1,
-                    ismaster: true,
+                    helloOk: true,
+                    isWritablePrimary: true,
                     setName: "rs",
                     hosts: ["a:27017", "b:27017"],
                     minWireVersion: 0,
diff --git a/test/spec/server-discovery-and-monitoring/rs/discover_arbiters.json b/test/spec/server-discovery-and-monitoring/rs/discover_arbiters.json
index ad337c127a..53709b0cee 100644
--- a/test/spec/server-discovery-and-monitoring/rs/discover_arbiters.json
+++ b/test/spec/server-discovery-and-monitoring/rs/discover_arbiters.json
@@ -8,7 +8,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
diff --git a/test/spec/server-discovery-and-monitoring/rs/discover_arbiters.yml b/test/spec/server-discovery-and-monitoring/rs/discover_arbiters.yml
index 15cd0308d5..67d29eadb5 100644
--- a/test/spec/server-discovery-and-monitoring/rs/discover_arbiters.yml
+++ b/test/spec/server-discovery-and-monitoring/rs/discover_arbiters.yml
@@ -10,7 +10,8 @@ phases: [
                 ["a:27017", {
 
                     ok: 1,
-                    ismaster: true,
+                    helloOk: true,
+                    isWritablePrimary: true,
                     hosts: ["a:27017"],
                     arbiters: ["b:27017"],
                     setName: "rs",
diff --git a/test/spec/server-discovery-and-monitoring/rs/discover_arbiters_replicaset.json b/test/spec/server-discovery-and-monitoring/rs/discover_arbiters_replicaset.json
index dc00dca5f0..64fb49f4fc 100644
--- a/test/spec/server-discovery-and-monitoring/rs/discover_arbiters_replicaset.json
+++ b/test/spec/server-discovery-and-monitoring/rs/discover_arbiters_replicaset.json
@@ -8,7 +8,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
diff --git a/test/spec/server-discovery-and-monitoring/rs/discover_arbiters_replicaset.yml b/test/spec/server-discovery-and-monitoring/rs/discover_arbiters_replicaset.yml
index c9255aa3ef..c7edb52b01 100644
--- a/test/spec/server-discovery-and-monitoring/rs/discover_arbiters_replicaset.yml
+++ b/test/spec/server-discovery-and-monitoring/rs/discover_arbiters_replicaset.yml
@@ -10,7 +10,8 @@ phases: [
                 ["a:27017", {
 
                     ok: 1,
-                    ismaster: true,
+                    helloOk: true,
+                    isWritablePrimary: true,
                     hosts: ["a:27017"],
                     arbiters: ["b:27017"],
                     setName: "rs",
diff --git a/test/spec/server-discovery-and-monitoring/rs/discover_ghost.json b/test/spec/server-discovery-and-monitoring/rs/discover_ghost.json
index 1e2ca91bcb..2e24c83e0b 100644
--- a/test/spec/server-discovery-and-monitoring/rs/discover_ghost.json
+++ b/test/spec/server-discovery-and-monitoring/rs/discover_ghost.json
@@ -8,7 +8,8 @@
           "b:27017",
           {
             "ok": 1,
-            "ismaster": false,
+            "helloOk": true,
+            "isWritablePrimary": false,
             "isreplicaset": true,
             "minWireVersion": 0,
             "maxWireVersion": 6
diff --git a/test/spec/server-discovery-and-monitoring/rs/discover_ghost.yml b/test/spec/server-discovery-and-monitoring/rs/discover_ghost.yml
index 9b2ddd6a85..e613f684b4 100644
--- a/test/spec/server-discovery-and-monitoring/rs/discover_ghost.yml
+++ b/test/spec/server-discovery-and-monitoring/rs/discover_ghost.yml
@@ -10,7 +10,8 @@ phases: [
                 ["b:27017", {
 
                     ok: 1,
-                    ismaster: false,
+                    helloOk: true,
+                    isWritablePrimary: false,
                     isreplicaset: true,
                     minWireVersion: 0,
                     maxWireVersion: 6
diff --git a/test/spec/server-discovery-and-monitoring/rs/discover_ghost_replicaset.json b/test/spec/server-discovery-and-monitoring/rs/discover_ghost_replicaset.json
index df504b6ca4..cf5fe83a54 100644
--- a/test/spec/server-discovery-and-monitoring/rs/discover_ghost_replicaset.json
+++ b/test/spec/server-discovery-and-monitoring/rs/discover_ghost_replicaset.json
@@ -8,7 +8,8 @@
           "b:27017",
           {
             "ok": 1,
-            "ismaster": false,
+            "helloOk": true,
+            "isWritablePrimary": false,
             "isreplicaset": true,
             "minWireVersion": 0,
             "maxWireVersion": 6
diff --git a/test/spec/server-discovery-and-monitoring/rs/discover_ghost_replicaset.yml b/test/spec/server-discovery-and-monitoring/rs/discover_ghost_replicaset.yml
index 638301e63e..75ec3e64a9 100644
--- a/test/spec/server-discovery-and-monitoring/rs/discover_ghost_replicaset.yml
+++ b/test/spec/server-discovery-and-monitoring/rs/discover_ghost_replicaset.yml
@@ -10,7 +10,8 @@ phases: [
                 ["b:27017", {
 
                     ok: 1,
-                    ismaster: false,
+                    helloOk: true,
+                    isWritablePrimary: false,
                     isreplicaset: true,
                     minWireVersion: 0,
                     maxWireVersion: 6
diff --git a/test/spec/server-discovery-and-monitoring/rs/discover_hidden.json b/test/spec/server-discovery-and-monitoring/rs/discover_hidden.json
index cb68120eaf..e4a90f1f9c 100644
--- a/test/spec/server-discovery-and-monitoring/rs/discover_hidden.json
+++ b/test/spec/server-discovery-and-monitoring/rs/discover_hidden.json
@@ -8,7 +8,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": false,
+            "helloOk": true,
+            "isWritablePrimary": false,
             "secondary": true,
             "hidden": true,
             "hosts": [
diff --git a/test/spec/server-discovery-and-monitoring/rs/discover_hidden.yml b/test/spec/server-discovery-and-monitoring/rs/discover_hidden.yml
index a54069c338..64ed1d82b9 100644
--- a/test/spec/server-discovery-and-monitoring/rs/discover_hidden.yml
+++ b/test/spec/server-discovery-and-monitoring/rs/discover_hidden.yml
@@ -10,7 +10,8 @@ phases: [
                 ["a:27017", {
 
                     ok: 1,
-                    ismaster: false,
+                    helloOk: true,
+                    isWritablePrimary: false,
                     secondary: true,
                     hidden: true,
                     hosts: ["c:27017", "d:27017"],
diff --git a/test/spec/server-discovery-and-monitoring/rs/discover_hidden_replicaset.json b/test/spec/server-discovery-and-monitoring/rs/discover_hidden_replicaset.json
index 216328dfa5..04420596f0 100644
--- a/test/spec/server-discovery-and-monitoring/rs/discover_hidden_replicaset.json
+++ b/test/spec/server-discovery-and-monitoring/rs/discover_hidden_replicaset.json
@@ -8,7 +8,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": false,
+            "helloOk": true,
+            "isWritablePrimary": false,
             "secondary": true,
             "hidden": true,
             "hosts": [
diff --git a/test/spec/server-discovery-and-monitoring/rs/discover_hidden_replicaset.yml b/test/spec/server-discovery-and-monitoring/rs/discover_hidden_replicaset.yml
index 1b6f41b01f..614a39d482 100644
--- a/test/spec/server-discovery-and-monitoring/rs/discover_hidden_replicaset.yml
+++ b/test/spec/server-discovery-and-monitoring/rs/discover_hidden_replicaset.yml
@@ -10,7 +10,8 @@ phases: [
                 ["a:27017", {
 
                     ok: 1,
-                    ismaster: false,
+                    helloOk: true,
+                    isWritablePrimary: false,
                     secondary: true,
                     hidden: true,
                     hosts: ["c:27017", "d:27017"],
diff --git a/test/spec/server-discovery-and-monitoring/rs/discover_passives.json b/test/spec/server-discovery-and-monitoring/rs/discover_passives.json
index 05922dc51c..30258409f6 100644
--- a/test/spec/server-discovery-and-monitoring/rs/discover_passives.json
+++ b/test/spec/server-discovery-and-monitoring/rs/discover_passives.json
@@ -8,7 +8,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
@@ -43,7 +44,8 @@
           "b:27017",
           {
             "ok": 1,
-            "ismaster": false,
+            "helloOk": true,
+            "isWritablePrimary": false,
             "secondary": true,
             "passive": true,
             "hosts": [
diff --git a/test/spec/server-discovery-and-monitoring/rs/discover_passives.yml b/test/spec/server-discovery-and-monitoring/rs/discover_passives.yml
index 3baed64aa0..637d86d7f1 100644
--- a/test/spec/server-discovery-and-monitoring/rs/discover_passives.yml
+++ b/test/spec/server-discovery-and-monitoring/rs/discover_passives.yml
@@ -10,7 +10,8 @@ phases: [
                 ["a:27017", {
 
                     ok: 1,
-                    ismaster: true,
+                    helloOk: true,
+                    isWritablePrimary: true,
                     hosts: ["a:27017"],
                     passives: ["b:27017"],
                     setName: "rs",
@@ -46,7 +47,8 @@ phases: [
                 ["b:27017", {
 
                     ok: 1,
-                    ismaster: false,
+                    helloOk: true,
+                    isWritablePrimary: false,
                     secondary: true,
                     passive: true,
                     hosts: ["a:27017"],
diff --git a/test/spec/server-discovery-and-monitoring/rs/discover_passives_replicaset.json b/test/spec/server-discovery-and-monitoring/rs/discover_passives_replicaset.json
index f9d8c2e032..266eaa5234 100644
--- a/test/spec/server-discovery-and-monitoring/rs/discover_passives_replicaset.json
+++ b/test/spec/server-discovery-and-monitoring/rs/discover_passives_replicaset.json
@@ -8,7 +8,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
@@ -43,7 +44,8 @@
           "b:27017",
           {
             "ok": 1,
-            "ismaster": false,
+            "helloOk": true,
+            "isWritablePrimary": false,
             "secondary": true,
             "passive": true,
             "hosts": [
diff --git a/test/spec/server-discovery-and-monitoring/rs/discover_passives_replicaset.yml b/test/spec/server-discovery-and-monitoring/rs/discover_passives_replicaset.yml
index 6d34516afc..a5ced995d3 100644
--- a/test/spec/server-discovery-and-monitoring/rs/discover_passives_replicaset.yml
+++ b/test/spec/server-discovery-and-monitoring/rs/discover_passives_replicaset.yml
@@ -10,7 +10,8 @@ phases: [
                 ["a:27017", {
 
                     ok: 1,
-                    ismaster: true,
+                    helloOk: true,
+                    isWritablePrimary: true,
                     hosts: ["a:27017"],
                     passives: ["b:27017"],
                     setName: "rs",
@@ -46,7 +47,8 @@ phases: [
                 ["b:27017", {
 
                     ok: 1,
-                    ismaster: false,
+                    helloOk: true,
+                    isWritablePrimary: false,
                     secondary: true,
                     passive: true,
                     hosts: ["a:27017"],
diff --git a/test/spec/server-discovery-and-monitoring/rs/discover_primary.json b/test/spec/server-discovery-and-monitoring/rs/discover_primary.json
index b9032144d4..2d1292bbd4 100644
--- a/test/spec/server-discovery-and-monitoring/rs/discover_primary.json
+++ b/test/spec/server-discovery-and-monitoring/rs/discover_primary.json
@@ -8,7 +8,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "setName": "rs",
             "hosts": [
               "a:27017",
diff --git a/test/spec/server-discovery-and-monitoring/rs/discover_primary.yml b/test/spec/server-discovery-and-monitoring/rs/discover_primary.yml
index 505acfb86f..eaedf130ba 100644
--- a/test/spec/server-discovery-and-monitoring/rs/discover_primary.yml
+++ b/test/spec/server-discovery-and-monitoring/rs/discover_primary.yml
@@ -10,7 +10,8 @@ phases: [
                 ["a:27017", {
 
                     ok: 1,
-                    ismaster: true,
+                    helloOk: true,
+                    isWritablePrimary: true,
                     setName: "rs",
                     hosts: ["a:27017", "b:27017"],
                     minWireVersion: 0,
diff --git a/test/spec/server-discovery-and-monitoring/rs/discover_primary_replicaset.json b/test/spec/server-discovery-and-monitoring/rs/discover_primary_replicaset.json
index 6f639b1c7e..54dfefba5f 100644
--- a/test/spec/server-discovery-and-monitoring/rs/discover_primary_replicaset.json
+++ b/test/spec/server-discovery-and-monitoring/rs/discover_primary_replicaset.json
@@ -8,7 +8,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "setName": "rs",
             "hosts": [
               "a:27017",
diff --git a/test/spec/server-discovery-and-monitoring/rs/discover_primary_replicaset.yml b/test/spec/server-discovery-and-monitoring/rs/discover_primary_replicaset.yml
index 330ed20b51..7879701bb2 100644
--- a/test/spec/server-discovery-and-monitoring/rs/discover_primary_replicaset.yml
+++ b/test/spec/server-discovery-and-monitoring/rs/discover_primary_replicaset.yml
@@ -10,7 +10,8 @@ phases: [
                 ["a:27017", {
 
                     ok: 1,
-                    ismaster: true,
+                    helloOk: true,
+                    isWritablePrimary: true,
                     setName: "rs",
                     hosts: ["a:27017", "b:27017"],
                     minWireVersion: 0,
diff --git a/test/spec/server-discovery-and-monitoring/rs/discover_rsother.json b/test/spec/server-discovery-and-monitoring/rs/discover_rsother.json
index 2cf5a5a6db..4ab25667f0 100644
--- a/test/spec/server-discovery-and-monitoring/rs/discover_rsother.json
+++ b/test/spec/server-discovery-and-monitoring/rs/discover_rsother.json
@@ -8,7 +8,8 @@
           "b:27017",
           {
             "ok": 1,
-            "ismaster": false,
+            "helloOk": true,
+            "isWritablePrimary": false,
             "secondary": false,
             "hosts": [
               "c:27017",
diff --git a/test/spec/server-discovery-and-monitoring/rs/discover_rsother.yml b/test/spec/server-discovery-and-monitoring/rs/discover_rsother.yml
index 1f06c78566..d78e70c5d7 100644
--- a/test/spec/server-discovery-and-monitoring/rs/discover_rsother.yml
+++ b/test/spec/server-discovery-and-monitoring/rs/discover_rsother.yml
@@ -10,7 +10,8 @@ phases: [
                 ["b:27017", {
 
                     ok: 1,
-                    ismaster: false,
+                    helloOk: true,
+                    isWritablePrimary: false,
                     secondary: false,
                     hosts: ["c:27017", "d:27017"],
                     setName: "rs",
diff --git a/test/spec/server-discovery-and-monitoring/rs/discover_rsother_replicaset.json b/test/spec/server-discovery-and-monitoring/rs/discover_rsother_replicaset.json
index d9420ca529..e3958d70ad 100644
--- a/test/spec/server-discovery-and-monitoring/rs/discover_rsother_replicaset.json
+++ b/test/spec/server-discovery-and-monitoring/rs/discover_rsother_replicaset.json
@@ -8,7 +8,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": false,
+            "helloOk": true,
+            "isWritablePrimary": false,
             "secondary": true,
             "hidden": true,
             "hosts": [
@@ -24,7 +25,8 @@
           "b:27017",
           {
             "ok": 1,
-            "ismaster": false,
+            "helloOk": true,
+            "isWritablePrimary": false,
             "secondary": false,
             "hosts": [
               "c:27017",
diff --git a/test/spec/server-discovery-and-monitoring/rs/discover_rsother_replicaset.yml b/test/spec/server-discovery-and-monitoring/rs/discover_rsother_replicaset.yml
index 24f4e302be..19159d1efe 100644
--- a/test/spec/server-discovery-and-monitoring/rs/discover_rsother_replicaset.yml
+++ b/test/spec/server-discovery-and-monitoring/rs/discover_rsother_replicaset.yml
@@ -10,7 +10,8 @@ phases: [
                 ["a:27017", {
 
                     ok: 1,
-                    ismaster: false,
+                    helloOk: true,
+                    isWritablePrimary: false,
                     secondary: true,
                     hidden: true,
                     hosts: ["c:27017", "d:27017"],
@@ -21,7 +22,8 @@ phases: [
                 ["b:27017", {
 
                     ok: 1,
-                    ismaster: false,
+                    helloOk: true,
+                    isWritablePrimary: false,
                     secondary: false,
                     hosts: ["c:27017", "d:27017"],
                     setName: "rs",
diff --git a/test/spec/server-discovery-and-monitoring/rs/discover_secondary.json b/test/spec/server-discovery-and-monitoring/rs/discover_secondary.json
index 02123625a7..22325d4e03 100644
--- a/test/spec/server-discovery-and-monitoring/rs/discover_secondary.json
+++ b/test/spec/server-discovery-and-monitoring/rs/discover_secondary.json
@@ -8,7 +8,8 @@
           "b:27017",
           {
             "ok": 1,
-            "ismaster": false,
+            "helloOk": true,
+            "isWritablePrimary": false,
             "secondary": true,
             "setName": "rs",
             "hosts": [
diff --git a/test/spec/server-discovery-and-monitoring/rs/discover_secondary.yml b/test/spec/server-discovery-and-monitoring/rs/discover_secondary.yml
index 3fdbccb283..184849d3ff 100644
--- a/test/spec/server-discovery-and-monitoring/rs/discover_secondary.yml
+++ b/test/spec/server-discovery-and-monitoring/rs/discover_secondary.yml
@@ -10,7 +10,8 @@ phases: [
                 ["b:27017", {
 
                     ok: 1,
-                    ismaster: false,
+                    helloOk: true,
+                    isWritablePrimary: false,
                     secondary: true,
                     setName: "rs",
                     hosts: ["a:27017", "b:27017"],
diff --git a/test/spec/server-discovery-and-monitoring/rs/discover_secondary_replicaset.json b/test/spec/server-discovery-and-monitoring/rs/discover_secondary_replicaset.json
index 3dde3166b4..d903b6444d 100644
--- a/test/spec/server-discovery-and-monitoring/rs/discover_secondary_replicaset.json
+++ b/test/spec/server-discovery-and-monitoring/rs/discover_secondary_replicaset.json
@@ -8,7 +8,8 @@
           "b:27017",
           {
             "ok": 1,
-            "ismaster": false,
+            "helloOk": true,
+            "isWritablePrimary": false,
             "secondary": true,
             "setName": "rs",
             "hosts": [
diff --git a/test/spec/server-discovery-and-monitoring/rs/discover_secondary_replicaset.yml b/test/spec/server-discovery-and-monitoring/rs/discover_secondary_replicaset.yml
index 3781d0e42d..c73a535f69 100644
--- a/test/spec/server-discovery-and-monitoring/rs/discover_secondary_replicaset.yml
+++ b/test/spec/server-discovery-and-monitoring/rs/discover_secondary_replicaset.yml
@@ -10,7 +10,8 @@ phases: [
                 ["b:27017", {
 
                     ok: 1,
-                    ismaster: false,
+                    helloOk: true,
+                    isWritablePrimary: false,
                     secondary: true,
                     setName: "rs",
                     hosts: ["a:27017", "b:27017"],
diff --git a/test/spec/server-discovery-and-monitoring/rs/discovery.json b/test/spec/server-discovery-and-monitoring/rs/discovery.json
index 57ed568e3b..50e1269223 100644
--- a/test/spec/server-discovery-and-monitoring/rs/discovery.json
+++ b/test/spec/server-discovery-and-monitoring/rs/discovery.json
@@ -8,7 +8,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": false,
+            "helloOk": true,
+            "isWritablePrimary": false,
             "secondary": true,
             "setName": "rs",
             "hosts": [
@@ -47,7 +48,8 @@
           "b:27017",
           {
             "ok": 1,
-            "ismaster": false,
+            "helloOk": true,
+            "isWritablePrimary": false,
             "secondary": true,
             "setName": "rs",
             "primary": "d:27017",
@@ -91,7 +93,8 @@
           "d:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "setName": "rs",
             "hosts": [
               "b:27017",
@@ -134,7 +137,8 @@
           "c:27017",
           {
             "ok": 1,
-            "ismaster": false,
+            "helloOk": true,
+            "isWritablePrimary": false,
             "secondary": true,
             "setName": "rs",
             "hosts": [
diff --git a/test/spec/server-discovery-and-monitoring/rs/discovery.yml b/test/spec/server-discovery-and-monitoring/rs/discovery.yml
index fc666a05f3..30c82e0cef 100644
--- a/test/spec/server-discovery-and-monitoring/rs/discovery.yml
+++ b/test/spec/server-discovery-and-monitoring/rs/discovery.yml
@@ -11,7 +11,8 @@ phases: [
                 ["a:27017", {
 
                     ok: 1,
-                    ismaster: false,
+                    helloOk: true,
+                    isWritablePrimary: false,
                     secondary: true,
                     setName: "rs",
                     hosts: ["a:27017", "b:27017", "c:27017"],
@@ -55,7 +56,8 @@ phases: [
                 ["b:27017", {
 
                     ok: 1,
-                    ismaster: false,
+                    helloOk: true,
+                    isWritablePrimary: false,
                     secondary: true,
                     setName: "rs",
                     primary: "d:27017",
@@ -106,7 +108,8 @@ phases: [
                 ["d:27017", {
 
                     ok: 1,
-                    ismaster: true,
+                    helloOk: true,
+                    isWritablePrimary: true,
                     setName: "rs",
                     hosts: ["b:27017", "c:27017", "d:27017", "e:27017"],
                     minWireVersion: 0,
@@ -156,7 +159,8 @@ phases: [
                 ["c:27017", {
 
                     ok: 1,
-                    ismaster: false,
+                    helloOk: true,
+                    isWritablePrimary: false,
                     secondary: true,
                     setName: "rs",
                     hosts: ["a:27017", "b:27017", "c:27017"],
diff --git a/test/spec/server-discovery-and-monitoring/rs/equal_electionids.json b/test/spec/server-discovery-and-monitoring/rs/equal_electionids.json
index f8d20b350d..17df3207fa 100644
--- a/test/spec/server-discovery-and-monitoring/rs/equal_electionids.json
+++ b/test/spec/server-discovery-and-monitoring/rs/equal_electionids.json
@@ -8,7 +8,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017",
               "b:27017"
@@ -26,7 +27,8 @@
           "b:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017",
               "b:27017"
diff --git a/test/spec/server-discovery-and-monitoring/rs/equal_electionids.yml b/test/spec/server-discovery-and-monitoring/rs/equal_electionids.yml
index 010d9cf937..48bb683d64 100644
--- a/test/spec/server-discovery-and-monitoring/rs/equal_electionids.yml
+++ b/test/spec/server-discovery-and-monitoring/rs/equal_electionids.yml
@@ -9,7 +9,8 @@ phases: [
         responses: [
             ["a:27017", {
                 ok: 1,
-                ismaster: true,
+                helloOk: true,
+                isWritablePrimary: true,
                 hosts: ["a:27017", "b:27017"],
                 setName: "rs",
                 setVersion: 1,
@@ -19,7 +20,8 @@ phases: [
             }],
             ["b:27017", {
                 ok: 1,
-                ismaster: true,
+                helloOk: true,
+                isWritablePrimary: true,
                 hosts: ["a:27017", "b:27017"],
                 setName: "rs",
                 setVersion: 1,
diff --git a/test/spec/server-discovery-and-monitoring/rs/hosts_differ_from_seeds.json b/test/spec/server-discovery-and-monitoring/rs/hosts_differ_from_seeds.json
index a67db57d0c..4e02304c61 100644
--- a/test/spec/server-discovery-and-monitoring/rs/hosts_differ_from_seeds.json
+++ b/test/spec/server-discovery-and-monitoring/rs/hosts_differ_from_seeds.json
@@ -8,7 +8,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "setName": "rs",
             "hosts": [
               "b:27017"
diff --git a/test/spec/server-discovery-and-monitoring/rs/hosts_differ_from_seeds.yml b/test/spec/server-discovery-and-monitoring/rs/hosts_differ_from_seeds.yml
index 557286e0b8..e97fbca05b 100644
--- a/test/spec/server-discovery-and-monitoring/rs/hosts_differ_from_seeds.yml
+++ b/test/spec/server-discovery-and-monitoring/rs/hosts_differ_from_seeds.yml
@@ -10,7 +10,8 @@ phases: [
                 ["a:27017", {
 
                     ok: 1,
-                    ismaster: true,
+                    helloOk: true,
+                    isWritablePrimary: true,
                     setName: "rs",
                     hosts: ["b:27017"],
                     minWireVersion: 0,
diff --git a/test/spec/server-discovery-and-monitoring/rs/incompatible_arbiter.json b/test/spec/server-discovery-and-monitoring/rs/incompatible_arbiter.json
index aa582208d6..f0539cb337 100644
--- a/test/spec/server-discovery-and-monitoring/rs/incompatible_arbiter.json
+++ b/test/spec/server-discovery-and-monitoring/rs/incompatible_arbiter.json
@@ -8,7 +8,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "setName": "rs",
             "hosts": [
               "a:27017",
@@ -22,6 +23,7 @@
           "b:27017",
           {
             "ok": 1,
+            "helloOk": true,
             "arbiterOnly": true,
             "setName": "rs",
             "hosts": [
diff --git a/test/spec/server-discovery-and-monitoring/rs/incompatible_arbiter.yml b/test/spec/server-discovery-and-monitoring/rs/incompatible_arbiter.yml
index e41dbcd6fe..e4928f191d 100644
--- a/test/spec/server-discovery-and-monitoring/rs/incompatible_arbiter.yml
+++ b/test/spec/server-discovery-and-monitoring/rs/incompatible_arbiter.yml
@@ -7,7 +7,8 @@ phases:
       -
         - "a:27017"
         - ok: 1
-          ismaster: true
+          helloOk: true
+          isWritablePrimary: true
           setName: "rs"
           hosts: ["a:27017", "b:27017"]
           minWireVersion: 0
@@ -15,6 +16,7 @@ phases:
       -
         - "b:27017"
         - ok: 1
+          helloOk: true
           arbiterOnly: true
           setName: "rs"
           hosts: ["a:27017", "b:27017"]
diff --git a/test/spec/server-discovery-and-monitoring/rs/incompatible_ghost.json b/test/spec/server-discovery-and-monitoring/rs/incompatible_ghost.json
index 088159c3ab..824e953f90 100644
--- a/test/spec/server-discovery-and-monitoring/rs/incompatible_ghost.json
+++ b/test/spec/server-discovery-and-monitoring/rs/incompatible_ghost.json
@@ -8,7 +8,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "setName": "rs",
             "hosts": [
               "a:27017",
@@ -22,6 +23,7 @@
           "b:27017",
           {
             "ok": 1,
+            "helloOk": true,
             "isreplicaset": true,
             "minWireVersion": 0,
             "maxWireVersion": 1
diff --git a/test/spec/server-discovery-and-monitoring/rs/incompatible_ghost.yml b/test/spec/server-discovery-and-monitoring/rs/incompatible_ghost.yml
index fa73ec3ddd..da1db790fe 100644
--- a/test/spec/server-discovery-and-monitoring/rs/incompatible_ghost.yml
+++ b/test/spec/server-discovery-and-monitoring/rs/incompatible_ghost.yml
@@ -7,7 +7,8 @@ phases:
       -
         - "a:27017"
         - ok: 1
-          ismaster: true
+          helloOk: true
+          isWritablePrimary: true
           setName: "rs"
           hosts: ["a:27017", "b:27017"]
           minWireVersion: 0
@@ -15,6 +16,7 @@ phases:
       -
         - "b:27017"
         - ok: 1
+          helloOk: true
           isreplicaset: true
           minWireVersion: 0
           maxWireVersion: 1
diff --git a/test/spec/server-discovery-and-monitoring/rs/incompatible_other.json b/test/spec/server-discovery-and-monitoring/rs/incompatible_other.json
index b65d674b42..6f301ef5de 100644
--- a/test/spec/server-discovery-and-monitoring/rs/incompatible_other.json
+++ b/test/spec/server-discovery-and-monitoring/rs/incompatible_other.json
@@ -8,7 +8,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "setName": "rs",
             "hosts": [
               "a:27017",
@@ -22,6 +23,7 @@
           "b:27017",
           {
             "ok": 1,
+            "helloOk": true,
             "hidden": true,
             "setName": "rs",
             "hosts": [
diff --git a/test/spec/server-discovery-and-monitoring/rs/incompatible_other.yml b/test/spec/server-discovery-and-monitoring/rs/incompatible_other.yml
index 848b307ab0..98061c0a1f 100644
--- a/test/spec/server-discovery-and-monitoring/rs/incompatible_other.yml
+++ b/test/spec/server-discovery-and-monitoring/rs/incompatible_other.yml
@@ -7,7 +7,8 @@ phases:
       -
         - "a:27017"
         - ok: 1
-          ismaster: true
+          helloOk: true
+          isWritablePrimary: true
           setName: "rs"
           hosts: ["a:27017", "b:27017"]
           minWireVersion: 0
@@ -15,6 +16,7 @@ phases:
       -
         - "b:27017"
         - ok: 1
+          helloOk: true
           hidden: true
           setName: "rs"
           hosts: ["a:27017", "b:27017"]
diff --git a/test/spec/server-discovery-and-monitoring/rs/ls_timeout.json b/test/spec/server-discovery-and-monitoring/rs/ls_timeout.json
index 6860742c9e..96389d3b76 100644
--- a/test/spec/server-discovery-and-monitoring/rs/ls_timeout.json
+++ b/test/spec/server-discovery-and-monitoring/rs/ls_timeout.json
@@ -8,7 +8,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017",
               "b:27017",
@@ -53,7 +54,8 @@
           "d:27017",
           {
             "ok": 1,
-            "ismaster": false,
+            "helloOk": true,
+            "isWritablePrimary": false,
             "isreplicaset": true,
             "minWireVersion": 0,
             "maxWireVersion": 6
@@ -90,7 +92,8 @@
           "e:27017",
           {
             "ok": 1,
-            "ismaster": false,
+            "helloOk": true,
+            "isWritablePrimary": false,
             "hosts": [
               "a:27017",
               "b:27017",
@@ -136,7 +139,8 @@
           "b:27017",
           {
             "ok": 1,
-            "ismaster": false,
+            "helloOk": true,
+            "isWritablePrimary": false,
             "secondary": true,
             "hosts": [
               "a:27017",
@@ -184,7 +188,8 @@
           "c:27017",
           {
             "ok": 1,
-            "ismaster": false,
+            "helloOk": true,
+            "isWritablePrimary": false,
             "setName": "rs",
             "hidden": true,
             "logicalSessionTimeoutMinutes": 1,
@@ -226,7 +231,8 @@
           "b:27017",
           {
             "ok": 1,
-            "ismaster": false,
+            "helloOk": true,
+            "isWritablePrimary": false,
             "secondary": true,
             "hosts": [
               "a:27017",
diff --git a/test/spec/server-discovery-and-monitoring/rs/ls_timeout.yml b/test/spec/server-discovery-and-monitoring/rs/ls_timeout.yml
index 7690c83a49..26679f339e 100644
--- a/test/spec/server-discovery-and-monitoring/rs/ls_timeout.yml
+++ b/test/spec/server-discovery-and-monitoring/rs/ls_timeout.yml
@@ -8,7 +8,8 @@ phases: [
         responses: [
              ["a:27017", {
                 ok: 1,
-                ismaster: true,
+                helloOk: true,
+                isWritablePrimary: true,
                 hosts: ["a:27017", "b:27017", "c:27017", "d:27017", "e:27017"],
                 setName: "rs",
                 logicalSessionTimeoutMinutes: 3,
@@ -46,7 +47,8 @@ phases: [
         responses: [
             ["d:27017", {
                 ok: 1,
-                ismaster: false,
+                helloOk: true,
+                isWritablePrimary: false,
                 isreplicaset: true,
                 minWireVersion: 0,
                 maxWireVersion: 6
@@ -82,7 +84,8 @@ phases: [
         responses: [
            ["e:27017", {
                 ok: 1,
-                ismaster: false,
+                helloOk: true,
+                isWritablePrimary: false,
                 hosts: ["a:27017", "b:27017", "c:27017", "d:27017", "e:27017"],
                 setName: "rs",
                 arbiterOnly: true,
@@ -121,7 +124,8 @@ phases: [
         responses: [
             ["b:27017", {
                 ok: 1,
-                ismaster: false,
+                helloOk: true,
+                isWritablePrimary: false,
                 secondary: true,
                 hosts: ["a:27017", "b:27017", "c:27017", "d:27017", "e:27017"],
                 setName: "rs",
@@ -162,7 +166,8 @@ phases: [
         responses: [
             ["c:27017", {
                 ok: 1,
-                ismaster: false,
+                helloOk: true,
+                isWritablePrimary: false,
                 setName: "rs",
                 hidden: true,
                 logicalSessionTimeoutMinutes: 1,
@@ -202,7 +207,8 @@ phases: [
         responses: [
             ["b:27017", {
                 ok: 1,
-                ismaster: false,
+                helloOk: true,
+                isWritablePrimary: false,
                 secondary: true,
                 hosts: ["a:27017", "b:27017", "c:27017", "d:27017", "e:27017"],
                 setName: "rs",
diff --git a/test/spec/server-discovery-and-monitoring/rs/member_reconfig.json b/test/spec/server-discovery-and-monitoring/rs/member_reconfig.json
index 336acff023..0e2c2c462e 100644
--- a/test/spec/server-discovery-and-monitoring/rs/member_reconfig.json
+++ b/test/spec/server-discovery-and-monitoring/rs/member_reconfig.json
@@ -8,7 +8,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "setName": "rs",
             "hosts": [
               "a:27017",
@@ -41,7 +42,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "setName": "rs",
             "hosts": [
               "a:27017"
diff --git a/test/spec/server-discovery-and-monitoring/rs/member_reconfig.yml b/test/spec/server-discovery-and-monitoring/rs/member_reconfig.yml
index a525bd1e66..37e63bc059 100644
--- a/test/spec/server-discovery-and-monitoring/rs/member_reconfig.yml
+++ b/test/spec/server-discovery-and-monitoring/rs/member_reconfig.yml
@@ -10,7 +10,8 @@ phases: [
                 ["a:27017", {
 
                     ok: 1,
-                    ismaster: true,
+                    helloOk: true,
+                    isWritablePrimary: true,
                     setName: "rs",
                     hosts: ["a:27017", "b:27017"],
                     minWireVersion: 0,
@@ -46,7 +47,8 @@ phases: [
                 ["a:27017", {
 
                     ok: 1,
-                    ismaster: true,
+                    helloOk: true,
+                    isWritablePrimary: true,
                     setName: "rs",
                     hosts: ["a:27017"],
                     minWireVersion: 0,
diff --git a/test/spec/server-discovery-and-monitoring/rs/member_standalone.json b/test/spec/server-discovery-and-monitoring/rs/member_standalone.json
index a97dfabf52..0756003a89 100644
--- a/test/spec/server-discovery-and-monitoring/rs/member_standalone.json
+++ b/test/spec/server-discovery-and-monitoring/rs/member_standalone.json
@@ -8,7 +8,8 @@
           "b:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "minWireVersion": 0,
             "maxWireVersion": 6
           }
@@ -32,7 +33,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "setName": "rs",
             "hosts": [
               "a:27017"
diff --git a/test/spec/server-discovery-and-monitoring/rs/member_standalone.yml b/test/spec/server-discovery-and-monitoring/rs/member_standalone.yml
index 8850b9f9b6..50c0056650 100644
--- a/test/spec/server-discovery-and-monitoring/rs/member_standalone.yml
+++ b/test/spec/server-discovery-and-monitoring/rs/member_standalone.yml
@@ -10,7 +10,8 @@ phases: [
                 ["b:27017", {
 
                     ok: 1,
-                    ismaster: true,
+                    helloOk: true,
+                    isWritablePrimary: true,
                     minWireVersion: 0,
                     maxWireVersion: 6
                 }]
@@ -38,7 +39,8 @@ phases: [
                 ["a:27017", {
 
                     ok: 1,
-                    ismaster: true,
+                    helloOk: true,
+                    isWritablePrimary: true,
                     setName: "rs",
                     hosts: ["a:27017"],
                     minWireVersion: 0,
diff --git a/test/spec/server-discovery-and-monitoring/rs/new_primary.json b/test/spec/server-discovery-and-monitoring/rs/new_primary.json
index eb73b304bd..ed1a6245f9 100644
--- a/test/spec/server-discovery-and-monitoring/rs/new_primary.json
+++ b/test/spec/server-discovery-and-monitoring/rs/new_primary.json
@@ -8,7 +8,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "setName": "rs",
             "hosts": [
               "a:27017",
@@ -41,7 +42,8 @@
           "b:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "setName": "rs",
             "hosts": [
               "a:27017",
diff --git a/test/spec/server-discovery-and-monitoring/rs/new_primary.yml b/test/spec/server-discovery-and-monitoring/rs/new_primary.yml
index b7cfd16014..736dd06c5f 100644
--- a/test/spec/server-discovery-and-monitoring/rs/new_primary.yml
+++ b/test/spec/server-discovery-and-monitoring/rs/new_primary.yml
@@ -10,7 +10,8 @@ phases: [
                 ["a:27017", {
 
                     ok: 1,
-                    ismaster: true,
+                    helloOk: true,
+                    isWritablePrimary: true,
                     setName: "rs",
                     hosts: ["a:27017", "b:27017"],
                     minWireVersion: 0,
@@ -46,7 +47,8 @@ phases: [
                 ["b:27017", {
 
                     ok: 1,
-                    ismaster: true,
+                    helloOk: true,
+                    isWritablePrimary: true,
                     setName: "rs",
                     hosts: ["a:27017", "b:27017"],
                     minWireVersion: 0,
diff --git a/test/spec/server-discovery-and-monitoring/rs/new_primary_new_electionid.json b/test/spec/server-discovery-and-monitoring/rs/new_primary_new_electionid.json
index 67f314b1ed..ccb3a41f75 100644
--- a/test/spec/server-discovery-and-monitoring/rs/new_primary_new_electionid.json
+++ b/test/spec/server-discovery-and-monitoring/rs/new_primary_new_electionid.json
@@ -8,7 +8,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017",
               "b:27017"
@@ -54,7 +55,8 @@
           "b:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017",
               "b:27017"
@@ -100,7 +102,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017",
               "b:27017"
diff --git a/test/spec/server-discovery-and-monitoring/rs/new_primary_new_electionid.yml b/test/spec/server-discovery-and-monitoring/rs/new_primary_new_electionid.yml
index 8467a83955..dfebbd8561 100644
--- a/test/spec/server-discovery-and-monitoring/rs/new_primary_new_electionid.yml
+++ b/test/spec/server-discovery-and-monitoring/rs/new_primary_new_electionid.yml
@@ -9,7 +9,8 @@ phases: [
         responses: [
             ["a:27017", {
                 ok: 1,
-                ismaster: true,
+                helloOk: true,
+                isWritablePrimary: true,
                 hosts: ["a:27017", "b:27017"],
                 setName: "rs",
                 setVersion: 1,
@@ -46,7 +47,8 @@ phases: [
         responses: [
             ["b:27017", {
                 ok: 1,
-                ismaster: true,
+                helloOk: true,
+                isWritablePrimary: true,
                 hosts: ["a:27017", "b:27017"],
                 setName: "rs",
                 setVersion: 1,
@@ -83,7 +85,8 @@ phases: [
         responses: [
             ["a:27017", {
                 ok: 1,
-                ismaster: true,
+                helloOk: true,
+                isWritablePrimary: true,
                 hosts: ["a:27017", "b:27017"],
                 setName: "rs",
                 setVersion: 1,
diff --git a/test/spec/server-discovery-and-monitoring/rs/new_primary_new_setversion.json b/test/spec/server-discovery-and-monitoring/rs/new_primary_new_setversion.json
index c1ec50c845..415a0f66aa 100644
--- a/test/spec/server-discovery-and-monitoring/rs/new_primary_new_setversion.json
+++ b/test/spec/server-discovery-and-monitoring/rs/new_primary_new_setversion.json
@@ -8,7 +8,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017",
               "b:27017"
@@ -54,7 +55,8 @@
           "b:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017",
               "b:27017"
@@ -100,7 +102,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017",
               "b:27017"
diff --git a/test/spec/server-discovery-and-monitoring/rs/new_primary_new_setversion.yml b/test/spec/server-discovery-and-monitoring/rs/new_primary_new_setversion.yml
index fed3840e0b..3ebc798b61 100644
--- a/test/spec/server-discovery-and-monitoring/rs/new_primary_new_setversion.yml
+++ b/test/spec/server-discovery-and-monitoring/rs/new_primary_new_setversion.yml
@@ -9,7 +9,8 @@ phases: [
         responses: [
             ["a:27017", {
                 ok: 1,
-                ismaster: true,
+                helloOk: true,
+                isWritablePrimary: true,
                 hosts: ["a:27017", "b:27017"],
                 setName: "rs",
                 setVersion: 1,
@@ -46,7 +47,8 @@ phases: [
         responses: [
             ["b:27017", {
                 ok: 1,
-                ismaster: true,
+                helloOk: true,
+                isWritablePrimary: true,
                 hosts: ["a:27017", "b:27017"],
                 setName: "rs",
                 setVersion: 2,
@@ -83,7 +85,8 @@ phases: [
         responses: [
             ["a:27017", {
                 ok: 1,
-                ismaster: true,
+                helloOk: true,
+                isWritablePrimary: true,
                 hosts: ["a:27017", "b:27017"],
                 setName: "rs",
                 setVersion: 1,
diff --git a/test/spec/server-discovery-and-monitoring/rs/new_primary_wrong_set_name.json b/test/spec/server-discovery-and-monitoring/rs/new_primary_wrong_set_name.json
index 7be79d2d3c..d7b19cfe8f 100644
--- a/test/spec/server-discovery-and-monitoring/rs/new_primary_wrong_set_name.json
+++ b/test/spec/server-discovery-and-monitoring/rs/new_primary_wrong_set_name.json
@@ -8,7 +8,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017",
               "b:27017"
@@ -41,7 +42,8 @@
           "b:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
diff --git a/test/spec/server-discovery-and-monitoring/rs/new_primary_wrong_set_name.yml b/test/spec/server-discovery-and-monitoring/rs/new_primary_wrong_set_name.yml
index adca8a2d50..ca6303cda9 100644
--- a/test/spec/server-discovery-and-monitoring/rs/new_primary_wrong_set_name.yml
+++ b/test/spec/server-discovery-and-monitoring/rs/new_primary_wrong_set_name.yml
@@ -11,7 +11,8 @@ phases: [
                 ["a:27017", {
 
                     ok: 1,
-                    ismaster: true,
+                    helloOk: true,
+                    isWritablePrimary: true,
                     hosts: ["a:27017", "b:27017"],
                     setName: "rs",
                     minWireVersion: 0,
@@ -49,7 +50,8 @@ phases: [
                 ["b:27017", {
 
                     ok: 1,
-                    ismaster: true,
+                    helloOk: true,
+                    isWritablePrimary: true,
                     hosts: ["a:27017"],
                     setName: "wrong",
                     minWireVersion: 0,
diff --git a/test/spec/server-discovery-and-monitoring/rs/non_rs_member.json b/test/spec/server-discovery-and-monitoring/rs/non_rs_member.json
index 907c1651e0..538077ef09 100644
--- a/test/spec/server-discovery-and-monitoring/rs/non_rs_member.json
+++ b/test/spec/server-discovery-and-monitoring/rs/non_rs_member.json
@@ -8,6 +8,7 @@
           "b:27017",
           {
             "ok": 1,
+            "helloOk": true,
             "minWireVersion": 0,
             "maxWireVersion": 6
           }
diff --git a/test/spec/server-discovery-and-monitoring/rs/non_rs_member.yml b/test/spec/server-discovery-and-monitoring/rs/non_rs_member.yml
index 7fc4dddf26..c18b27ee3f 100644
--- a/test/spec/server-discovery-and-monitoring/rs/non_rs_member.yml
+++ b/test/spec/server-discovery-and-monitoring/rs/non_rs_member.yml
@@ -9,6 +9,7 @@ phases: [
 
                 ["b:27017", {
                     ok: 1,
+                    helloOk: true,
                     minWireVersion: 0,
                     maxWireVersion: 6
                 }]
diff --git a/test/spec/server-discovery-and-monitoring/rs/normalize_case.json b/test/spec/server-discovery-and-monitoring/rs/normalize_case.json
index 4d0b0ae629..96a944f0c3 100644
--- a/test/spec/server-discovery-and-monitoring/rs/normalize_case.json
+++ b/test/spec/server-discovery-and-monitoring/rs/normalize_case.json
@@ -8,7 +8,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "setName": "rs",
             "hosts": [
               "A:27017"
diff --git a/test/spec/server-discovery-and-monitoring/rs/normalize_case.yml b/test/spec/server-discovery-and-monitoring/rs/normalize_case.yml
index f1fdd78830..d8003ee375 100644
--- a/test/spec/server-discovery-and-monitoring/rs/normalize_case.yml
+++ b/test/spec/server-discovery-and-monitoring/rs/normalize_case.yml
@@ -10,7 +10,8 @@ phases: [
                 ["a:27017", {
 
                     ok: 1,
-                    ismaster: true,
+                    helloOk: true,
+                    isWritablePrimary: true,
                     setName: "rs",
                     hosts: ["A:27017"],
                     passives: ["B:27017"],
diff --git a/test/spec/server-discovery-and-monitoring/rs/normalize_case_me.json b/test/spec/server-discovery-and-monitoring/rs/normalize_case_me.json
index e854e7fb43..ab1720cefc 100644
--- a/test/spec/server-discovery-and-monitoring/rs/normalize_case_me.json
+++ b/test/spec/server-discovery-and-monitoring/rs/normalize_case_me.json
@@ -8,7 +8,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "setName": "rs",
             "me": "A:27017",
             "hosts": [
@@ -51,7 +52,8 @@
           "b:27017",
           {
             "ok": 1,
-            "ismaster": false,
+            "helloOk": true,
+            "isWritablePrimary": false,
             "secondary": true,
             "setName": "rs",
             "me": "B:27017",
diff --git a/test/spec/server-discovery-and-monitoring/rs/normalize_case_me.yml b/test/spec/server-discovery-and-monitoring/rs/normalize_case_me.yml
index 51700b96a9..a0df3351a5 100644
--- a/test/spec/server-discovery-and-monitoring/rs/normalize_case_me.yml
+++ b/test/spec/server-discovery-and-monitoring/rs/normalize_case_me.yml
@@ -10,7 +10,8 @@ phases: [
                 ["a:27017", {
 
                     ok: 1,
-                    ismaster: true,
+                    helloOk: true,
+                    isWritablePrimary: true,
                     setName: "rs",
                     me: "A:27017",
                     hosts: ["A:27017"],
@@ -56,7 +57,8 @@ phases: [
                 ["b:27017", {
 
                     ok: 1,
-                    ismaster: false,
+                    helloOk: true,
+                    isWritablePrimary: false,
                     secondary: true,
                     setName: "rs",
                     me: "B:27017",
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 3de0a74e41..62120e8448 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
@@ -8,7 +8,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017",
               "b:27017",
@@ -52,7 +53,8 @@
           "b:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017",
               "b:27017",
@@ -104,7 +106,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017",
               "b:27017",
@@ -151,7 +154,8 @@
           "c:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017",
               "b:27017",
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 f435d0d2fb..7de496cd79 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
@@ -9,7 +9,8 @@ phases: [
         responses: [
             ["a:27017", {
                 ok: 1,
-                ismaster: true,
+                helloOk: true,
+                isWritablePrimary: true,
                 hosts: ["a:27017", "b:27017", "c:27017"],
                 setVersion: 1,
                 setName: "rs",
@@ -49,7 +50,8 @@ phases: [
         responses: [
             ["b:27017", {
                 ok: 1,
-                ismaster: true,
+                helloOk: true,
+                isWritablePrimary: true,
                 hosts: ["a:27017", "b:27017", "c:27017"],
                 setName: "rs",
                 setVersion: 1,
@@ -91,7 +93,8 @@ phases: [
         responses: [
             ["a:27017", {
                 ok: 1,
-                ismaster: true,
+                helloOk: true,
+                isWritablePrimary: true,
                 hosts: ["a:27017", "b:27017", "c:27017"],
                 setVersion: 1,
                 setName: "rs",
@@ -132,7 +135,8 @@ phases: [
         responses: [
             ["c:27017", {
                 ok: 1,
-                ismaster: true,
+                helloOk: true,
+                isWritablePrimary: true,
                 hosts: ["a:27017", "b:27017", "c:27017"],
                 setName: "rs",
                 setVersion: 1,
diff --git a/test/spec/server-discovery-and-monitoring/rs/primary_becomes_ghost.json b/test/spec/server-discovery-and-monitoring/rs/primary_becomes_ghost.json
index 897120f1fb..9c54b39856 100644
--- a/test/spec/server-discovery-and-monitoring/rs/primary_becomes_ghost.json
+++ b/test/spec/server-discovery-and-monitoring/rs/primary_becomes_ghost.json
@@ -8,7 +8,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
@@ -36,7 +37,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": false,
+            "helloOk": true,
+            "isWritablePrimary": false,
             "isreplicaset": true,
             "minWireVersion": 0,
             "maxWireVersion": 6
diff --git a/test/spec/server-discovery-and-monitoring/rs/primary_becomes_ghost.yml b/test/spec/server-discovery-and-monitoring/rs/primary_becomes_ghost.yml
index e504d76417..dbf5b9289d 100644
--- a/test/spec/server-discovery-and-monitoring/rs/primary_becomes_ghost.yml
+++ b/test/spec/server-discovery-and-monitoring/rs/primary_becomes_ghost.yml
@@ -10,7 +10,8 @@ phases: [
                 ["a:27017", {
 
                     ok: 1,
-                    ismaster: true,
+                    helloOk: true,
+                    isWritablePrimary: true,
                     hosts: ["a:27017"],
                     setName: "rs",
                     minWireVersion: 0,
@@ -38,7 +39,8 @@ phases: [
         responses: [
                 ["a:27017", {
                     ok: 1,
-                    ismaster: false,
+                    helloOk: true,
+                    isWritablePrimary: false,
                     isreplicaset: true,
                     minWireVersion: 0,
                     maxWireVersion: 6
diff --git a/test/spec/server-discovery-and-monitoring/rs/primary_becomes_mongos.json b/test/spec/server-discovery-and-monitoring/rs/primary_becomes_mongos.json
index 8d4967b7dd..ac416e57d5 100644
--- a/test/spec/server-discovery-and-monitoring/rs/primary_becomes_mongos.json
+++ b/test/spec/server-discovery-and-monitoring/rs/primary_becomes_mongos.json
@@ -8,7 +8,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
@@ -36,7 +37,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "msg": "isdbgrid",
             "minWireVersion": 0,
             "maxWireVersion": 6
diff --git a/test/spec/server-discovery-and-monitoring/rs/primary_becomes_mongos.yml b/test/spec/server-discovery-and-monitoring/rs/primary_becomes_mongos.yml
index ae46051121..6cdb077106 100644
--- a/test/spec/server-discovery-and-monitoring/rs/primary_becomes_mongos.yml
+++ b/test/spec/server-discovery-and-monitoring/rs/primary_becomes_mongos.yml
@@ -10,7 +10,8 @@ phases: [
                 ["a:27017", {
 
                     ok: 1,
-                    ismaster: true,
+                    helloOk: true,
+                    isWritablePrimary: true,
                     hosts: ["a:27017"],
                     setName: "rs",
                     minWireVersion: 0,
@@ -38,7 +39,8 @@ phases: [
         responses: [
                 ["a:27017", {
                     ok: 1,
-                    ismaster: true,
+                    helloOk: true,
+                    isWritablePrimary: true,
                     msg: "isdbgrid",
                     minWireVersion: 0,
                     maxWireVersion: 6
diff --git a/test/spec/server-discovery-and-monitoring/rs/primary_becomes_standalone.json b/test/spec/server-discovery-and-monitoring/rs/primary_becomes_standalone.json
index e35c75f4bc..a64524d0ca 100644
--- a/test/spec/server-discovery-and-monitoring/rs/primary_becomes_standalone.json
+++ b/test/spec/server-discovery-and-monitoring/rs/primary_becomes_standalone.json
@@ -8,7 +8,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
diff --git a/test/spec/server-discovery-and-monitoring/rs/primary_becomes_standalone.yml b/test/spec/server-discovery-and-monitoring/rs/primary_becomes_standalone.yml
index 2f7db8054f..abcc7fcfe3 100644
--- a/test/spec/server-discovery-and-monitoring/rs/primary_becomes_standalone.yml
+++ b/test/spec/server-discovery-and-monitoring/rs/primary_becomes_standalone.yml
@@ -10,7 +10,8 @@ phases: [
                 ["a:27017", {
 
                     ok: 1,
-                    ismaster: true,
+                    helloOk: true,
+                    isWritablePrimary: true,
                     hosts: ["a:27017"],
                     setName: "rs",
                     minWireVersion: 0,
diff --git a/test/spec/server-discovery-and-monitoring/rs/primary_changes_set_name.json b/test/spec/server-discovery-and-monitoring/rs/primary_changes_set_name.json
index d008326123..bf70ca3014 100644
--- a/test/spec/server-discovery-and-monitoring/rs/primary_changes_set_name.json
+++ b/test/spec/server-discovery-and-monitoring/rs/primary_changes_set_name.json
@@ -8,7 +8,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
@@ -36,7 +37,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
diff --git a/test/spec/server-discovery-and-monitoring/rs/primary_changes_set_name.yml b/test/spec/server-discovery-and-monitoring/rs/primary_changes_set_name.yml
index 67a24ec5ba..00ed1c0a13 100644
--- a/test/spec/server-discovery-and-monitoring/rs/primary_changes_set_name.yml
+++ b/test/spec/server-discovery-and-monitoring/rs/primary_changes_set_name.yml
@@ -11,7 +11,8 @@ phases: [
                 ["a:27017", {
 
                     ok: 1,
-                    ismaster: true,
+                    helloOk: true,
+                    isWritablePrimary: true,
                     hosts: ["a:27017"],
                     setName: "rs",
                     minWireVersion: 0,
@@ -42,7 +43,8 @@ phases: [
                 ["a:27017", {
 
                     ok: 1,
-                    ismaster: true,
+                    helloOk: true,
+                    isWritablePrimary: true,
                     hosts: ["a:27017"],
                     setName: "wrong",
                     minWireVersion: 0,
diff --git a/test/spec/server-discovery-and-monitoring/rs/primary_disconnect.json b/test/spec/server-discovery-and-monitoring/rs/primary_disconnect.json
index 271ca5874e..3db854f085 100644
--- a/test/spec/server-discovery-and-monitoring/rs/primary_disconnect.json
+++ b/test/spec/server-discovery-and-monitoring/rs/primary_disconnect.json
@@ -8,7 +8,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
diff --git a/test/spec/server-discovery-and-monitoring/rs/primary_disconnect.yml b/test/spec/server-discovery-and-monitoring/rs/primary_disconnect.yml
index 421e1f0ae4..9a49656549 100644
--- a/test/spec/server-discovery-and-monitoring/rs/primary_disconnect.yml
+++ b/test/spec/server-discovery-and-monitoring/rs/primary_disconnect.yml
@@ -10,7 +10,8 @@ phases: [
                 ["a:27017", {
 
                     ok: 1,
-                    ismaster: true,
+                    helloOk: true,
+                    isWritablePrimary: true,
                     hosts: ["a:27017"],
                     setName: "rs",
                     minWireVersion: 0,
diff --git a/test/spec/server-discovery-and-monitoring/rs/primary_disconnect_electionid.json b/test/spec/server-discovery-and-monitoring/rs/primary_disconnect_electionid.json
index 59c8faf180..3a80b150fe 100644
--- a/test/spec/server-discovery-and-monitoring/rs/primary_disconnect_electionid.json
+++ b/test/spec/server-discovery-and-monitoring/rs/primary_disconnect_electionid.json
@@ -8,7 +8,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017",
               "b:27017"
@@ -26,7 +27,8 @@
           "b:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017",
               "b:27017"
@@ -101,7 +103,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017",
               "b:27017"
@@ -144,7 +147,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017",
               "b:27017"
@@ -190,7 +194,8 @@
           "b:27017",
           {
             "ok": 1,
-            "ismaster": false,
+            "helloOk": true,
+            "isWritablePrimary": false,
             "secondary": true,
             "hosts": [
               "a:27017",
diff --git a/test/spec/server-discovery-and-monitoring/rs/primary_disconnect_electionid.yml b/test/spec/server-discovery-and-monitoring/rs/primary_disconnect_electionid.yml
index eb923201c9..0d7d294f97 100644
--- a/test/spec/server-discovery-and-monitoring/rs/primary_disconnect_electionid.yml
+++ b/test/spec/server-discovery-and-monitoring/rs/primary_disconnect_electionid.yml
@@ -9,7 +9,8 @@ phases: [
         responses: [
             ["a:27017", {
                 ok: 1,
-                ismaster: true,
+                helloOk: true,
+                isWritablePrimary: true,
                 hosts: ["a:27017", "b:27017"],
                 setName: "rs",
                 setVersion: 1,
@@ -19,7 +20,8 @@ phases: [
             }],
             ["b:27017", {
                 ok: 1,
-                ismaster: true,
+                helloOk: true,
+                isWritablePrimary: true,
                 hosts: ["a:27017", "b:27017"],
                 setName: "rs",
                 setVersion: 1,
@@ -82,7 +84,8 @@ phases: [
         responses: [
             ["a:27017", {
                 ok: 1,
-                ismaster: true,
+                helloOk: true,
+                isWritablePrimary: true,
                 hosts: ["a:27017", "b:27017"],
                 setName: "rs",
                 setVersion: 1,
@@ -117,7 +120,8 @@ phases: [
         responses: [
             ["a:27017", {
                 ok: 1,
-                ismaster: true,
+                helloOk: true,
+                isWritablePrimary: true,
                 hosts: ["a:27017", "b:27017"],
                 setName: "rs",
                 setVersion: 1,
@@ -153,7 +157,8 @@ phases: [
         responses: [
             ["b:27017", {
                 ok: 1,
-                ismaster: false,
+                helloOk: true,
+                isWritablePrimary: false,
                 secondary: true,
                 hosts: ["a:27017", "b:27017"],
                 setName: "rs",
diff --git a/test/spec/server-discovery-and-monitoring/rs/primary_disconnect_setversion.json b/test/spec/server-discovery-and-monitoring/rs/primary_disconnect_setversion.json
index beb023e4f4..32e03fb7d4 100644
--- a/test/spec/server-discovery-and-monitoring/rs/primary_disconnect_setversion.json
+++ b/test/spec/server-discovery-and-monitoring/rs/primary_disconnect_setversion.json
@@ -8,7 +8,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017",
               "b:27017"
@@ -26,7 +27,8 @@
           "b:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017",
               "b:27017"
@@ -101,7 +103,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017",
               "b:27017"
@@ -144,7 +147,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017",
               "b:27017"
@@ -190,7 +194,8 @@
           "b:27017",
           {
             "ok": 1,
-            "ismaster": false,
+            "helloOk": true,
+            "isWritablePrimary": false,
             "secondary": true,
             "hosts": [
               "a:27017",
diff --git a/test/spec/server-discovery-and-monitoring/rs/primary_disconnect_setversion.yml b/test/spec/server-discovery-and-monitoring/rs/primary_disconnect_setversion.yml
index 86bbdff35b..41f2f8d7b7 100644
--- a/test/spec/server-discovery-and-monitoring/rs/primary_disconnect_setversion.yml
+++ b/test/spec/server-discovery-and-monitoring/rs/primary_disconnect_setversion.yml
@@ -9,7 +9,8 @@ phases: [
         responses: [
             ["a:27017", {
                 ok: 1,
-                ismaster: true,
+                helloOk: true,
+                isWritablePrimary: true,
                 hosts: ["a:27017", "b:27017"],
                 setName: "rs",
                 setVersion: 1,
@@ -19,7 +20,8 @@ phases: [
             }],
             ["b:27017", {
                 ok: 1,
-                ismaster: true,
+                helloOk: true,
+                isWritablePrimary: true,
                 hosts: ["a:27017", "b:27017"],
                 setName: "rs",
                 setVersion: 2,
@@ -82,7 +84,8 @@ phases: [
         responses: [
             ["a:27017", {
                 ok: 1,
-                ismaster: true,
+                helloOk: true,
+                isWritablePrimary: true,
                 hosts: ["a:27017", "b:27017"],
                 setName: "rs",
                 setVersion: 1,
@@ -117,7 +120,8 @@ phases: [
         responses: [
             ["a:27017", {
                 ok: 1,
-                ismaster: true,
+                helloOk: true,
+                isWritablePrimary: true,
                 hosts: ["a:27017", "b:27017"],
                 setName: "rs",
                 setVersion: 2,
@@ -153,7 +157,8 @@ phases: [
         responses: [
             ["b:27017", {
                 ok: 1,
-                ismaster: false,
+                helloOk: true,
+                isWritablePrimary: false,
                 secondary: true,
                 hosts: ["a:27017", "b:27017"],
                 setName: "rs",
diff --git a/test/spec/server-discovery-and-monitoring/rs/primary_hint_from_secondary_with_mismatched_me.json b/test/spec/server-discovery-and-monitoring/rs/primary_hint_from_secondary_with_mismatched_me.json
index 806fda37c3..bc02cc9571 100644
--- a/test/spec/server-discovery-and-monitoring/rs/primary_hint_from_secondary_with_mismatched_me.json
+++ b/test/spec/server-discovery-and-monitoring/rs/primary_hint_from_secondary_with_mismatched_me.json
@@ -8,7 +8,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": false,
+            "helloOk": true,
+            "isWritablePrimary": false,
             "secondary": true,
             "me": "c:27017",
             "hosts": [
@@ -39,7 +40,8 @@
           "b:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "me": "b:27017",
             "hosts": [
               "b:27017"
diff --git a/test/spec/server-discovery-and-monitoring/rs/primary_hint_from_secondary_with_mismatched_me.yml b/test/spec/server-discovery-and-monitoring/rs/primary_hint_from_secondary_with_mismatched_me.yml
index 9ffa677327..f5b536c01f 100644
--- a/test/spec/server-discovery-and-monitoring/rs/primary_hint_from_secondary_with_mismatched_me.yml
+++ b/test/spec/server-discovery-and-monitoring/rs/primary_hint_from_secondary_with_mismatched_me.yml
@@ -9,7 +9,8 @@ phases: [
         responses: [
             ["a:27017", {
                 ok: 1,
-                ismaster: false,
+                helloOk: true,
+                isWritablePrimary: false,
                 secondary: true,
                 me: "c:27017",
                 hosts: ["b:27017"],
@@ -38,7 +39,8 @@ phases: [
         responses: [
             ["b:27017", {
                 ok: 1,
-                ismaster: true,
+                helloOk: true,
+                isWritablePrimary: true,
                 me: "b:27017",
                 hosts: ["b:27017"],
                 setName: "rs",
diff --git a/test/spec/server-discovery-and-monitoring/rs/primary_mismatched_me.json b/test/spec/server-discovery-and-monitoring/rs/primary_mismatched_me.json
index 8d18a6971f..2d2c0f40d8 100644
--- a/test/spec/server-discovery-and-monitoring/rs/primary_mismatched_me.json
+++ b/test/spec/server-discovery-and-monitoring/rs/primary_mismatched_me.json
@@ -26,7 +26,8 @@
               "a:27017",
               "b:27017"
             ],
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "ok": 1,
             "setName": "rs",
             "minWireVersion": 0,
diff --git a/test/spec/server-discovery-and-monitoring/rs/primary_mismatched_me.yml b/test/spec/server-discovery-and-monitoring/rs/primary_mismatched_me.yml
index 7a4b89fae5..c24fd1a990 100644
--- a/test/spec/server-discovery-and-monitoring/rs/primary_mismatched_me.yml
+++ b/test/spec/server-discovery-and-monitoring/rs/primary_mismatched_me.yml
@@ -17,7 +17,8 @@ phases:
           hosts:
             - 'a:27017'
             - 'b:27017'
-          ismaster: true
+          helloOk: true
+          isWritablePrimary: true
           ok: 1
           setName: rs
           minWireVersion: 0
diff --git a/test/spec/server-discovery-and-monitoring/rs/primary_mismatched_me_not_removed.json b/test/spec/server-discovery-and-monitoring/rs/primary_mismatched_me_not_removed.json
index a9e01987c8..4c40093659 100644
--- a/test/spec/server-discovery-and-monitoring/rs/primary_mismatched_me_not_removed.json
+++ b/test/spec/server-discovery-and-monitoring/rs/primary_mismatched_me_not_removed.json
@@ -12,7 +12,8 @@
               "localhost:27017",
               "localhost:27018"
             ],
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "setName": "rs",
             "primary": "localhost:27017",
             "me": "a:27017",
@@ -47,7 +48,8 @@
               "localhost:27017",
               "localhost:27018"
             ],
-            "ismaster": false,
+            "helloOk": true,
+            "isWritablePrimary": false,
             "secondary": true,
             "setName": "rs",
             "primary": "localhost:27017",
diff --git a/test/spec/server-discovery-and-monitoring/rs/primary_mismatched_me_not_removed.yml b/test/spec/server-discovery-and-monitoring/rs/primary_mismatched_me_not_removed.yml
index 540e206d45..5b7e92e603 100644
--- a/test/spec/server-discovery-and-monitoring/rs/primary_mismatched_me_not_removed.yml
+++ b/test/spec/server-discovery-and-monitoring/rs/primary_mismatched_me_not_removed.yml
@@ -10,12 +10,13 @@ phases: [
           "localhost:27017",
           "localhost:27018"
         ],
-        ismaster: true,
+        helloOk: true,
+        isWritablePrimary: true,
         setName: "rs",
         primary: "localhost:27017",
         # me does not match the primary responder's address, but the server
         # is still added because we don't me mismatch check the primary and all
-        # servers from a primary ismaster are added to the working server set
+        # servers from a primary isWritablePrimary are added to the working server set
         me: "a:27017",
         minWireVersion: 0,
         maxWireVersion: 7
@@ -45,7 +46,8 @@ phases: [
           "localhost:27017",
           "localhost:27018"
         ],
-        ismaster: false,
+        helloOk: true,
+        isWritablePrimary: false,
         secondary: true,
         setName: "rs",
         primary: "localhost:27017",
diff --git a/test/spec/server-discovery-and-monitoring/rs/primary_reports_new_member.json b/test/spec/server-discovery-and-monitoring/rs/primary_reports_new_member.json
index 6ed55ab3d1..ac0d9374f0 100644
--- a/test/spec/server-discovery-and-monitoring/rs/primary_reports_new_member.json
+++ b/test/spec/server-discovery-and-monitoring/rs/primary_reports_new_member.json
@@ -8,7 +8,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": false,
+            "helloOk": true,
+            "isWritablePrimary": false,
             "secondary": true,
             "setName": "rs",
             "hosts": [
@@ -42,7 +43,8 @@
           "b:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "setName": "rs",
             "hosts": [
               "a:27017",
@@ -75,7 +77,8 @@
           "b:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "setName": "rs",
             "hosts": [
               "a:27017",
@@ -113,7 +116,8 @@
           "c:27017",
           {
             "ok": 1,
-            "ismaster": false,
+            "helloOk": true,
+            "isWritablePrimary": false,
             "secondary": true,
             "setName": "rs",
             "primary": "b:27017",
diff --git a/test/spec/server-discovery-and-monitoring/rs/primary_reports_new_member.yml b/test/spec/server-discovery-and-monitoring/rs/primary_reports_new_member.yml
index 719c444782..de3f528fe9 100644
--- a/test/spec/server-discovery-and-monitoring/rs/primary_reports_new_member.yml
+++ b/test/spec/server-discovery-and-monitoring/rs/primary_reports_new_member.yml
@@ -11,7 +11,8 @@ phases: [
                 ["a:27017", {
 
                     ok: 1,
-                    ismaster: false,
+                    helloOk: true,
+                    isWritablePrimary: false,
                     secondary: true,
                     setName: "rs",
                     hosts: ["a:27017", "b:27017"],
@@ -49,7 +50,8 @@ phases: [
                 ["b:27017", {
 
                     ok: 1,
-                    ismaster: true,
+                    helloOk: true,
+                    isWritablePrimary: true,
                     setName: "rs",
                     hosts: ["a:27017", "b:27017"],
                     minWireVersion: 0,
@@ -86,7 +88,8 @@ phases: [
                 ["b:27017", {
 
                     ok: 1,
-                    ismaster: true,
+                    helloOk: true,
+                    isWritablePrimary: true,
                     setName: "rs",
                     hosts: ["a:27017", "b:27017", "c:27017"],
                     minWireVersion: 0,
@@ -130,7 +133,8 @@ phases: [
                 ["c:27017", {
 
                     ok: 1,
-                    ismaster: false,
+                    helloOk: true,
+                    isWritablePrimary: false,
                     secondary: true,
                     setName: "rs",
                     primary: "b:27017",
diff --git a/test/spec/server-discovery-and-monitoring/rs/primary_to_no_primary_mismatched_me.json b/test/spec/server-discovery-and-monitoring/rs/primary_to_no_primary_mismatched_me.json
index fdb250ffef..6dbd73dadc 100644
--- a/test/spec/server-discovery-and-monitoring/rs/primary_to_no_primary_mismatched_me.json
+++ b/test/spec/server-discovery-and-monitoring/rs/primary_to_no_primary_mismatched_me.json
@@ -8,7 +8,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017",
               "b:27017"
@@ -42,7 +43,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "c:27017",
               "d:27017"
diff --git a/test/spec/server-discovery-and-monitoring/rs/primary_to_no_primary_mismatched_me.yml b/test/spec/server-discovery-and-monitoring/rs/primary_to_no_primary_mismatched_me.yml
index 0b2d82a05f..a78982c28e 100644
--- a/test/spec/server-discovery-and-monitoring/rs/primary_to_no_primary_mismatched_me.yml
+++ b/test/spec/server-discovery-and-monitoring/rs/primary_to_no_primary_mismatched_me.yml
@@ -10,7 +10,8 @@ phases: [
                 ["a:27017", {
 
                     ok: 1,
-                    ismaster: true,
+                    helloOk: true,
+                    isWritablePrimary: true,
                     hosts: ["a:27017", "b:27017"],
                     me: "a:27017",
                     setName: "rs",
@@ -46,7 +47,8 @@ phases: [
                 ["a:27017", {
 
                     ok: 1,
-                    ismaster: true,
+                    helloOk: true,
+                    isWritablePrimary: true,
                     hosts: ["c:27017", "d:27017"],
                     me : "c:27017",
                     setName: "rs",
diff --git a/test/spec/server-discovery-and-monitoring/rs/primary_wrong_set_name.json b/test/spec/server-discovery-and-monitoring/rs/primary_wrong_set_name.json
index eda4787173..cc0691fb8c 100644
--- a/test/spec/server-discovery-and-monitoring/rs/primary_wrong_set_name.json
+++ b/test/spec/server-discovery-and-monitoring/rs/primary_wrong_set_name.json
@@ -8,7 +8,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
diff --git a/test/spec/server-discovery-and-monitoring/rs/primary_wrong_set_name.yml b/test/spec/server-discovery-and-monitoring/rs/primary_wrong_set_name.yml
index 4a06ce63c2..d4434522a9 100644
--- a/test/spec/server-discovery-and-monitoring/rs/primary_wrong_set_name.yml
+++ b/test/spec/server-discovery-and-monitoring/rs/primary_wrong_set_name.yml
@@ -10,7 +10,8 @@ phases: [
                 ["a:27017", {
 
                     ok: 1,
-                    ismaster: true,
+                    helloOk: true,
+                    isWritablePrimary: true,
                     hosts: ["a:27017"],
                     setName: "wrong",
                     minWireVersion: 0,
diff --git a/test/spec/server-discovery-and-monitoring/rs/repeated.json b/test/spec/server-discovery-and-monitoring/rs/repeated.json
index 392d485794..610aeae0ac 100644
--- a/test/spec/server-discovery-and-monitoring/rs/repeated.json
+++ b/test/spec/server-discovery-and-monitoring/rs/repeated.json
@@ -1,5 +1,5 @@
 {
-  "description": "Repeated ismaster response must be processed",
+  "description": "Repeated isWritablePrimary response must be processed",
   "uri": "mongodb://a,b/?replicaSet=rs",
   "phases": [
     {
@@ -8,7 +8,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": false,
+            "helloOk": true,
+            "isWritablePrimary": false,
             "secondary": true,
             "hidden": true,
             "hosts": [
@@ -45,7 +46,8 @@
           "c:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "minWireVersion": 0,
             "maxWireVersion": 6
           }
@@ -72,7 +74,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": false,
+            "helloOk": true,
+            "isWritablePrimary": false,
             "secondary": true,
             "hidden": true,
             "hosts": [
@@ -109,7 +112,8 @@
           "c:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017",
               "c:27017"
diff --git a/test/spec/server-discovery-and-monitoring/rs/repeated.yml b/test/spec/server-discovery-and-monitoring/rs/repeated.yml
index 141e41c9e2..f651005bab 100644
--- a/test/spec/server-discovery-and-monitoring/rs/repeated.yml
+++ b/test/spec/server-discovery-and-monitoring/rs/repeated.yml
@@ -1,4 +1,4 @@
-description: Repeated ismaster response must be processed
+description: Repeated isWritablePrimary response must be processed
 
 uri: "mongodb://a,b/?replicaSet=rs"
 
@@ -8,7 +8,8 @@ phases:
     -
       - "a:27017"
       - ok: 1
-        ismaster: false
+        helloOk: true
+        isWritablePrimary: false
         secondary: true
         hidden: true
         hosts: ["a:27017", "c:27017"]
@@ -35,7 +36,8 @@ phases:
     -
       - "c:27017"
       - ok: 1
-        ismaster: true
+        helloOk: true
+        isWritablePrimary: true
         minWireVersion: 0
         maxWireVersion: 6
     outcome:
@@ -55,7 +57,8 @@ phases:
     -
       - "a:27017"
       - ok: 1
-        ismaster: false
+        helloOk: true
+        isWritablePrimary: false
         secondary: true
         hidden: true
         hosts: ["a:27017", "c:27017"]
@@ -82,7 +85,8 @@ phases:
     -
       - "c:27017"
       - ok: 1
-        ismaster: true
+        helloOk: true
+        isWritablePrimary: true
         hosts: ["a:27017", "c:27017"]
         setName: "rs"
         minWireVersion: 0
diff --git a/test/spec/server-discovery-and-monitoring/rs/replicaset_rsnp.json b/test/spec/server-discovery-and-monitoring/rs/replicaset_rsnp.json
index a0f69de486..3148e1c141 100644
--- a/test/spec/server-discovery-and-monitoring/rs/replicaset_rsnp.json
+++ b/test/spec/server-discovery-and-monitoring/rs/replicaset_rsnp.json
@@ -8,7 +8,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "minWireVersion": 0,
             "maxWireVersion": 6
           }
diff --git a/test/spec/server-discovery-and-monitoring/rs/replicaset_rsnp.yml b/test/spec/server-discovery-and-monitoring/rs/replicaset_rsnp.yml
index cb15fac812..87e80bdb31 100644
--- a/test/spec/server-discovery-and-monitoring/rs/replicaset_rsnp.yml
+++ b/test/spec/server-discovery-and-monitoring/rs/replicaset_rsnp.yml
@@ -8,7 +8,8 @@ phases:
     -
       - "a:27017"
       - ok: 1
-        ismaster: true
+        helloOk: true
+        isWritablePrimary: true
         minWireVersion: 0
         maxWireVersion: 6
     outcome:
diff --git a/test/spec/server-discovery-and-monitoring/rs/response_from_removed.json b/test/spec/server-discovery-and-monitoring/rs/response_from_removed.json
index dd3562d7fc..87a66d9e72 100644
--- a/test/spec/server-discovery-and-monitoring/rs/response_from_removed.json
+++ b/test/spec/server-discovery-and-monitoring/rs/response_from_removed.json
@@ -8,7 +8,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "setName": "rs",
             "hosts": [
               "a:27017"
@@ -36,7 +37,8 @@
           "b:27017",
           {
             "ok": 1,
-            "ismaster": false,
+            "helloOk": true,
+            "isWritablePrimary": false,
             "secondary": true,
             "setName": "rs",
             "hosts": [
diff --git a/test/spec/server-discovery-and-monitoring/rs/response_from_removed.yml b/test/spec/server-discovery-and-monitoring/rs/response_from_removed.yml
index 061a839379..6ec66c8750 100644
--- a/test/spec/server-discovery-and-monitoring/rs/response_from_removed.yml
+++ b/test/spec/server-discovery-and-monitoring/rs/response_from_removed.yml
@@ -10,7 +10,8 @@ phases: [
                 ["a:27017", {
 
                     ok: 1,
-                    ismaster: true,
+                    helloOk: true,
+                    isWritablePrimary: true,
                     setName: "rs",
                     hosts: ["a:27017"],
                     minWireVersion: 0,
@@ -40,7 +41,8 @@ phases: [
                 ["b:27017", {
 
                     ok: 1,
-                    ismaster: false,
+                    helloOk: true,
+                    isWritablePrimary: false,
                     secondary: true,
                     setName: "rs",
                     hosts: ["a:27017", "b:27017"],
diff --git a/test/spec/server-discovery-and-monitoring/rs/sec_not_auth.json b/test/spec/server-discovery-and-monitoring/rs/sec_not_auth.json
index 7d5e700035..a39855e654 100644
--- a/test/spec/server-discovery-and-monitoring/rs/sec_not_auth.json
+++ b/test/spec/server-discovery-and-monitoring/rs/sec_not_auth.json
@@ -8,7 +8,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "setName": "rs",
             "hosts": [
               "a:27017",
@@ -22,7 +23,8 @@
           "b:27017",
           {
             "ok": 1,
-            "ismaster": false,
+            "helloOk": true,
+            "isWritablePrimary": false,
             "secondary": true,
             "setName": "rs",
             "hosts": [
diff --git a/test/spec/server-discovery-and-monitoring/rs/sec_not_auth.yml b/test/spec/server-discovery-and-monitoring/rs/sec_not_auth.yml
index 5caca0b9de..09c75f9c78 100644
--- a/test/spec/server-discovery-and-monitoring/rs/sec_not_auth.yml
+++ b/test/spec/server-discovery-and-monitoring/rs/sec_not_auth.yml
@@ -10,7 +10,8 @@ phases: [
                 ["a:27017", {
 
                     ok: 1,
-                    ismaster: true,
+                    helloOk: true,
+                    isWritablePrimary: true,
                     setName: "rs",
                     hosts: ["a:27017", "b:27017"],
                     minWireVersion: 0,
@@ -20,7 +21,8 @@ phases: [
                 ["b:27017", {
 
                     ok: 1,
-                    ismaster: false,
+                    helloOk: true,
+                    isWritablePrimary: false,
                     secondary: true,
                     setName: "rs",
                     hosts: ["b:27017", "c:27017"],
diff --git a/test/spec/server-discovery-and-monitoring/rs/secondary_ignore_ok_0.json b/test/spec/server-discovery-and-monitoring/rs/secondary_ignore_ok_0.json
index 6d3033eeee..4c1cb011a5 100644
--- a/test/spec/server-discovery-and-monitoring/rs/secondary_ignore_ok_0.json
+++ b/test/spec/server-discovery-and-monitoring/rs/secondary_ignore_ok_0.json
@@ -8,7 +8,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "setName": "rs",
             "hosts": [
               "a:27017",
@@ -22,7 +23,8 @@
           "b:27017",
           {
             "ok": 1,
-            "ismaster": false,
+            "helloOk": true,
+            "isWritablePrimary": false,
             "secondary": true,
             "setName": "rs",
             "hosts": [
diff --git a/test/spec/server-discovery-and-monitoring/rs/secondary_ignore_ok_0.yml b/test/spec/server-discovery-and-monitoring/rs/secondary_ignore_ok_0.yml
index a77166927f..c7e605d662 100644
--- a/test/spec/server-discovery-and-monitoring/rs/secondary_ignore_ok_0.yml
+++ b/test/spec/server-discovery-and-monitoring/rs/secondary_ignore_ok_0.yml
@@ -10,7 +10,8 @@ phases: [
                 ["a:27017", {
 
                     ok: 1,
-                    ismaster: true,
+                    helloOk: true,
+                    isWritablePrimary: true,
                     setName: "rs",
                     hosts: ["a:27017", "b:27017"],
                     minWireVersion: 0,
@@ -19,7 +20,8 @@ phases: [
                 ["b:27017", {
 
                     ok: 1,
-                    ismaster: false,
+                    helloOk: true,
+                    isWritablePrimary: false,
                     secondary: true,
                     setName: "rs",
                     hosts: ["a:27017", "b:27017"],
diff --git a/test/spec/server-discovery-and-monitoring/rs/secondary_mismatched_me.json b/test/spec/server-discovery-and-monitoring/rs/secondary_mismatched_me.json
index 769e272a66..6f1b9b5986 100644
--- a/test/spec/server-discovery-and-monitoring/rs/secondary_mismatched_me.json
+++ b/test/spec/server-discovery-and-monitoring/rs/secondary_mismatched_me.json
@@ -27,7 +27,8 @@
               "a:27017",
               "b:27017"
             ],
-            "ismaster": false,
+            "helloOk": true,
+            "isWritablePrimary": false,
             "ok": 1,
             "setName": "rs",
             "minWireVersion": 0,
diff --git a/test/spec/server-discovery-and-monitoring/rs/secondary_mismatched_me.yml b/test/spec/server-discovery-and-monitoring/rs/secondary_mismatched_me.yml
index be2ace0cf0..e5f0f9aceb 100644
--- a/test/spec/server-discovery-and-monitoring/rs/secondary_mismatched_me.yml
+++ b/test/spec/server-discovery-and-monitoring/rs/secondary_mismatched_me.yml
@@ -20,7 +20,8 @@ phases:
           hosts:
             - 'a:27017'
             - 'b:27017'
-          ismaster: false
+          helloOk: true
+          isWritablePrimary: false
           ok: 1
           setName: rs
           minWireVersion: 0
diff --git a/test/spec/server-discovery-and-monitoring/rs/secondary_wrong_set_name.json b/test/spec/server-discovery-and-monitoring/rs/secondary_wrong_set_name.json
index 4c132b633e..8d2f152f59 100644
--- a/test/spec/server-discovery-and-monitoring/rs/secondary_wrong_set_name.json
+++ b/test/spec/server-discovery-and-monitoring/rs/secondary_wrong_set_name.json
@@ -8,7 +8,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": false,
+            "helloOk": true,
+            "isWritablePrimary": false,
             "secondary": true,
             "hosts": [
               "a:27017"
diff --git a/test/spec/server-discovery-and-monitoring/rs/secondary_wrong_set_name.yml b/test/spec/server-discovery-and-monitoring/rs/secondary_wrong_set_name.yml
index 10ae3674f0..0121d631ce 100644
--- a/test/spec/server-discovery-and-monitoring/rs/secondary_wrong_set_name.yml
+++ b/test/spec/server-discovery-and-monitoring/rs/secondary_wrong_set_name.yml
@@ -10,7 +10,8 @@ phases: [
                 ["a:27017", {
 
                     ok: 1,
-                    ismaster: false,
+                    helloOk: true,
+                    isWritablePrimary: false,
                     secondary: true,
                     hosts: ["a:27017"],
                     setName: "wrong",
diff --git a/test/spec/server-discovery-and-monitoring/rs/secondary_wrong_set_name_with_primary.json b/test/spec/server-discovery-and-monitoring/rs/secondary_wrong_set_name_with_primary.json
index 73cbab7c5d..b7ef2d6d6a 100644
--- a/test/spec/server-discovery-and-monitoring/rs/secondary_wrong_set_name_with_primary.json
+++ b/test/spec/server-discovery-and-monitoring/rs/secondary_wrong_set_name_with_primary.json
@@ -8,7 +8,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017",
               "b:27017"
@@ -41,7 +42,8 @@
           "b:27017",
           {
             "ok": 1,
-            "ismaster": false,
+            "helloOk": true,
+            "isWritablePrimary": false,
             "secondary": true,
             "hosts": [
               "a:27017",
diff --git a/test/spec/server-discovery-and-monitoring/rs/secondary_wrong_set_name_with_primary.yml b/test/spec/server-discovery-and-monitoring/rs/secondary_wrong_set_name_with_primary.yml
index 667d93e38a..acd471e78b 100644
--- a/test/spec/server-discovery-and-monitoring/rs/secondary_wrong_set_name_with_primary.yml
+++ b/test/spec/server-discovery-and-monitoring/rs/secondary_wrong_set_name_with_primary.yml
@@ -10,7 +10,8 @@ phases: [
                 ["a:27017", {
 
                     ok: 1,
-                    ismaster: true,
+                    helloOk: true,
+                    isWritablePrimary: true,
                     hosts: ["a:27017", "b:27017"],
                     setName: "rs",
                     minWireVersion: 0,
@@ -46,7 +47,8 @@ phases: [
                 ["b:27017", {
 
                     ok: 1,
-                    ismaster: false,
+                    helloOk: true,
+                    isWritablePrimary: false,
                     secondary: true,
                     hosts: ["a:27017", "b:27017"],
                     setName: "wrong",
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 0500c6d157..2f68287f1d 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
@@ -8,7 +8,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017",
               "b:27017"
@@ -46,7 +47,8 @@
           "b:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017",
               "b:27017"
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 17bf9415ce..55c841f24b 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
@@ -9,7 +9,8 @@ phases: [
         responses: [
             ["a:27017", {
                 ok: 1,
-                ismaster: true,
+                helloOk: true,
+                isWritablePrimary: true,
                 hosts: ["a:27017", "b:27017"],
                 setName: "rs",
                 setVersion: 2,
@@ -45,7 +46,8 @@ phases: [
         responses: [
             ["b:27017", {
                 ok: 1,
-                ismaster: true,
+                helloOk: true,
+                isWritablePrimary: true,
                 hosts: ["a:27017", "b:27017"],
                 setName: "rs",
                 setVersion: 1,
diff --git a/test/spec/server-discovery-and-monitoring/rs/stepdown_change_set_name.json b/test/spec/server-discovery-and-monitoring/rs/stepdown_change_set_name.json
index 39a4f532dd..e9075f97f2 100644
--- a/test/spec/server-discovery-and-monitoring/rs/stepdown_change_set_name.json
+++ b/test/spec/server-discovery-and-monitoring/rs/stepdown_change_set_name.json
@@ -8,7 +8,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
@@ -36,7 +37,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": false,
+            "helloOk": true,
+            "isWritablePrimary": false,
             "secondary": true,
             "hosts": [
               "a:27017"
diff --git a/test/spec/server-discovery-and-monitoring/rs/stepdown_change_set_name.yml b/test/spec/server-discovery-and-monitoring/rs/stepdown_change_set_name.yml
index 0d38f33e94..9c4140925d 100644
--- a/test/spec/server-discovery-and-monitoring/rs/stepdown_change_set_name.yml
+++ b/test/spec/server-discovery-and-monitoring/rs/stepdown_change_set_name.yml
@@ -11,7 +11,8 @@ phases: [
                 ["a:27017", {
 
                     ok: 1,
-                    ismaster: true,
+                    helloOk: true,
+                    isWritablePrimary: true,
                     hosts: ["a:27017"],
                     setName: "rs",
                     minWireVersion: 0,
@@ -43,7 +44,8 @@ phases: [
                 ["a:27017", {
 
                     ok: 1,
-                    ismaster: false,
+                    helloOk: true,
+                    isWritablePrimary: false,
                     secondary: true,
                     hosts: ["a:27017"],
                     setName: "wrong",
diff --git a/test/spec/server-discovery-and-monitoring/rs/too_new.json b/test/spec/server-discovery-and-monitoring/rs/too_new.json
index 945145af88..0433d27a36 100644
--- a/test/spec/server-discovery-and-monitoring/rs/too_new.json
+++ b/test/spec/server-discovery-and-monitoring/rs/too_new.json
@@ -8,7 +8,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "setName": "rs",
             "hosts": [
               "a:27017",
@@ -22,7 +23,8 @@
           "b:27017",
           {
             "ok": 1,
-            "ismaster": false,
+            "helloOk": true,
+            "isWritablePrimary": false,
             "secondary": true,
             "setName": "rs",
             "hosts": [
diff --git a/test/spec/server-discovery-and-monitoring/rs/too_new.yml b/test/spec/server-discovery-and-monitoring/rs/too_new.yml
index 5f185f7a19..52912826be 100644
--- a/test/spec/server-discovery-and-monitoring/rs/too_new.yml
+++ b/test/spec/server-discovery-and-monitoring/rs/too_new.yml
@@ -7,7 +7,8 @@ phases: [
         responses: [
                 ["a:27017", {
                     ok: 1,
-                    ismaster: true,
+                    helloOk: true,
+                    isWritablePrimary: true,
                     setName: "rs",
                     hosts: ["a:27017", "b:27017"],
                     minWireVersion: 0,
@@ -15,7 +16,8 @@ phases: [
                 }],
                 ["b:27017", {
                     ok: 1,
-                    ismaster: false,
+                    helloOk: true,
+                    isWritablePrimary: false,
                     secondary: true,
                     setName: "rs",
                     hosts: ["a:27017", "b:27017"],
diff --git a/test/spec/server-discovery-and-monitoring/rs/too_old.json b/test/spec/server-discovery-and-monitoring/rs/too_old.json
index 3f9eadc4bc..461d00acc4 100644
--- a/test/spec/server-discovery-and-monitoring/rs/too_old.json
+++ b/test/spec/server-discovery-and-monitoring/rs/too_old.json
@@ -8,7 +8,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "setName": "rs",
             "hosts": [
               "a:27017",
@@ -22,7 +23,8 @@
           "b:27017",
           {
             "ok": 1,
-            "ismaster": false,
+            "helloOk": true,
+            "isWritablePrimary": false,
             "secondary": true,
             "setName": "rs",
             "hosts": [
diff --git a/test/spec/server-discovery-and-monitoring/rs/too_old.yml b/test/spec/server-discovery-and-monitoring/rs/too_old.yml
index faa29ba596..ab238dbab9 100644
--- a/test/spec/server-discovery-and-monitoring/rs/too_old.yml
+++ b/test/spec/server-discovery-and-monitoring/rs/too_old.yml
@@ -5,7 +5,8 @@ phases: [
         responses: [
                 ["a:27017", {
                     ok: 1,
-                    ismaster: true,
+                    helloOk: true,
+                    isWritablePrimary: true,
                     setName: "rs",
                     hosts: ["a:27017", "b:27017"],
                     minWireVersion: 0,
@@ -13,7 +14,8 @@ phases: [
                 }],
                 ["b:27017", {
                     ok: 1,
-                    ismaster: false,
+                    helloOk: true,
+                    isWritablePrimary: false,
                     secondary: true,
                     setName: "rs",
                     hosts: ["a:27017", "b:27017"]
diff --git a/test/spec/server-discovery-and-monitoring/rs/topology_version_equal.json b/test/spec/server-discovery-and-monitoring/rs/topology_version_equal.json
index ba84e059a0..d3baa13479 100644
--- a/test/spec/server-discovery-and-monitoring/rs/topology_version_equal.json
+++ b/test/spec/server-discovery-and-monitoring/rs/topology_version_equal.json
@@ -8,7 +8,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
@@ -52,7 +53,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017",
               "b:27017"
diff --git a/test/spec/server-discovery-and-monitoring/rs/topology_version_equal.yml b/test/spec/server-discovery-and-monitoring/rs/topology_version_equal.yml
index 104194ac84..3ce3bb6050 100644
--- a/test/spec/server-discovery-and-monitoring/rs/topology_version_equal.yml
+++ b/test/spec/server-discovery-and-monitoring/rs/topology_version_equal.yml
@@ -9,7 +9,8 @@ phases: [
         responses: [
             ["a:27017", {
                 ok: 1,
-                ismaster: true,
+                helloOk: true,
+                isWritablePrimary: true,
                 hosts: ["a:27017"],
                 setName: "rs",
                 minWireVersion: 0,
@@ -37,7 +38,8 @@ phases: [
         responses: [
             ["a:27017", {
                 ok: 1,
-                ismaster: true,
+                helloOk: true,
+                isWritablePrimary: true,
                 hosts: ["a:27017", "b:27017"],
                 setName: "rs",
                 minWireVersion: 0,
diff --git a/test/spec/server-discovery-and-monitoring/rs/topology_version_greater.json b/test/spec/server-discovery-and-monitoring/rs/topology_version_greater.json
index afa8108ea2..f296ccee62 100644
--- a/test/spec/server-discovery-and-monitoring/rs/topology_version_greater.json
+++ b/test/spec/server-discovery-and-monitoring/rs/topology_version_greater.json
@@ -8,7 +8,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
@@ -52,7 +53,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017",
               "b:27017"
@@ -101,7 +103,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017",
               "c:27017"
@@ -150,7 +153,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017",
               "d:27017"
@@ -184,7 +188,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017",
               "e:27017"
diff --git a/test/spec/server-discovery-and-monitoring/rs/topology_version_greater.yml b/test/spec/server-discovery-and-monitoring/rs/topology_version_greater.yml
index 4edf99ba8c..89603d604d 100644
--- a/test/spec/server-discovery-and-monitoring/rs/topology_version_greater.yml
+++ b/test/spec/server-discovery-and-monitoring/rs/topology_version_greater.yml
@@ -9,7 +9,8 @@ phases: [
         responses: [
             ["a:27017", {
                 ok: 1,
-                ismaster: true,
+                helloOk: true,
+                isWritablePrimary: true,
                 hosts: ["a:27017"],
                 setName: "rs",
                 minWireVersion: 0,
@@ -37,7 +38,8 @@ phases: [
         responses: [
             ["a:27017", {
                 ok: 1,
-                ismaster: true,
+                helloOk: true,
+                isWritablePrimary: true,
                 hosts: ["a:27017", "b:27017"],
                 setName: "rs",
                 minWireVersion: 0,
@@ -70,7 +72,8 @@ phases: [
         responses: [
             ["a:27017", {
                 ok: 1,
-                ismaster: true,
+                helloOk: true,
+                isWritablePrimary: true,
                 hosts: ["a:27017", "c:27017"],
                 setName: "rs",
                 minWireVersion: 0,
@@ -103,7 +106,8 @@ phases: [
         responses: [
             ["a:27017", {
                 ok: 1,
-                ismaster: true,
+                helloOk: true,
+                isWritablePrimary: true,
                 hosts: ["a:27017", "d:27017"],
                 setName: "rs",
                 minWireVersion: 0,
@@ -135,7 +139,8 @@ phases: [
         responses: [
             ["a:27017", {
                 ok: 1,
-                ismaster: true,
+                helloOk: true,
+                isWritablePrimary: true,
                 hosts: ["a:27017", "e:27017"],
                 setName: "rs",
                 minWireVersion: 0,
diff --git a/test/spec/server-discovery-and-monitoring/rs/topology_version_less.json b/test/spec/server-discovery-and-monitoring/rs/topology_version_less.json
index ae45f803d4..435337ff25 100644
--- a/test/spec/server-discovery-and-monitoring/rs/topology_version_less.json
+++ b/test/spec/server-discovery-and-monitoring/rs/topology_version_less.json
@@ -8,7 +8,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017"
             ],
@@ -52,7 +53,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017",
               "b:27017"
diff --git a/test/spec/server-discovery-and-monitoring/rs/topology_version_less.yml b/test/spec/server-discovery-and-monitoring/rs/topology_version_less.yml
index 1faac9b9a7..1c23e7849e 100644
--- a/test/spec/server-discovery-and-monitoring/rs/topology_version_less.yml
+++ b/test/spec/server-discovery-and-monitoring/rs/topology_version_less.yml
@@ -9,7 +9,8 @@ phases: [
         responses: [
             ["a:27017", {
                 ok: 1,
-                ismaster: true,
+                helloOk: true,
+                isWritablePrimary: true,
                 hosts: ["a:27017"],
                 setName: "rs",
                 minWireVersion: 0,
@@ -37,7 +38,8 @@ phases: [
         responses: [
             ["a:27017", {
                 ok: 1,
-                ismaster: true,
+                helloOk: true,
+                isWritablePrimary: true,
                 hosts: ["a:27017", "b:27017"],
                 setName: "rs",
                 minWireVersion: 0,
diff --git a/test/spec/server-discovery-and-monitoring/rs/unexpected_mongos.json b/test/spec/server-discovery-and-monitoring/rs/unexpected_mongos.json
index 95c7aa9dce..cc19a961f2 100644
--- a/test/spec/server-discovery-and-monitoring/rs/unexpected_mongos.json
+++ b/test/spec/server-discovery-and-monitoring/rs/unexpected_mongos.json
@@ -8,7 +8,8 @@
           "b:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "msg": "isdbgrid",
             "minWireVersion": 0,
             "maxWireVersion": 6
diff --git a/test/spec/server-discovery-and-monitoring/rs/unexpected_mongos.yml b/test/spec/server-discovery-and-monitoring/rs/unexpected_mongos.yml
index 37d2f09223..d0d8547f96 100644
--- a/test/spec/server-discovery-and-monitoring/rs/unexpected_mongos.yml
+++ b/test/spec/server-discovery-and-monitoring/rs/unexpected_mongos.yml
@@ -10,7 +10,8 @@ phases: [
                 ["b:27017", {
 
                     ok: 1,
-                    ismaster: true,
+                    helloOk: true,
+                    isWritablePrimary: true,
                     msg: "isdbgrid",
                     minWireVersion: 0,
                     maxWireVersion: 6
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 16225d6b83..421ff57c8d 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
@@ -8,7 +8,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017",
               "b:27017"
@@ -54,7 +55,8 @@
           "b:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017",
               "b:27017"
@@ -94,7 +96,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017",
               "b:27017"
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 003cff4416..300f9d9304 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
@@ -9,7 +9,8 @@ phases: [
         responses: [
             ["a:27017", {
                 ok: 1,
-                ismaster: true,
+                helloOk: true,
+                isWritablePrimary: true,
                 hosts: ["a:27017", "b:27017"],
                 setName: "rs",
                 setVersion: 1,
@@ -46,7 +47,8 @@ phases: [
         responses: [
             ["b:27017", {
                 ok: 1,
-                ismaster: true,
+                helloOk: true,
+                isWritablePrimary: true,
                 hosts: ["a:27017", "b:27017"],
                 setName: "rs",
                 setVersion: 2,
@@ -82,7 +84,8 @@ phases: [
         responses: [
             ["a:27017", {
                 ok: 1,
-                ismaster: true,
+                helloOk: true,
+                isWritablePrimary: true,
                 hosts: ["a:27017", "b:27017"],
                 setName: "rs",
                 setVersion: 1,
diff --git a/test/spec/server-discovery-and-monitoring/rs/wrong_set_name.json b/test/spec/server-discovery-and-monitoring/rs/wrong_set_name.json
index 45be2f502b..9654ff7b79 100644
--- a/test/spec/server-discovery-and-monitoring/rs/wrong_set_name.json
+++ b/test/spec/server-discovery-and-monitoring/rs/wrong_set_name.json
@@ -8,7 +8,8 @@
           "b:27017",
           {
             "ok": 1,
-            "ismaster": false,
+            "helloOk": true,
+            "isWritablePrimary": false,
             "secondary": true,
             "hosts": [
               "b:27017",
diff --git a/test/spec/server-discovery-and-monitoring/rs/wrong_set_name.yml b/test/spec/server-discovery-and-monitoring/rs/wrong_set_name.yml
index 93004e8783..ae75d6f7e4 100644
--- a/test/spec/server-discovery-and-monitoring/rs/wrong_set_name.yml
+++ b/test/spec/server-discovery-and-monitoring/rs/wrong_set_name.yml
@@ -10,7 +10,8 @@ phases: [
                 ["b:27017", {
 
                     ok: 1,
-                    ismaster: false,
+                    helloOk: true,
+                    isWritablePrimary: false,
                     secondary: true,
                     hosts: ["b:27017", "c:27017"],
                     setName: "wrong",
diff --git a/test/spec/server-discovery-and-monitoring/sharded/compatible.json b/test/spec/server-discovery-and-monitoring/sharded/compatible.json
index 3dae1f7ea1..e531db97f9 100644
--- a/test/spec/server-discovery-and-monitoring/sharded/compatible.json
+++ b/test/spec/server-discovery-and-monitoring/sharded/compatible.json
@@ -8,7 +8,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "msg": "isdbgrid",
             "minWireVersion": 0,
             "maxWireVersion": 1000
@@ -18,7 +19,8 @@
           "b:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "msg": "isdbgrid",
             "minWireVersion": 0,
             "maxWireVersion": 6
diff --git a/test/spec/server-discovery-and-monitoring/sharded/compatible.yml b/test/spec/server-discovery-and-monitoring/sharded/compatible.yml
index 4e05a0e0ae..06d5182a5c 100644
--- a/test/spec/server-discovery-and-monitoring/sharded/compatible.yml
+++ b/test/spec/server-discovery-and-monitoring/sharded/compatible.yml
@@ -5,14 +5,16 @@ phases: [
         responses: [
                 ["a:27017", {
                     ok: 1,
-                    ismaster: true,
+                    helloOk: true,
+                    isWritablePrimary: true,
                     msg: "isdbgrid",
                     minWireVersion: 0,
                     maxWireVersion: 1000
                 }],
                 ["b:27017", {
                     ok: 1,
-                    ismaster: true,
+                    helloOk: true,
+                    isWritablePrimary: true,
                     msg: "isdbgrid",
                     minWireVersion: 0,
                     maxWireVersion: 6
diff --git a/test/spec/server-discovery-and-monitoring/sharded/discover_single_mongos.json b/test/spec/server-discovery-and-monitoring/sharded/discover_single_mongos.json
index 427889f8cc..9e877a0840 100644
--- a/test/spec/server-discovery-and-monitoring/sharded/discover_single_mongos.json
+++ b/test/spec/server-discovery-and-monitoring/sharded/discover_single_mongos.json
@@ -8,7 +8,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "msg": "isdbgrid",
             "minWireVersion": 0,
             "maxWireVersion": 6
diff --git a/test/spec/server-discovery-and-monitoring/sharded/discover_single_mongos.yml b/test/spec/server-discovery-and-monitoring/sharded/discover_single_mongos.yml
index be12100925..f44a2970dd 100644
--- a/test/spec/server-discovery-and-monitoring/sharded/discover_single_mongos.yml
+++ b/test/spec/server-discovery-and-monitoring/sharded/discover_single_mongos.yml
@@ -9,7 +9,8 @@ phases:
       - "a:27017"
       -
         ok: 1
-        ismaster: true
+        helloOk: true
+        isWritablePrimary: true
         msg: "isdbgrid"
         minWireVersion: 0
         maxWireVersion: 6
diff --git a/test/spec/server-discovery-and-monitoring/sharded/ls_timeout_mongos.json b/test/spec/server-discovery-and-monitoring/sharded/ls_timeout_mongos.json
index 96f8dec17a..93fa398d52 100644
--- a/test/spec/server-discovery-and-monitoring/sharded/ls_timeout_mongos.json
+++ b/test/spec/server-discovery-and-monitoring/sharded/ls_timeout_mongos.json
@@ -8,7 +8,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "msg": "isdbgrid",
             "logicalSessionTimeoutMinutes": 1,
             "minWireVersion": 0,
@@ -19,7 +20,8 @@
           "b:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "msg": "isdbgrid",
             "logicalSessionTimeoutMinutes": 2,
             "minWireVersion": 0,
@@ -49,7 +51,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "msg": "isdbgrid",
             "logicalSessionTimeoutMinutes": 1,
             "minWireVersion": 0,
@@ -60,7 +63,8 @@
           "b:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "msg": "isdbgrid",
             "minWireVersion": 0,
             "maxWireVersion": 6
diff --git a/test/spec/server-discovery-and-monitoring/sharded/ls_timeout_mongos.yml b/test/spec/server-discovery-and-monitoring/sharded/ls_timeout_mongos.yml
index 8da08da783..7f78d0d6c6 100644
--- a/test/spec/server-discovery-and-monitoring/sharded/ls_timeout_mongos.yml
+++ b/test/spec/server-discovery-and-monitoring/sharded/ls_timeout_mongos.yml
@@ -10,7 +10,8 @@ phases: [
                 ["a:27017", {
 
                     ok: 1,
-                    ismaster: true,
+                    helloOk: true,
+                    isWritablePrimary: true,
                     msg: "isdbgrid",
                     logicalSessionTimeoutMinutes: 1,
                     minWireVersion: 0,
@@ -20,7 +21,8 @@ phases: [
                 ["b:27017", {
 
                     ok: 1,
-                    ismaster: true,
+                    helloOk: true,
+                    isWritablePrimary: true,
                     msg: "isdbgrid",
                     logicalSessionTimeoutMinutes: 2,
                     minWireVersion: 0,
@@ -49,14 +51,15 @@ phases: [
             setName:
         }
     },
-    # Now an ismaster response with no logicalSessionTimeoutMinutes
+    # Now an isWritablePrimary response with no logicalSessionTimeoutMinutes
     {
         responses: [
 
                 ["a:27017", {
 
                     ok: 1,
-                    ismaster: true,
+                    helloOk: true,
+                    isWritablePrimary: true,
                     msg: "isdbgrid",
                     logicalSessionTimeoutMinutes: 1,
                     minWireVersion: 0,
@@ -66,7 +69,8 @@ phases: [
                 ["b:27017", {
 
                     ok: 1,
-                    ismaster: true,
+                    helloOk: true,
+                    isWritablePrimary: true,
                     msg: "isdbgrid",
                     minWireVersion: 0,
                     maxWireVersion: 6
diff --git a/test/spec/server-discovery-and-monitoring/sharded/mongos_disconnect.json b/test/spec/server-discovery-and-monitoring/sharded/mongos_disconnect.json
index 04015694a8..50a93eda5f 100644
--- a/test/spec/server-discovery-and-monitoring/sharded/mongos_disconnect.json
+++ b/test/spec/server-discovery-and-monitoring/sharded/mongos_disconnect.json
@@ -8,7 +8,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "msg": "isdbgrid",
             "minWireVersion": 0,
             "maxWireVersion": 6
@@ -18,7 +19,8 @@
           "b:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "msg": "isdbgrid",
             "minWireVersion": 0,
             "maxWireVersion": 6
@@ -70,7 +72,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "msg": "isdbgrid",
             "minWireVersion": 0,
             "maxWireVersion": 6
diff --git a/test/spec/server-discovery-and-monitoring/sharded/mongos_disconnect.yml b/test/spec/server-discovery-and-monitoring/sharded/mongos_disconnect.yml
index bb9890b8fe..c4393d85b1 100644
--- a/test/spec/server-discovery-and-monitoring/sharded/mongos_disconnect.yml
+++ b/test/spec/server-discovery-and-monitoring/sharded/mongos_disconnect.yml
@@ -10,7 +10,8 @@ phases: [
                 ["a:27017", {
 
                     ok: 1,
-                    ismaster: true,
+                    helloOk: true,
+                    isWritablePrimary: true,
                     msg: "isdbgrid",
                     minWireVersion: 0,
                     maxWireVersion: 6
@@ -19,7 +20,8 @@ phases: [
                 ["b:27017", {
 
                     ok: 1,
-                    ismaster: true,
+                    helloOk: true,
+                    isWritablePrimary: true,
                     msg: "isdbgrid",
                     minWireVersion: 0,
                     maxWireVersion: 6
@@ -79,7 +81,8 @@ phases: [
                 ["a:27017", {
 
                     ok: 1,
-                    ismaster: true,
+                    helloOk: true,
+                    isWritablePrimary: true,
                     msg: "isdbgrid",
                     minWireVersion: 0,
                     maxWireVersion: 6
diff --git a/test/spec/server-discovery-and-monitoring/sharded/multiple_mongoses.json b/test/spec/server-discovery-and-monitoring/sharded/multiple_mongoses.json
index 6e60fd05c7..311592d715 100644
--- a/test/spec/server-discovery-and-monitoring/sharded/multiple_mongoses.json
+++ b/test/spec/server-discovery-and-monitoring/sharded/multiple_mongoses.json
@@ -8,7 +8,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "msg": "isdbgrid",
             "minWireVersion": 0,
             "maxWireVersion": 6
@@ -18,7 +19,8 @@
           "b:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "msg": "isdbgrid",
             "minWireVersion": 0,
             "maxWireVersion": 6
diff --git a/test/spec/server-discovery-and-monitoring/sharded/multiple_mongoses.yml b/test/spec/server-discovery-and-monitoring/sharded/multiple_mongoses.yml
index 462478c0bd..0a49d64249 100644
--- a/test/spec/server-discovery-and-monitoring/sharded/multiple_mongoses.yml
+++ b/test/spec/server-discovery-and-monitoring/sharded/multiple_mongoses.yml
@@ -10,7 +10,8 @@ phases: [
                 ["a:27017", {
 
                     ok: 1,
-                    ismaster: true,
+                    helloOk: true,
+                    isWritablePrimary: true,
                     msg: "isdbgrid",
                     minWireVersion: 0,
                     maxWireVersion: 6
@@ -19,7 +20,8 @@ phases: [
                 ["b:27017", {
 
                     ok: 1,
-                    ismaster: true,
+                    helloOk: true,
+                    isWritablePrimary: true,
                     msg: "isdbgrid",
                     minWireVersion: 0,
                     maxWireVersion: 6
diff --git a/test/spec/server-discovery-and-monitoring/sharded/non_mongos_removed.json b/test/spec/server-discovery-and-monitoring/sharded/non_mongos_removed.json
index 58cf7c07d7..d74375ebbf 100644
--- a/test/spec/server-discovery-and-monitoring/sharded/non_mongos_removed.json
+++ b/test/spec/server-discovery-and-monitoring/sharded/non_mongos_removed.json
@@ -8,7 +8,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "msg": "isdbgrid",
             "minWireVersion": 0,
             "maxWireVersion": 6
@@ -18,7 +19,8 @@
           "b:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "b:27017"
             ],
diff --git a/test/spec/server-discovery-and-monitoring/sharded/non_mongos_removed.yml b/test/spec/server-discovery-and-monitoring/sharded/non_mongos_removed.yml
index 476c799705..ab25349bda 100644
--- a/test/spec/server-discovery-and-monitoring/sharded/non_mongos_removed.yml
+++ b/test/spec/server-discovery-and-monitoring/sharded/non_mongos_removed.yml
@@ -10,7 +10,8 @@ phases: [
                 ["a:27017", {
 
                     ok: 1,
-                    ismaster: true,
+                    helloOk: true,
+                    isWritablePrimary: true,
                     msg: "isdbgrid",
                     minWireVersion: 0,
                     maxWireVersion: 6
@@ -19,7 +20,8 @@ phases: [
                 ["b:27017", {
 
                     ok: 1,
-                    ismaster: true,
+                    helloOk: true,
+                    isWritablePrimary: true,
                     hosts: ["b:27017"],
                     setName: "rs",
                     minWireVersion: 0,
diff --git a/test/spec/server-discovery-and-monitoring/sharded/too_new.json b/test/spec/server-discovery-and-monitoring/sharded/too_new.json
index 9521e11789..4b997d2163 100644
--- a/test/spec/server-discovery-and-monitoring/sharded/too_new.json
+++ b/test/spec/server-discovery-and-monitoring/sharded/too_new.json
@@ -8,7 +8,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "msg": "isdbgrid",
             "minWireVersion": 999,
             "maxWireVersion": 1000
@@ -18,7 +19,8 @@
           "b:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "msg": "isdbgrid"
           }
         ]
diff --git a/test/spec/server-discovery-and-monitoring/sharded/too_new.yml b/test/spec/server-discovery-and-monitoring/sharded/too_new.yml
index 4e03636879..7d59cb4305 100644
--- a/test/spec/server-discovery-and-monitoring/sharded/too_new.yml
+++ b/test/spec/server-discovery-and-monitoring/sharded/too_new.yml
@@ -5,14 +5,16 @@ phases: [
         responses: [
                 ["a:27017", {
                     ok: 1,
-                    ismaster: true,
+                    helloOk: true,
+                    isWritablePrimary: true,
                     msg: "isdbgrid",
                     minWireVersion: 999,
                     maxWireVersion: 1000
                 }],
                 ["b:27017", {
                     ok: 1,
-                    ismaster: true,
+                    helloOk: true,
+                    isWritablePrimary: true,
                     msg: "isdbgrid"
                 }]
         ],
diff --git a/test/spec/server-discovery-and-monitoring/sharded/too_old.json b/test/spec/server-discovery-and-monitoring/sharded/too_old.json
index 6bd187f61d..688e1db0f5 100644
--- a/test/spec/server-discovery-and-monitoring/sharded/too_old.json
+++ b/test/spec/server-discovery-and-monitoring/sharded/too_old.json
@@ -8,7 +8,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "msg": "isdbgrid",
             "minWireVersion": 2,
             "maxWireVersion": 6
@@ -18,7 +19,8 @@
           "b:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "msg": "isdbgrid"
           }
         ]
diff --git a/test/spec/server-discovery-and-monitoring/sharded/too_old.yml b/test/spec/server-discovery-and-monitoring/sharded/too_old.yml
index 2870057028..925a8f55b8 100644
--- a/test/spec/server-discovery-and-monitoring/sharded/too_old.yml
+++ b/test/spec/server-discovery-and-monitoring/sharded/too_old.yml
@@ -5,14 +5,16 @@ phases: [
         responses: [
                 ["a:27017", {
                     ok: 1,
-                    ismaster: true,
+                    helloOk: true,
+                    isWritablePrimary: true,
                     msg: "isdbgrid",
                     minWireVersion: 2,
                     maxWireVersion: 6
                 }],
                 ["b:27017", {
                     ok: 1,
-                    ismaster: true,
+                    helloOk: true,
+                    isWritablePrimary: true,
                     msg: "isdbgrid"
                 }]
         ],
diff --git a/test/spec/server-discovery-and-monitoring/single/compatible.json b/test/spec/server-discovery-and-monitoring/single/compatible.json
index ee6b847ade..302927598c 100644
--- a/test/spec/server-discovery-and-monitoring/single/compatible.json
+++ b/test/spec/server-discovery-and-monitoring/single/compatible.json
@@ -8,7 +8,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "minWireVersion": 0,
             "maxWireVersion": 6
           }
diff --git a/test/spec/server-discovery-and-monitoring/single/compatible.yml b/test/spec/server-discovery-and-monitoring/single/compatible.yml
index eff9b73cdd..b84c1388c3 100644
--- a/test/spec/server-discovery-and-monitoring/single/compatible.yml
+++ b/test/spec/server-discovery-and-monitoring/single/compatible.yml
@@ -5,7 +5,8 @@ phases: [
         responses: [
                 ["a:27017", {
                     ok: 1,
-                    ismaster: true,
+                    helloOk: true,
+                    isWritablePrimary: true,
                     minWireVersion: 0,
                     maxWireVersion: 6
                 }]
diff --git a/test/spec/server-discovery-and-monitoring/single/direct_connection_external_ip.json b/test/spec/server-discovery-and-monitoring/single/direct_connection_external_ip.json
index afd5edc1d2..90676a8f9b 100644
--- a/test/spec/server-discovery-and-monitoring/single/direct_connection_external_ip.json
+++ b/test/spec/server-discovery-and-monitoring/single/direct_connection_external_ip.json
@@ -8,7 +8,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "b:27017"
             ],
diff --git a/test/spec/server-discovery-and-monitoring/single/direct_connection_external_ip.yml b/test/spec/server-discovery-and-monitoring/single/direct_connection_external_ip.yml
index 1b3a8db70b..18c01226a9 100644
--- a/test/spec/server-discovery-and-monitoring/single/direct_connection_external_ip.yml
+++ b/test/spec/server-discovery-and-monitoring/single/direct_connection_external_ip.yml
@@ -10,7 +10,8 @@ phases: [
                 ["a:27017", {
 
                     ok: 1,
-                    ismaster: true,
+                    helloOk: true,
+                    isWritablePrimary: true,
                     hosts: ["b:27017"],  # Internal IP.
                     setName: "rs",
                     minWireVersion: 0,
diff --git a/test/spec/server-discovery-and-monitoring/single/direct_connection_mongos.json b/test/spec/server-discovery-and-monitoring/single/direct_connection_mongos.json
index 9175049cc6..25fe965185 100644
--- a/test/spec/server-discovery-and-monitoring/single/direct_connection_mongos.json
+++ b/test/spec/server-discovery-and-monitoring/single/direct_connection_mongos.json
@@ -8,7 +8,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "msg": "isdbgrid",
             "minWireVersion": 0,
             "maxWireVersion": 6
diff --git a/test/spec/server-discovery-and-monitoring/single/direct_connection_mongos.yml b/test/spec/server-discovery-and-monitoring/single/direct_connection_mongos.yml
index 1253bbcc8d..853ce57c17 100644
--- a/test/spec/server-discovery-and-monitoring/single/direct_connection_mongos.yml
+++ b/test/spec/server-discovery-and-monitoring/single/direct_connection_mongos.yml
@@ -10,7 +10,8 @@ phases: [
                 ["a:27017", {
 
                     ok: 1,
-                    ismaster: true,
+                    helloOk: true,
+                    isWritablePrimary: true,
                     msg: "isdbgrid",
                     minWireVersion: 0,
                     maxWireVersion: 6
diff --git a/test/spec/server-discovery-and-monitoring/single/direct_connection_replicaset.json b/test/spec/server-discovery-and-monitoring/single/direct_connection_replicaset.json
index c629a709be..cd8660888a 100644
--- a/test/spec/server-discovery-and-monitoring/single/direct_connection_replicaset.json
+++ b/test/spec/server-discovery-and-monitoring/single/direct_connection_replicaset.json
@@ -8,7 +8,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "setName": "rs",
             "minWireVersion": 0,
             "maxWireVersion": 6
diff --git a/test/spec/server-discovery-and-monitoring/single/direct_connection_replicaset.yml b/test/spec/server-discovery-and-monitoring/single/direct_connection_replicaset.yml
index 25418e66e1..21e565fd9c 100644
--- a/test/spec/server-discovery-and-monitoring/single/direct_connection_replicaset.yml
+++ b/test/spec/server-discovery-and-monitoring/single/direct_connection_replicaset.yml
@@ -8,7 +8,8 @@ phases:
     -
       - "a:27017"
       - ok: 1
-        ismaster: true
+        helloOk: true
+        isWritablePrimary: true
         setName: rs
         minWireVersion: 0
         maxWireVersion: 6
diff --git a/test/spec/server-discovery-and-monitoring/single/direct_connection_rsarbiter.json b/test/spec/server-discovery-and-monitoring/single/direct_connection_rsarbiter.json
index b07beb31ed..e204956056 100644
--- a/test/spec/server-discovery-and-monitoring/single/direct_connection_rsarbiter.json
+++ b/test/spec/server-discovery-and-monitoring/single/direct_connection_rsarbiter.json
@@ -8,7 +8,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": false,
+            "helloOk": true,
+            "isWritablePrimary": false,
             "arbiterOnly": true,
             "hosts": [
               "a:27017",
diff --git a/test/spec/server-discovery-and-monitoring/single/direct_connection_rsarbiter.yml b/test/spec/server-discovery-and-monitoring/single/direct_connection_rsarbiter.yml
index c531aab5e5..7e262c9dbe 100644
--- a/test/spec/server-discovery-and-monitoring/single/direct_connection_rsarbiter.yml
+++ b/test/spec/server-discovery-and-monitoring/single/direct_connection_rsarbiter.yml
@@ -10,7 +10,8 @@ phases: [
                 ["a:27017", {
 
                    ok: 1,
-                   ismaster: false,
+                   helloOk: true,
+                   isWritablePrimary: false,
                    arbiterOnly: true,
                    hosts: ["a:27017", "b:27017"],
                    setName: "rs",
diff --git a/test/spec/server-discovery-and-monitoring/single/direct_connection_rsprimary.json b/test/spec/server-discovery-and-monitoring/single/direct_connection_rsprimary.json
index 7216a13345..409e8502b3 100644
--- a/test/spec/server-discovery-and-monitoring/single/direct_connection_rsprimary.json
+++ b/test/spec/server-discovery-and-monitoring/single/direct_connection_rsprimary.json
@@ -8,7 +8,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017",
               "b:27017"
diff --git a/test/spec/server-discovery-and-monitoring/single/direct_connection_rsprimary.yml b/test/spec/server-discovery-and-monitoring/single/direct_connection_rsprimary.yml
index 0aea56e12b..4ea0b1551f 100644
--- a/test/spec/server-discovery-and-monitoring/single/direct_connection_rsprimary.yml
+++ b/test/spec/server-discovery-and-monitoring/single/direct_connection_rsprimary.yml
@@ -10,7 +10,8 @@ phases: [
                 ["a:27017", {
 
                    ok: 1,
-                   ismaster: true,
+                   helloOk: true,
+                   isWritablePrimary: true,
                    hosts: ["a:27017", "b:27017"],
                    setName: "rs",
                    minWireVersion: 0,
diff --git a/test/spec/server-discovery-and-monitoring/single/direct_connection_rssecondary.json b/test/spec/server-discovery-and-monitoring/single/direct_connection_rssecondary.json
index 573036f2aa..305f283b52 100644
--- a/test/spec/server-discovery-and-monitoring/single/direct_connection_rssecondary.json
+++ b/test/spec/server-discovery-and-monitoring/single/direct_connection_rssecondary.json
@@ -8,7 +8,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": false,
+            "helloOk": true,
+            "isWritablePrimary": false,
             "secondary": true,
             "hosts": [
               "a:27017",
diff --git a/test/spec/server-discovery-and-monitoring/single/direct_connection_rssecondary.yml b/test/spec/server-discovery-and-monitoring/single/direct_connection_rssecondary.yml
index 6cd3e5909a..b0c4d1f218 100644
--- a/test/spec/server-discovery-and-monitoring/single/direct_connection_rssecondary.yml
+++ b/test/spec/server-discovery-and-monitoring/single/direct_connection_rssecondary.yml
@@ -10,7 +10,8 @@ phases: [
                 ["a:27017", {
 
                     ok: 1,
-                    ismaster: false,
+                    helloOk: true,
+                    isWritablePrimary: false,
                     secondary: true,
                     hosts: ["a:27017", "b:27017"],
                     setName: "rs",
diff --git a/test/spec/server-discovery-and-monitoring/single/direct_connection_standalone.json b/test/spec/server-discovery-and-monitoring/single/direct_connection_standalone.json
index c53d76e76e..b47278482a 100644
--- a/test/spec/server-discovery-and-monitoring/single/direct_connection_standalone.json
+++ b/test/spec/server-discovery-and-monitoring/single/direct_connection_standalone.json
@@ -8,7 +8,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "minWireVersion": 0,
             "maxWireVersion": 6
           }
diff --git a/test/spec/server-discovery-and-monitoring/single/direct_connection_standalone.yml b/test/spec/server-discovery-and-monitoring/single/direct_connection_standalone.yml
index 7ad5f590b8..cd71087e4d 100644
--- a/test/spec/server-discovery-and-monitoring/single/direct_connection_standalone.yml
+++ b/test/spec/server-discovery-and-monitoring/single/direct_connection_standalone.yml
@@ -10,7 +10,8 @@ phases: [
                 ["a:27017", {
 
                     ok: 1,
-                    ismaster: true,
+                    helloOk: true,
+                    isWritablePrimary: true,
                     minWireVersion: 0,
                     maxWireVersion: 6
                 }]
diff --git a/test/spec/server-discovery-and-monitoring/single/direct_connection_wrong_set_name.json b/test/spec/server-discovery-and-monitoring/single/direct_connection_wrong_set_name.json
index de0b4b2aa7..71080e6810 100644
--- a/test/spec/server-discovery-and-monitoring/single/direct_connection_wrong_set_name.json
+++ b/test/spec/server-discovery-and-monitoring/single/direct_connection_wrong_set_name.json
@@ -8,7 +8,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017",
               "b:27017"
@@ -36,7 +37,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "hosts": [
               "a:27017",
               "b:27017"
diff --git a/test/spec/server-discovery-and-monitoring/single/direct_connection_wrong_set_name.yml b/test/spec/server-discovery-and-monitoring/single/direct_connection_wrong_set_name.yml
index 718b0229d1..f1e48dc419 100644
--- a/test/spec/server-discovery-and-monitoring/single/direct_connection_wrong_set_name.yml
+++ b/test/spec/server-discovery-and-monitoring/single/direct_connection_wrong_set_name.yml
@@ -4,7 +4,8 @@ phases:
 - responses:
   - - a:27017
     - ok: 1
-      ismaster: true
+      helloOk: true
+      isWritablePrimary: true
       hosts:
       - a:27017
       - b:27017
@@ -21,7 +22,8 @@ phases:
 - responses:
   - - a:27017
     - ok: 1
-      ismaster: true
+      helloOk: true
+      isWritablePrimary: true
       hosts:
       - a:27017
       - b:27017
diff --git a/test/spec/server-discovery-and-monitoring/single/discover_standalone.json b/test/spec/server-discovery-and-monitoring/single/discover_standalone.json
index eb6c6ae746..858cbdaf63 100644
--- a/test/spec/server-discovery-and-monitoring/single/discover_standalone.json
+++ b/test/spec/server-discovery-and-monitoring/single/discover_standalone.json
@@ -8,7 +8,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "minWireVersion": 0,
             "maxWireVersion": 6
           }
diff --git a/test/spec/server-discovery-and-monitoring/single/discover_standalone.yml b/test/spec/server-discovery-and-monitoring/single/discover_standalone.yml
index 5071033b8e..49ebb14209 100644
--- a/test/spec/server-discovery-and-monitoring/single/discover_standalone.yml
+++ b/test/spec/server-discovery-and-monitoring/single/discover_standalone.yml
@@ -10,7 +10,8 @@ phases: [
                 ["a:27017", {
 
                     ok: 1,
-                    ismaster: true,
+                    helloOk: true,
+                    isWritablePrimary: true,
                     minWireVersion: 0,
                     maxWireVersion: 6
                 }]
diff --git a/test/spec/server-discovery-and-monitoring/single/ls_timeout_standalone.json b/test/spec/server-discovery-and-monitoring/single/ls_timeout_standalone.json
index ae6c8ba11b..87b3e4e8a1 100644
--- a/test/spec/server-discovery-and-monitoring/single/ls_timeout_standalone.json
+++ b/test/spec/server-discovery-and-monitoring/single/ls_timeout_standalone.json
@@ -8,7 +8,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "logicalSessionTimeoutMinutes": 7,
             "minWireVersion": 0,
             "maxWireVersion": 6
diff --git a/test/spec/server-discovery-and-monitoring/single/ls_timeout_standalone.yml b/test/spec/server-discovery-and-monitoring/single/ls_timeout_standalone.yml
index d0273db6cd..2926d95a9d 100644
--- a/test/spec/server-discovery-and-monitoring/single/ls_timeout_standalone.yml
+++ b/test/spec/server-discovery-and-monitoring/single/ls_timeout_standalone.yml
@@ -10,7 +10,8 @@ phases: [
                 ["a:27017", {
 
                     ok: 1,
-                    ismaster: true,
+                    helloOk: true,
+                    isWritablePrimary: true,
                     logicalSessionTimeoutMinutes: 7,
                     minWireVersion: 0,
                     maxWireVersion: 6
diff --git a/test/spec/server-discovery-and-monitoring/single/not_ok_response.json b/test/spec/server-discovery-and-monitoring/single/not_ok_response.json
index 06f71305dc..8e7c2a10e3 100644
--- a/test/spec/server-discovery-and-monitoring/single/not_ok_response.json
+++ b/test/spec/server-discovery-and-monitoring/single/not_ok_response.json
@@ -1,5 +1,5 @@
 {
-  "description": "Handle a not-ok ismaster response",
+  "description": "Handle a not-ok isWritablePrimary response",
   "uri": "mongodb://a",
   "phases": [
     {
@@ -8,7 +8,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "minWireVersion": 0,
             "maxWireVersion": 6
           }
@@ -17,7 +18,8 @@
           "a:27017",
           {
             "ok": 0,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "minWireVersion": 0,
             "maxWireVersion": 6
           }
diff --git a/test/spec/server-discovery-and-monitoring/single/not_ok_response.yml b/test/spec/server-discovery-and-monitoring/single/not_ok_response.yml
index 6d49cca9c2..64103a5902 100644
--- a/test/spec/server-discovery-and-monitoring/single/not_ok_response.yml
+++ b/test/spec/server-discovery-and-monitoring/single/not_ok_response.yml
@@ -1,4 +1,4 @@
-description: "Handle a not-ok ismaster response"
+description: "Handle a not-ok isWritablePrimary response"
 
 uri: "mongodb://a"
 
@@ -10,7 +10,8 @@ phases: [
                 ["a:27017", {
 
                     ok: 1,
-                    ismaster: true,
+                    helloOk: true,
+                    isWritablePrimary: true,
                     minWireVersion: 0,
                     maxWireVersion: 6
                 }],
@@ -18,7 +19,8 @@ phases: [
                 ["a:27017", {
 
                     ok: 0,
-                    ismaster: true,
+                    helloOk: true,
+                    isWritablePrimary: true,
                     minWireVersion: 0,
                     maxWireVersion: 6
                 }]
diff --git a/test/spec/server-discovery-and-monitoring/single/standalone_removed.json b/test/spec/server-discovery-and-monitoring/single/standalone_removed.json
index 4c363ffffb..57f8f861b1 100644
--- a/test/spec/server-discovery-and-monitoring/single/standalone_removed.json
+++ b/test/spec/server-discovery-and-monitoring/single/standalone_removed.json
@@ -8,7 +8,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "minWireVersion": 0,
             "maxWireVersion": 6
           }
diff --git a/test/spec/server-discovery-and-monitoring/single/standalone_removed.yml b/test/spec/server-discovery-and-monitoring/single/standalone_removed.yml
index ff8c64f533..59b44b162e 100644
--- a/test/spec/server-discovery-and-monitoring/single/standalone_removed.yml
+++ b/test/spec/server-discovery-and-monitoring/single/standalone_removed.yml
@@ -10,7 +10,8 @@ phases: [
                 ["a:27017", {
 
                     ok: 1,
-                    ismaster: true,
+                    helloOk: true,
+                    isWritablePrimary: true,
                     minWireVersion: 0,
                     maxWireVersion: 6
                 }]
diff --git a/test/spec/server-discovery-and-monitoring/single/direct_connection_slave.json b/test/spec/server-discovery-and-monitoring/single/standalone_using_legacy_hello.json
similarity index 79%
rename from test/spec/server-discovery-and-monitoring/single/direct_connection_slave.json
rename to test/spec/server-discovery-and-monitoring/single/standalone_using_legacy_hello.json
index 720ec3dd82..46660fa8de 100644
--- a/test/spec/server-discovery-and-monitoring/single/direct_connection_slave.json
+++ b/test/spec/server-discovery-and-monitoring/single/standalone_using_legacy_hello.json
@@ -1,6 +1,6 @@
 {
-  "description": "Direct connection to slave",
-  "uri": "mongodb://a/?directConnection=true",
+  "description": "Connect to standalone using legacy hello",
+  "uri": "mongodb://a",
   "phases": [
     {
       "responses": [
@@ -8,7 +8,7 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": false,
+            "ismaster": true,
             "minWireVersion": 0,
             "maxWireVersion": 6
           }
diff --git a/test/spec/server-discovery-and-monitoring/single/direct_connection_slave.yml b/test/spec/server-discovery-and-monitoring/single/standalone_using_legacy_hello.yml
similarity index 80%
rename from test/spec/server-discovery-and-monitoring/single/direct_connection_slave.yml
rename to test/spec/server-discovery-and-monitoring/single/standalone_using_legacy_hello.yml
index 7c2436db16..a18ecb70fc 100644
--- a/test/spec/server-discovery-and-monitoring/single/direct_connection_slave.yml
+++ b/test/spec/server-discovery-and-monitoring/single/standalone_using_legacy_hello.yml
@@ -1,6 +1,6 @@
-description: "Direct connection to slave"
+description: "Connect to standalone using legacy hello"
 
-uri: "mongodb://a/?directConnection=true"
+uri: "mongodb://a"
 
 phases: [
 
@@ -10,7 +10,7 @@ phases: [
                 ["a:27017", {
 
                     ok: 1,
-                    ismaster: false,
+                    ismaster: true,
                     minWireVersion: 0,
                     maxWireVersion: 6
                 }]
diff --git a/test/spec/server-discovery-and-monitoring/single/too_new.json b/test/spec/server-discovery-and-monitoring/single/too_new.json
index 38e4621d60..8dd57d3348 100644
--- a/test/spec/server-discovery-and-monitoring/single/too_new.json
+++ b/test/spec/server-discovery-and-monitoring/single/too_new.json
@@ -8,7 +8,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "minWireVersion": 999,
             "maxWireVersion": 1000
           }
diff --git a/test/spec/server-discovery-and-monitoring/single/too_new.yml b/test/spec/server-discovery-and-monitoring/single/too_new.yml
index 2c295c5406..b176660d96 100644
--- a/test/spec/server-discovery-and-monitoring/single/too_new.yml
+++ b/test/spec/server-discovery-and-monitoring/single/too_new.yml
@@ -5,7 +5,8 @@ phases: [
         responses: [
                 ["a:27017", {
                     ok: 1,
-                    ismaster: true,
+                    helloOk: true,
+                    isWritablePrimary: true,
                     minWireVersion: 999,
                     maxWireVersion: 1000
                 }]
diff --git a/test/spec/server-discovery-and-monitoring/single/too_old.json b/test/spec/server-discovery-and-monitoring/single/too_old.json
index fbf68262c0..8c027e01db 100644
--- a/test/spec/server-discovery-and-monitoring/single/too_old.json
+++ b/test/spec/server-discovery-and-monitoring/single/too_old.json
@@ -8,7 +8,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true
+            "helloOk": true,
+            "isWritablePrimary": true
           }
         ]
       ],
diff --git a/test/spec/server-discovery-and-monitoring/single/too_old.yml b/test/spec/server-discovery-and-monitoring/single/too_old.yml
index 0035f5b06d..05cc1dc8f1 100644
--- a/test/spec/server-discovery-and-monitoring/single/too_old.yml
+++ b/test/spec/server-discovery-and-monitoring/single/too_old.yml
@@ -5,7 +5,8 @@ phases: [
         responses: [
                 ["a:27017", {
                     ok: 1,
-                    ismaster: true
+                    helloOk: true,
+                    isWritablePrimary: true
                 }]
         ],
         outcome: {
diff --git a/test/spec/server-discovery-and-monitoring/single/too_old_then_upgraded.json b/test/spec/server-discovery-and-monitoring/single/too_old_then_upgraded.json
index 7da46856fb..58ae7d9de4 100644
--- a/test/spec/server-discovery-and-monitoring/single/too_old_then_upgraded.json
+++ b/test/spec/server-discovery-and-monitoring/single/too_old_then_upgraded.json
@@ -8,7 +8,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true
+            "helloOk": true,
+            "isWritablePrimary": true
           }
         ]
       ],
@@ -31,7 +32,8 @@
           "a:27017",
           {
             "ok": 1,
-            "ismaster": true,
+            "helloOk": true,
+            "isWritablePrimary": true,
             "minWireVersion": 0,
             "maxWireVersion": 6
           }
diff --git a/test/spec/server-discovery-and-monitoring/single/too_old_then_upgraded.yml b/test/spec/server-discovery-and-monitoring/single/too_old_then_upgraded.yml
index ddf8f8fc47..aed6bae6e0 100644
--- a/test/spec/server-discovery-and-monitoring/single/too_old_then_upgraded.yml
+++ b/test/spec/server-discovery-and-monitoring/single/too_old_then_upgraded.yml
@@ -5,7 +5,8 @@ phases: [
         responses: [
                 ["a:27017", {
                     ok: 1,
-                    ismaster: true
+                    helloOk: true,
+                    isWritablePrimary: true
                 }]
         ],
         outcome: {
@@ -25,7 +26,8 @@ phases: [
         responses: [
                 ["a:27017", {
                     ok: 1,
-                    ismaster: true,
+                    helloOk: true,
+                    isWritablePrimary: true,
                     minWireVersion: 0,
                     maxWireVersion: 6
                 }]

From 796b270e78fe8dcf0636944fa9194bc1c661c9e4 Mon Sep 17 00:00:00 2001
From: Neal Beeken <neal.beeken@mongodb.com>
Date: Wed, 8 Sep 2021 14:17:12 -0400
Subject: [PATCH 02/14] refactor(NODE-3424): add helloOk support for monitoring

---
 lib/cmap/connection_pool.js         |  5 ++-
 lib/core/connection/connect.js      |  6 +++
 lib/core/connection/connection.js   |  1 +
 lib/core/sdam/monitor.js            | 12 ++++-
 lib/core/sdam/server_description.js |  2 +-
 lib/topologies/native_topology.js   |  2 +
 test/tools/runner/index.js          | 18 --------
 test/unit/sdam/monitoring.test.js   | 70 +++++++++++++++++++++++++++++
 8 files changed, 93 insertions(+), 23 deletions(-)

diff --git a/lib/cmap/connection_pool.js b/lib/cmap/connection_pool.js
index e11148cfd5..7f513e6248 100644
--- a/lib/cmap/connection_pool.js
+++ b/lib/cmap/connection_pool.js
@@ -158,12 +158,13 @@ class ConnectionPool extends EventEmitter {
       waitQueueTimeoutMS:
         typeof options.waitQueueTimeoutMS === 'number' ? options.waitQueueTimeoutMS : 0,
       autoEncrypter: options.autoEncrypter,
-      metadata: options.metadata
+      metadata: options.metadata,
+      useUnifiedTopology: options.useUnifiedTopology
     });
 
     if (options.minSize > options.maxSize) {
       throw new TypeError(
-        'Connection pool minimum size must not be greater than maxiumum pool size'
+        'Connection pool minimum size must not be greater than maximum pool size'
       );
     }
 
diff --git a/lib/core/connection/connect.js b/lib/core/connection/connect.js
index 6db2ce990a..60987c879e 100644
--- a/lib/core/connection/connect.js
+++ b/lib/core/connection/connect.js
@@ -95,6 +95,8 @@ function performInitialHandshake(conn, options, _callback) {
       handshakeOptions.socketTimeout = options.connectTimeoutMS || options.connectionTimeout;
     }
 
+    handshakeDoc.helloOk = !!options.useUnifiedTopology;
+
     const start = new Date().getTime();
     conn.command('admin.$cmd', handshakeDoc, handshakeOptions, (err, result) => {
       if (err) {
@@ -113,6 +115,10 @@ function performInitialHandshake(conn, options, _callback) {
         response.ismaster = response.isWritablePrimary;
       }
 
+      if (options.useUnifiedTopology && response.helloOk) {
+        conn.helloOk = true;
+      }
+
       const supportedServerErr = checkSupportedServer(response, options);
       if (supportedServerErr) {
         callback(supportedServerErr);
diff --git a/lib/core/connection/connection.js b/lib/core/connection/connection.js
index 1070438cca..3bd36a7051 100644
--- a/lib/core/connection/connection.js
+++ b/lib/core/connection/connection.js
@@ -91,6 +91,7 @@ class Connection extends EventEmitter {
     this.bson = options.bson;
     this.tag = options.tag;
     this.maxBsonMessageSize = options.maxBsonMessageSize || DEFAULT_MAX_BSON_MESSAGE_SIZE;
+    this.helloOk = undefined;
 
     this.port = options.port || 27017;
     this.host = options.host || 'localhost';
diff --git a/lib/core/sdam/monitor.js b/lib/core/sdam/monitor.js
index e27b236e75..be20fb03e5 100644
--- a/lib/core/sdam/monitor.js
+++ b/lib/core/sdam/monitor.js
@@ -65,7 +65,8 @@ class Monitor extends EventEmitter {
       heartbeatFrequencyMS:
         typeof options.heartbeatFrequencyMS === 'number' ? options.heartbeatFrequencyMS : 10000,
       minHeartbeatFrequencyMS:
-        typeof options.minHeartbeatFrequencyMS === 'number' ? options.minHeartbeatFrequencyMS : 500
+        typeof options.minHeartbeatFrequencyMS === 'number' ? options.minHeartbeatFrequencyMS : 500,
+      useUnifiedTopology: options.useUnifiedTopology
     });
 
     // TODO: refactor this to pull it directly from the pool, requires new ConnectionPool integration
@@ -205,8 +206,15 @@ function checkServer(monitor, callback) {
     const topologyVersion = monitor[kServer].description.topologyVersion;
     const isAwaitable = topologyVersion != null;
     const serverApi = monitor[kConnection].serverApi;
+    const helloOk = monitor[kConnection].helloOk;
+
+    const cmd = {
+      [serverApi || helloOk ? 'hello' : 'ismaster']: true
+    };
+
+    // written this way omit helloOk from the command if its false-y (do not want -> helloOk: null)
+    if (helloOk) cmd.helloOk = helloOk;
 
-    const cmd = { [serverApi ? 'hello' : 'ismaster']: true };
     const options = { socketTimeout: connectTimeoutMS };
 
     if (isAwaitable) {
diff --git a/lib/core/sdam/server_description.js b/lib/core/sdam/server_description.js
index 3bb7d26917..79ef18171f 100644
--- a/lib/core/sdam/server_description.js
+++ b/lib/core/sdam/server_description.js
@@ -180,7 +180,7 @@ function parseServerType(ismaster) {
   if (ismaster.setName) {
     if (ismaster.hidden) {
       return ServerType.RSOther;
-    } else if (ismaster.ismaster) {
+    } else if (ismaster.ismaster || ismaster.isWritablePrimary) {
       return ServerType.RSPrimary;
     } else if (ismaster.secondary) {
       return ServerType.RSSecondary;
diff --git a/lib/topologies/native_topology.js b/lib/topologies/native_topology.js
index 227cad3f1c..6ccfff57e7 100644
--- a/lib/topologies/native_topology.js
+++ b/lib/topologies/native_topology.js
@@ -46,6 +46,8 @@ class NativeTopology extends Topology {
 
     clonedOptions.serverApi = options.serverApi;
 
+    clonedOptions.useUnifiedTopology = options.useUnifiedTopology;
+
     super(servers, clonedOptions);
   }
 
diff --git a/test/tools/runner/index.js b/test/tools/runner/index.js
index 5b1fce00bf..7ba5948852 100644
--- a/test/tools/runner/index.js
+++ b/test/tools/runner/index.js
@@ -11,7 +11,6 @@ const TestConfiguration = require('./config');
 const parseConnectionString = require('../../../lib/core/uri_parser');
 const eachAsync = require('../../../lib/core/utils').eachAsync;
 const mock = require('mongodb-mock-server');
-const wtfnode = require('wtfnode');
 
 const MONGODB_URI = process.env.MONGODB_URI || 'mongodb://localhost:27017';
 const MONGODB_API_VERSION = process.env.MONGODB_API_VERSION;
@@ -121,20 +120,3 @@ require('mocha-sinon');
 const chai = require('chai');
 chai.use(require('sinon-chai'));
 chai.use(require('../../functional/spec-runner/matcher').default);
-
-// install signal handlers for printing open/active handles
-function dumpAndExit() {
-  // let other potential handlers run before exiting
-  process.nextTick(function() {
-    try {
-      wtfnode.dump();
-    } catch (e) {
-      console.log(e);
-    }
-
-    process.exit();
-  });
-}
-
-process.on('SIGINT', dumpAndExit);
-process.on('SIGTERM', dumpAndExit);
diff --git a/test/unit/sdam/monitoring.test.js b/test/unit/sdam/monitoring.test.js
index 472c1a72a1..f8ca377e06 100644
--- a/test/unit/sdam/monitoring.test.js
+++ b/test/unit/sdam/monitoring.test.js
@@ -218,4 +218,74 @@ describe('monitoring', function() {
       monitor.connect();
     });
   });
+
+  it('should upgrade to hello from legacy hello when initial handshake contains helloOk', {
+    metadata: { requires: { unifiedTopology: true } },
+    test(done) {
+      const docs = [];
+      mockServer.setMessageHandler(request => {
+        const doc = request.document;
+        docs.push(doc);
+        if (docs.length === 2) {
+          expect(docs[0]).to.have.property('ismaster', true);
+          expect(docs[0]).to.have.property('helloOk', true);
+          expect(docs[1]).to.have.property('hello', true);
+          done();
+        } else if (doc.ismaster || doc.hello) {
+          request.reply(Object.assign({ helloOk: true }, mock.DEFAULT_ISMASTER));
+        }
+      });
+
+      const server = new MockServer(mockServer.address());
+      const monitor = new Monitor(server, { useUnifiedTopology: true });
+      this.defer(() => monitor.close());
+      monitor.connect();
+      monitor.once('serverHeartbeatSucceeded', () => {
+        const minHeartbeatFrequencyMS = 500;
+        setTimeout(() => {
+          // wait for minHeartbeatFrequencyMS, then request a check and verify another check occurred
+          monitor.once('serverHeartbeatSucceeded', () => {
+            monitor.close();
+          });
+
+          monitor.requestCheck();
+        }, minHeartbeatFrequencyMS);
+      });
+    }
+  });
+
+  it('should not upgrade to hello when using the legacy topology', {
+    metadata: { requires: { unifiedTopology: false } },
+    test(done) {
+      const docs = [];
+      mockServer.setMessageHandler(request => {
+        const doc = request.document;
+        docs.push(doc);
+        if (docs.length === 2) {
+          expect(docs[0]).to.have.property('ismaster', true);
+          expect(docs[0]).to.not.have.property('helloOk');
+          expect(docs[1]).to.not.have.property('hello');
+          done();
+        } else if (doc.ismaster || doc.hello) {
+          request.reply(Object.assign({ helloOk: true }, mock.DEFAULT_ISMASTER));
+        }
+      });
+
+      const server = new MockServer(mockServer.address());
+      const monitor = new Monitor(server, { useUnifiedTopology: false });
+      this.defer(() => monitor.close());
+      monitor.connect();
+      monitor.once('serverHeartbeatSucceeded', () => {
+        const minHeartbeatFrequencyMS = 500;
+        setTimeout(() => {
+          // wait for minHeartbeatFrequencyMS, then request a check and verify another check occurred
+          monitor.once('serverHeartbeatSucceeded', () => {
+            monitor.close();
+          });
+
+          monitor.requestCheck();
+        }, minHeartbeatFrequencyMS);
+      });
+    }
+  });
 });

From c1ccbe6879e05189898ba9c27bef5304440b26b5 Mon Sep 17 00:00:00 2001
From: Neal Beeken <neal.beeken@mongodb.com>
Date: Wed, 8 Sep 2021 15:07:18 -0400
Subject: [PATCH 03/14] fix: SDAM marked topology Unknown when it should only
 remove server

---
 .evergreen/install-dependencies.sh                  | 2 +-
 lib/core/topologies/replset_state.js                | 6 ++++--
 test/tools/runner/filters/mongodb_version_filter.js | 3 +++
 3 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/.evergreen/install-dependencies.sh b/.evergreen/install-dependencies.sh
index 186dabffb3..5e046fce48 100644
--- a/.evergreen/install-dependencies.sh
+++ b/.evergreen/install-dependencies.sh
@@ -3,7 +3,7 @@
 set -o errexit  # Exit the script with error if any of the commands fail
 
 NVM_WINDOWS_URL="https://github.com/coreybutler/nvm-windows/releases/download/1.1.7/nvm-noinstall.zip"
-NVM_URL="https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh"
+NVM_URL="https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh"
 
 NODE_LTS_NAME=${NODE_LTS_NAME:-carbon}
 MSVS_VERSION=${MSVS_VERSION:-2017}
diff --git a/lib/core/topologies/replset_state.js b/lib/core/topologies/replset_state.js
index 24c16d6d71..81cb7f1fd0 100644
--- a/lib/core/topologies/replset_state.js
+++ b/lib/core/topologies/replset_state.js
@@ -218,7 +218,8 @@ const isArbiter = ismaster => ismaster.arbiterOnly && ismaster.setName;
 ReplSetState.prototype.update = function(server) {
   var self = this;
   // Get the current ismaster
-  var ismaster = server.lastIsMaster();
+  const ismaster = server.lastIsMaster();
+  if (ismaster && ismaster.isWritablePrimary) ismaster.ismaster = ismaster.isWritablePrimary;
 
   // Get the server name and lowerCase it
   var serverName = server.name.toLowerCase();
@@ -358,7 +359,8 @@ ReplSetState.prototype.update = function(server) {
   // Standalone server, destroy and return
   //
   if (ismaster && ismaster.ismaster && !ismaster.setName) {
-    this.topologyType = this.primary ? TopologyType.ReplicaSetWithPrimary : TopologyType.Unknown;
+    // We should not mark the topology as Unknown because of one standalone
+    // we should just remove this server from the set
     this.remove(server, { force: true });
     return false;
   }
diff --git a/test/tools/runner/filters/mongodb_version_filter.js b/test/tools/runner/filters/mongodb_version_filter.js
index be5447dcc5..f855ad0c0a 100755
--- a/test/tools/runner/filters/mongodb_version_filter.js
+++ b/test/tools/runner/filters/mongodb_version_filter.js
@@ -39,6 +39,9 @@ class MongoDBVersionFilter {
   }
 
   filter(test) {
+    if (!process.env.MONGODB_UNIFIED_TOPOLOGY && semver.satisfies(this.version, '>=5.0')) {
+      return false; // do not run any tests on 5.0 if unified topology isn't enabled.
+    }
     if (this.options.skip) return true;
     if (!test.metadata) return true;
     if (!test.metadata.requires) return true;

From 0c6126fc55910042aeae8ee181ff3f57f39ee7a1 Mon Sep 17 00:00:00 2001
From: Neal Beeken <neal.beeken@mongodb.com>
Date: Wed, 8 Sep 2021 16:45:01 -0400
Subject: [PATCH 04/14] fix: SDAM should look for setName to default
 topologyType

---
 lib/core/topologies/replset_state.js | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/core/topologies/replset_state.js b/lib/core/topologies/replset_state.js
index 81cb7f1fd0..7edb7915ca 100644
--- a/lib/core/topologies/replset_state.js
+++ b/lib/core/topologies/replset_state.js
@@ -34,7 +34,7 @@ var ReplSetState = function(options) {
   // Add event listener
   EventEmitter.call(this);
   // Topology state
-  this.topologyType = TopologyType.ReplicaSetNoPrimary;
+  this.topologyType = options.setName ? TopologyType.ReplicaSetNoPrimary : TopologyType.Unknown;
   this.setName = options.setName;
 
   // Server set

From 329722b0e60f69439c1a1b8b4d75da0edab1ca54 Mon Sep 17 00:00:00 2001
From: Neal Beeken <neal.beeken@mongodb.com>
Date: Thu, 9 Sep 2021 13:46:46 -0400
Subject: [PATCH 05/14] fix(NODE-3071): Ignore error message if error code is
 defined

---
 lib/core/error.js                          | 85 ++++++++++++----------
 lib/core/topologies/shared.js              |  5 +-
 lib/core/uri_parser.js                     | 17 +++++
 lib/error.js                               | 41 ++++++-----
 lib/error_codes.js                         | 36 +++++++++
 lib/gridfs-stream/upload.js                | 17 ++---
 lib/operations/db_ops.js                   | 17 +++--
 lib/operations/estimated_document_count.js |  3 +-
 lib/url_parser.js                          | 12 +++
 test/functional/core/replset_state.test.js |  1 +
 test/unit/sdam/spec.test.js                | 11 ++-
 11 files changed, 166 insertions(+), 79 deletions(-)
 create mode 100644 lib/error_codes.js

diff --git a/lib/core/error.js b/lib/core/error.js
index 702e3cecde..8272b11a30 100644
--- a/lib/core/error.js
+++ b/lib/core/error.js
@@ -1,5 +1,7 @@
 'use strict';
 
+const MONGODB_ERROR_CODES = require('../error_codes').MONGODB_ERROR_CODES;
+
 const kErrorLabels = Symbol('errorLabels');
 
 /**
@@ -216,32 +218,32 @@ class MongoWriteConcernError extends MongoError {
 
 // see: https://github.com/mongodb/specifications/blob/master/source/retryable-writes/retryable-writes.rst#terms
 const RETRYABLE_ERROR_CODES = new Set([
-  6, // HostUnreachable
-  7, // HostNotFound
-  89, // NetworkTimeout
-  91, // ShutdownInProgress
-  189, // PrimarySteppedDown
-  9001, // SocketException
-  10107, // NotMaster
-  11600, // InterruptedAtShutdown
-  11602, // InterruptedDueToReplStateChange
-  13435, // NotMasterNoSlaveOk
-  13436 // NotMasterOrSecondary
+  MONGODB_ERROR_CODES.HostUnreachable,
+  MONGODB_ERROR_CODES.HostNotFound,
+  MONGODB_ERROR_CODES.NetworkTimeout,
+  MONGODB_ERROR_CODES.ShutdownInProgress,
+  MONGODB_ERROR_CODES.PrimarySteppedDown,
+  MONGODB_ERROR_CODES.SocketException,
+  MONGODB_ERROR_CODES.NotMaster,
+  MONGODB_ERROR_CODES.InterruptedAtShutdown,
+  MONGODB_ERROR_CODES.InterruptedDueToReplStateChange,
+  MONGODB_ERROR_CODES.NotMasterNoSlaveOk,
+  MONGODB_ERROR_CODES.NotMasterOrSecondary
 ]);
 
 const RETRYABLE_WRITE_ERROR_CODES = new Set([
-  11600, // InterruptedAtShutdown
-  11602, // InterruptedDueToReplStateChange
-  10107, // NotMaster
-  13435, // NotMasterNoSlaveOk
-  13436, // NotMasterOrSecondary
-  189, // PrimarySteppedDown
-  91, // ShutdownInProgress
-  7, // HostNotFound
-  6, // HostUnreachable
-  89, // NetworkTimeout
-  9001, // SocketException
-  262 // ExceededTimeLimit
+  MONGODB_ERROR_CODES.InterruptedAtShutdown,
+  MONGODB_ERROR_CODES.InterruptedDueToReplStateChange,
+  MONGODB_ERROR_CODES.NotMaster,
+  MONGODB_ERROR_CODES.NotMasterNoSlaveOk,
+  MONGODB_ERROR_CODES.NotMasterOrSecondary,
+  MONGODB_ERROR_CODES.PrimarySteppedDown,
+  MONGODB_ERROR_CODES.ShutdownInProgress,
+  MONGODB_ERROR_CODES.HostNotFound,
+  MONGODB_ERROR_CODES.HostUnreachable,
+  MONGODB_ERROR_CODES.NetworkTimeout,
+  MONGODB_ERROR_CODES.SocketException,
+  MONGODB_ERROR_CODES.ExceededTimeLimit
 ]);
 
 function isRetryableWriteError(error) {
@@ -271,41 +273,44 @@ function isRetryableError(error) {
 }
 
 const SDAM_RECOVERING_CODES = new Set([
-  91, // ShutdownInProgress
-  189, // PrimarySteppedDown
-  11600, // InterruptedAtShutdown
-  11602, // InterruptedDueToReplStateChange
-  13436 // NotMasterOrSecondary
+  MONGODB_ERROR_CODES.ShutdownInProgress,
+  MONGODB_ERROR_CODES.PrimarySteppedDown,
+  MONGODB_ERROR_CODES.InterruptedAtShutdown,
+  MONGODB_ERROR_CODES.InterruptedDueToReplStateChange,
+  MONGODB_ERROR_CODES.NotMasterOrSecondary
 ]);
 
 const SDAM_NOTMASTER_CODES = new Set([
-  10107, // NotMaster
-  13435 // NotMasterNoSlaveOk
+  MONGODB_ERROR_CODES.NotMaster,
+  MONGODB_ERROR_CODES.NotMasterNoSlaveOk,
+  MONGODB_ERROR_CODES.LegacyNotPrimary
 ]);
 
 const SDAM_NODE_SHUTTING_DOWN_ERROR_CODES = new Set([
-  11600, // InterruptedAtShutdown
-  91 // ShutdownInProgress
+  MONGODB_ERROR_CODES.InterruptedAtShutdown,
+  MONGODB_ERROR_CODES.ShutdownInProgress
 ]);
 
 function isRecoveringError(err) {
-  if (err.code && SDAM_RECOVERING_CODES.has(err.code)) {
-    return true;
+  if (typeof err.code !== 'undefined') {
+    // If any error code exists, we ignore the error.message
+    return SDAM_RECOVERING_CODES.has(err.code);
   }
 
-  return err.message.match(/not master or secondary/) || err.message.match(/node is recovering/);
+  return /not master or secondary/.test(err.message) || /node is recovering/.test(err.message);
 }
 
 function isNotMasterError(err) {
-  if (err.code && SDAM_NOTMASTER_CODES.has(err.code)) {
-    return true;
+  if (typeof err.code !== 'undefined') {
+    // If any error code exists, we ignore the error.message
+    return SDAM_NOTMASTER_CODES.has(err.code);
   }
 
   if (isRecoveringError(err)) {
     return false;
   }
 
-  return err.message.match(/not master/);
+  return /not master/.test(err.message);
 }
 
 function isNodeShuttingDownError(err) {
@@ -328,6 +333,10 @@ function isSDAMUnrecoverableError(error) {
     return true;
   }
 
+  if (typeof error.code !== 'undefined') {
+    return isRecoveringError(error) || isNotMasterError(error);
+  }
+
   if (isRecoveringError(error) || isNotMasterError(error)) {
     return true;
   }
diff --git a/lib/core/topologies/shared.js b/lib/core/topologies/shared.js
index 1ec55919bb..dff35a5127 100644
--- a/lib/core/topologies/shared.js
+++ b/lib/core/topologies/shared.js
@@ -1,11 +1,14 @@
 'use strict';
+
+const MONGODB_ERROR_CODES = require('../../error_codes').MONGODB_ERROR_CODES;
 const ReadPreference = require('./read_preference');
 const TopologyType = require('../sdam/common').TopologyType;
 const MongoError = require('../error').MongoError;
 const isRetryableWriteError = require('../error').isRetryableWriteError;
 const maxWireVersion = require('../utils').maxWireVersion;
 const MongoNetworkError = require('../error').MongoNetworkError;
-const MMAPv1_RETRY_WRITES_ERROR_CODE = 20;
+
+const MMAPv1_RETRY_WRITES_ERROR_CODE = MONGODB_ERROR_CODES.IllegalOperation;
 
 /**
  * Emit event if it exists
diff --git a/lib/core/uri_parser.js b/lib/core/uri_parser.js
index 1d3980858b..b867b80e68 100644
--- a/lib/core/uri_parser.js
+++ b/lib/core/uri_parser.js
@@ -106,6 +106,15 @@ function parseSrvConnectionString(uri, options, callback) {
         }
 
         record = qs.parse(record[0].join(''));
+
+        if (
+          Object.keys(record)
+            .map(k => k.toLowerCase())
+            .indexOf('loadbalanced') !== -1
+        ) {
+          return callback(new MongoParseError('Load balancer mode requires driver version 4+'));
+        }
+
         if (Object.keys(record).some(key => key !== 'authSource' && key !== 'replicaSet')) {
           return callback(
             new MongoParseError('Text record must only set `authSource` or `replicaSet`')
@@ -598,6 +607,14 @@ function parseConnectionString(uri, options, callback) {
 
   parsedOptions = Object.assign({}, parsedOptions, options);
 
+  if (
+    Object.keys(parsedOptions)
+      .map(k => k.toLowerCase())
+      .indexOf('loadbalanced') !== -1
+  ) {
+    return callback(new MongoParseError('Load balancer mode requires driver version 4+'));
+  }
+
   if (protocol === PROTOCOL_MONGODB_SRV) {
     return parseSrvConnectionString(uri, parsedOptions, callback);
   }
diff --git a/lib/error.js b/lib/error.js
index b2d026ce90..31b4ffd670 100644
--- a/lib/error.js
+++ b/lib/error.js
@@ -1,27 +1,28 @@
 'use strict';
 
 const MongoNetworkError = require('./core').MongoNetworkError;
+const MONGODB_ERROR_CODES = require('./error_codes').MONGODB_ERROR_CODES;
 
 // From spec@https://github.com/mongodb/specifications/blob/f93d78191f3db2898a59013a7ed5650352ef6da8/source/change-streams/change-streams.rst#resumable-error
 const GET_MORE_RESUMABLE_CODES = new Set([
-  6, // HostUnreachable
-  7, // HostNotFound
-  89, // NetworkTimeout
-  91, // ShutdownInProgress
-  189, // PrimarySteppedDown
-  262, // ExceededTimeLimit
-  9001, // SocketException
-  10107, // NotMaster
-  11600, // InterruptedAtShutdown
-  11602, // InterruptedDueToReplStateChange
-  13435, // NotMasterNoSlaveOk
-  13436, // NotMasterOrSecondary
-  63, // StaleShardVersion
-  150, // StaleEpoch
-  13388, // StaleConfig
-  234, // RetryChangeStream
-  133, // FailedToSatisfyReadPreference
-  43 // CursorNotFound
+  MONGODB_ERROR_CODES.HostUnreachable,
+  MONGODB_ERROR_CODES.HostNotFound,
+  MONGODB_ERROR_CODES.NetworkTimeout,
+  MONGODB_ERROR_CODES.ShutdownInProgress,
+  MONGODB_ERROR_CODES.PrimarySteppedDown,
+  MONGODB_ERROR_CODES.ExceededTimeLimit,
+  MONGODB_ERROR_CODES.SocketException,
+  MONGODB_ERROR_CODES.NotMaster,
+  MONGODB_ERROR_CODES.InterruptedAtShutdown,
+  MONGODB_ERROR_CODES.InterruptedDueToReplStateChange,
+  MONGODB_ERROR_CODES.NotMasterNoSlaveOk,
+  MONGODB_ERROR_CODES.NotMasterOrSecondary,
+  MONGODB_ERROR_CODES.StaleShardVersion,
+  MONGODB_ERROR_CODES.StaleEpoch,
+  MONGODB_ERROR_CODES.StaleConfig,
+  MONGODB_ERROR_CODES.RetryChangeStream,
+  MONGODB_ERROR_CODES.FailedToSatisfyReadPreference,
+  MONGODB_ERROR_CODES.CursorNotFound
 ]);
 
 function isResumableError(error, wireVersion) {
@@ -31,7 +32,7 @@ function isResumableError(error, wireVersion) {
 
   if (wireVersion >= 9) {
     // DRIVERS-1308: For 4.4 drivers running against 4.4 servers, drivers will add a special case to treat the CursorNotFound error code as resumable
-    if (error.code === 43) {
+    if (error.code === MONGODB_ERROR_CODES.CursorNotFound) {
       return true;
     }
     return error.hasErrorLabel('ResumableChangeStreamError');
@@ -40,4 +41,4 @@ function isResumableError(error, wireVersion) {
   return GET_MORE_RESUMABLE_CODES.has(error.code);
 }
 
-module.exports = { GET_MORE_RESUMABLE_CODES, isResumableError };
+module.exports = { GET_MORE_RESUMABLE_CODES, isResumableError, MONGODB_ERROR_CODES };
diff --git a/lib/error_codes.js b/lib/error_codes.js
new file mode 100644
index 0000000000..7f80000bdc
--- /dev/null
+++ b/lib/error_codes.js
@@ -0,0 +1,36 @@
+'use strict';
+
+const MONGODB_ERROR_CODES = Object.freeze({
+  HostUnreachable: 6,
+  HostNotFound: 7,
+  NetworkTimeout: 89,
+  ShutdownInProgress: 91,
+  PrimarySteppedDown: 189,
+  ExceededTimeLimit: 262,
+  SocketException: 9001,
+  NotMaster: 10107,
+  InterruptedAtShutdown: 11600,
+  InterruptedDueToReplStateChange: 11602,
+  NotMasterNoSlaveOk: 13435,
+  NotMasterOrSecondary: 13436,
+  StaleShardVersion: 63,
+  StaleEpoch: 150,
+  StaleConfig: 13388,
+  RetryChangeStream: 234,
+  FailedToSatisfyReadPreference: 133,
+  CursorNotFound: 43,
+  LegacyNotPrimary: 10058,
+  WriteConcernFailed: 64,
+  NamespaceNotFound: 26,
+  IllegalOperation: 20,
+  MaxTimeMSExpired: 50,
+  UnknownReplWriteConcern: 79,
+  UnsatisfiableWriteConcern: 100,
+  DuplicateKey: 11000,
+  CannotCreateIndex: 67,
+  IndexOptionsConflict: 85,
+  IndexKeySpecsConflict: 86,
+  InvalidIndexSpecificationOption: 197
+});
+
+module.exports = Object.freeze({ MONGODB_ERROR_CODES });
diff --git a/lib/gridfs-stream/upload.js b/lib/gridfs-stream/upload.js
index e0bf48cf9a..d988fdc197 100644
--- a/lib/gridfs-stream/upload.js
+++ b/lib/gridfs-stream/upload.js
@@ -1,14 +1,13 @@
 'use strict';
 
-var core = require('../core');
-var crypto = require('crypto');
-var stream = require('stream');
-var util = require('util');
-var Buffer = require('safe-buffer').Buffer;
+const MONGODB_ERROR_CODES = require('../error_codes').MONGODB_ERROR_CODES;
+const core = require('../core');
+const crypto = require('crypto');
+const stream = require('stream');
+const util = require('util');
+const Buffer = require('safe-buffer').Buffer;
 const deprecateOptions = require('../utils').deprecateOptions;
 
-const ERROR_NAMESPACE_NOT_FOUND = 26;
-
 /**
  * A writable stream that enables you to write buffers to GridFS.
  *
@@ -216,7 +215,7 @@ function checkChunksIndex(_this, callback) {
   _this.chunks.listIndexes().toArray(function(error, indexes) {
     if (error) {
       // Collection doesn't exist so create index
-      if (error.code === ERROR_NAMESPACE_NOT_FOUND) {
+      if (error.code === MONGODB_ERROR_CODES.NamespaceNotFound) {
         var index = { files_id: 1, n: 1 };
         _this.chunks.createIndex(index, { background: false, unique: true }, function(error) {
           if (error) {
@@ -315,7 +314,7 @@ function checkIndexes(_this, callback) {
     _this.files.listIndexes().toArray(function(error, indexes) {
       if (error) {
         // Collection doesn't exist so create index
-        if (error.code === ERROR_NAMESPACE_NOT_FOUND) {
+        if (error.code === MONGODB_ERROR_CODES.NamespaceNotFound) {
           var index = { filename: 1, uploadDate: 1 };
           _this.files.createIndex(index, { background: false }, function(error) {
             if (error) {
diff --git a/lib/operations/db_ops.js b/lib/operations/db_ops.js
index 785af776a0..78f1e4f143 100644
--- a/lib/operations/db_ops.js
+++ b/lib/operations/db_ops.js
@@ -1,5 +1,6 @@
 'use strict';
 
+const MONGODB_ERROR_CODES = require('../error_codes').MONGODB_ERROR_CODES;
 const applyWriteConcern = require('../utils').applyWriteConcern;
 const Code = require('../core').BSON.Code;
 const debugOptions = require('../utils').debugOptions;
@@ -75,12 +76,12 @@ function createIndex(db, name, fieldOrSpec, options, callback) {
      * 197 = 'InvalidIndexSpecificationOption' (`_id` with `background: true`)
      */
     if (
-      err.code === 67 ||
-      err.code === 11000 ||
-      err.code === 85 ||
-      err.code === 86 ||
-      err.code === 11600 ||
-      err.code === 197
+      err.code === MONGODB_ERROR_CODES.CannotCreateIndex ||
+      err.code === MONGODB_ERROR_CODES.DuplicateKey ||
+      err.code === MONGODB_ERROR_CODES.IndexOptionsConflict ||
+      err.code === MONGODB_ERROR_CODES.IndexKeySpecsConflict ||
+      err.code === MONGODB_ERROR_CODES.InterruptedAtShutdown ||
+      err.code === MONGODB_ERROR_CODES.InvalidIndexSpecificationOption
     ) {
       return handleCallback(callback, err, result);
     }
@@ -147,7 +148,9 @@ function ensureIndex(db, name, fieldOrSpec, options, callback) {
 
   // Check if the index already exists
   indexInformation(db, name, finalOptions, (err, indexInformation) => {
-    if (err != null && err.code !== 26) return handleCallback(callback, err, null);
+    if (err != null && err.code !== MONGODB_ERROR_CODES.NamespaceNotFound) {
+      return handleCallback(callback, err, null);
+    }
     // If the index does not exist, create it
     if (indexInformation == null || !indexInformation[index_name]) {
       createIndex(db, name, fieldOrSpec, options, callback);
diff --git a/lib/operations/estimated_document_count.js b/lib/operations/estimated_document_count.js
index ca102275b7..1def94d2a5 100644
--- a/lib/operations/estimated_document_count.js
+++ b/lib/operations/estimated_document_count.js
@@ -1,5 +1,6 @@
 'use strict';
 
+const MONGODB_ERROR_CODES = require('../error_codes').MONGODB_ERROR_CODES;
 const Aspect = require('./operation').Aspect;
 const defineAspects = require('./operation').defineAspects;
 const CommandOperationV2 = require('./command_v2');
@@ -30,7 +31,7 @@ class EstimatedDocumentCountOperation extends CommandOperationV2 {
     }
 
     super.executeCommand(server, cmd, (err, response) => {
-      if (err && err.code !== 26) {
+      if (err && err.code !== MONGODB_ERROR_CODES.NamespaceNotFound) {
         callback(err);
         return;
       }
diff --git a/lib/url_parser.js b/lib/url_parser.js
index eb7ec7a7d2..d9aaca33e0 100644
--- a/lib/url_parser.js
+++ b/lib/url_parser.js
@@ -101,6 +101,13 @@ module.exports = function(url, options, callback) {
         record = record[0].join('');
         const parsedRecord = qs.parse(record);
         const items = Object.keys(parsedRecord);
+        if (
+          Object.keys(items)
+            .map(k => k.toLowerCase())
+            .indexOf('loadbalanced') !== -1
+        ) {
+          return callback(new MongoParseError('Load balancer mode requires driver version 4+'));
+        }
         if (items.some(item => item !== 'authSource' && item !== 'replicaSet')) {
           return callback(
             new MongoParseError('Text record must only set `authSource` or `replicaSet`')
@@ -378,6 +385,11 @@ function parseConnectionString(url, options) {
   object.dbName = dbName || 'admin';
   // Split up all the options
   urlOptions = (query_string_part || '').split(/[&;]/);
+
+  if (urlOptions.map(k => k.toLowerCase()).indexOf('loadbalanced') !== -1) {
+    throw new MongoParseError('Load balancer mode requires driver version 4+');
+  }
+
   // Ugh, we have to figure out which options go to which constructor manually.
   urlOptions.forEach(function(opt) {
     if (!opt) return;
diff --git a/test/functional/core/replset_state.test.js b/test/functional/core/replset_state.test.js
index b295c3f244..b2a6784058 100644
--- a/test/functional/core/replset_state.test.js
+++ b/test/functional/core/replset_state.test.js
@@ -102,6 +102,7 @@ function executePhase(phase, state, callback) {
       });
     } else {
       var ismaster = x[1];
+      if (ismaster && ismaster.isWritablePrimary) ismaster.ismaster = ismaster.isWritablePrimary;
       if (ismaster.electionId) ismaster.electionId = new ObjectId(ismaster.electionId.$oid);
 
       state.update({
diff --git a/test/unit/sdam/spec.test.js b/test/unit/sdam/spec.test.js
index a0c020cd80..e02ee0ced6 100644
--- a/test/unit/sdam/spec.test.js
+++ b/test/unit/sdam/spec.test.js
@@ -164,7 +164,12 @@ function cloneForCompare(event) {
 
 function executeSDAMTest(testData, testDone) {
   parse(testData.uri, (err, parsedUri) => {
-    if (err) return done(err);
+    if (err) {
+      if (err.message.toLowerCase().indexOf('load balancer') !== -1) {
+        return testDone();
+      }
+      return testDone(err);
+    }
 
     // create the topology
     const topology = new Topology(parsedUri.hosts, parsedUri.options);
@@ -196,9 +201,9 @@ function executeSDAMTest(testData, testDone) {
       topology.on(eventName, event => events.push(event));
     });
 
-    function done(err) {
+    const done = function(err) {
       topology.close(e => testDone(e || err));
-    }
+    };
 
     const incompatibilityHandler = err => {
       if (err.message.match(/but this version of the driver/)) return;

From 76df5bdfadce08201fcdf10c56b6219d786cf31f Mon Sep 17 00:00:00 2001
From: Neal Beeken <neal.beeken@mongodb.com>
Date: Thu, 9 Sep 2021 16:13:46 -0400
Subject: [PATCH 06/14] fix: skip new spec tests that have not been implemented

---
 lib/core/connection/connect.js               | 13 ++++--
 test/functional/mongo_client_options.test.js | 42 +++++---------------
 test/functional/sdam.test.js                 | 29 +++++++++++++-
 3 files changed, 46 insertions(+), 38 deletions(-)

diff --git a/lib/core/connection/connect.js b/lib/core/connection/connect.js
index 60987c879e..b3f487d61d 100644
--- a/lib/core/connection/connect.js
+++ b/lib/core/connection/connect.js
@@ -278,12 +278,17 @@ function makeConnection(family, options, cancellationToken, _callback) {
       : typeof options.connectTimeoutMS === 'number'
       ? options.connectTimeoutMS
       : 30000;
-  const socketTimeout = typeof options.socketTimeout === 'number' ? options.socketTimeout : 0;
+  const socketTimeoutMS =
+    typeof options.socketTimeoutMS === 'number'
+      ? options.socketTimeoutMS
+      : typeof options.socketTimeout === 'number'
+      ? options.socketTimeout
+      : 0;
   const rejectUnauthorized =
     typeof options.rejectUnauthorized === 'boolean' ? options.rejectUnauthorized : true;
 
-  if (keepAliveInitialDelay > socketTimeout) {
-    keepAliveInitialDelay = Math.round(socketTimeout / 2);
+  if (keepAliveInitialDelay > socketTimeoutMS) {
+    keepAliveInitialDelay = Math.round(socketTimeoutMS / 2);
   }
 
   let socket;
@@ -336,7 +341,7 @@ function makeConnection(family, options, cancellationToken, _callback) {
       return callback(socket.authorizationError);
     }
 
-    socket.setTimeout(socketTimeout);
+    socket.setTimeout(socketTimeoutMS);
     callback(null, socket);
   }
 
diff --git a/test/functional/mongo_client_options.test.js b/test/functional/mongo_client_options.test.js
index d905c8c606..fdb0b2a972 100644
--- a/test/functional/mongo_client_options.test.js
+++ b/test/functional/mongo_client_options.test.js
@@ -40,36 +40,6 @@ describe('MongoClient Options', function() {
     }
   });
 
-  /**
-   * @ignore
-   */
-  it('pass in server and db top level options', {
-    metadata: { requires: { topology: 'single' } },
-
-    // The actual test we wish to run
-    test: function(done) {
-      const configuration = this.configuration;
-      if (configuration.usingUnifiedTopology()) {
-        // skipped for direct legacy variable inspection
-        return this.skip();
-      }
-
-      const client = configuration.newClient(configuration.url(), {
-        autoReconnect: true,
-        poolSize: 4
-      });
-
-      client.connect(
-        connectionTester(configuration, 'testConnectServerOptions', function(client) {
-          test.ok(client.topology.poolSize >= 1);
-          test.equal(4, client.topology.s.coreTopology.s.pool.size);
-          test.equal(true, client.topology.autoReconnect);
-          client.close(done);
-        })
-      );
-    }
-  });
-
   /**
    * @ignore
    */
@@ -127,7 +97,11 @@ describe('MongoClient Options', function() {
           const ns = args[0];
           const command = args[1];
           const options = args[2];
-          if (ns === 'admin.$cmd' && command.ismaster && options.exhaustAllowed) {
+          if (
+            ns === 'admin.$cmd' &&
+            (command.hello || command.ismaster) &&
+            options.exhaustAllowed
+          ) {
             stub.restore();
             expect(options)
               .property('socketTimeout')
@@ -155,7 +129,11 @@ describe('MongoClient Options', function() {
           const ns = args[0];
           const command = args[1];
           const options = args[2];
-          if (ns === 'admin.$cmd' && command.ismaster && options.exhaustAllowed) {
+          if (
+            ns === 'admin.$cmd' &&
+            (command.hello || command.ismaster) &&
+            options.exhaustAllowed
+          ) {
             stub.restore();
             expect(options)
               .property('socketTimeout')
diff --git a/test/functional/sdam.test.js b/test/functional/sdam.test.js
index fde81b20d9..7ccf1da7bf 100644
--- a/test/functional/sdam.test.js
+++ b/test/functional/sdam.test.js
@@ -1,6 +1,8 @@
 'use strict';
 const TestRunnerContext = require('./spec-runner').TestRunnerContext;
-const loadSpecTests = require('../spec').loadSpecTests;
+const path = require('path');
+const fs = require('fs');
+const EJSON = require('mongodb-extjson');
 const generateTopologyTests = require('./spec-runner').generateTopologyTests;
 
 class SDAMRunnerContext extends TestRunnerContext {
@@ -39,10 +41,33 @@ class SDAMRunnerContext extends TestRunnerContext {
   }
 }
 
+// TODO -- NODE-2994
+const SKIP_SDAM_INTEGRATION_FILES = [
+  'auth-error.json',
+  'auth-misc-command-error.json',
+  'auth-network-error.json',
+  'auth-network-timeout-error.json',
+  'auth-shutdown-error.json',
+  'find-network-timeout-error.json',
+  'pool-cleared-error.json',
+  'minPoolSize-error.json'
+];
+
 describe('SDAM', function() {
   context('integration spec tests', function() {
     const testContext = new SDAMRunnerContext();
-    const testSuites = loadSpecTests('server-discovery-and-monitoring/integration');
+    const specPath = path.resolve(__dirname, '../spec/server-discovery-and-monitoring/integration');
+
+    const testSuites = fs
+      .readdirSync(specPath)
+      .filter(x => x.indexOf('.json') !== -1)
+      .filter(fn => SKIP_SDAM_INTEGRATION_FILES.indexOf(fn) === -1)
+      .map(x =>
+        Object.assign(EJSON.parse(fs.readFileSync(path.join(specPath, x)), { relaxed: true }), {
+          name: path.basename(x, '.json')
+        })
+      );
+
     after(() => testContext.teardown());
     before(function() {
       return testContext.setup(this.configuration);

From a1db9c2d8ab40c3ad399a5b126a202775210301d Mon Sep 17 00:00:00 2001
From: Neal Beeken <neal.beeken@mongodb.com>
Date: Thu, 9 Sep 2021 16:46:55 -0400
Subject: [PATCH 07/14] fix: turn off leak checker

---
 test/functional/change_stream.test.js | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/test/functional/change_stream.test.js b/test/functional/change_stream.test.js
index b2b558cde5..52a1536cd1 100644
--- a/test/functional/change_stream.test.js
+++ b/test/functional/change_stream.test.js
@@ -1902,7 +1902,10 @@ describe('Change Streams', function() {
     });
 
     it('when invoked with promises', {
-      metadata: { requires: { topology: 'replicaset', mongodb: '>=3.6' } },
+      metadata: {
+        requires: { topology: 'replicaset', mongodb: '>=3.6' },
+        sessions: { skipLeakTests: true }
+      },
       test: function() {
         const test = this;
 
@@ -1925,7 +1928,10 @@ describe('Change Streams', function() {
     });
 
     it('when invoked with callbacks', {
-      metadata: { requires: { topology: 'replicaset', mongodb: '>=3.6' } },
+      metadata: {
+        requires: { topology: 'replicaset', mongodb: '>=3.6' },
+        sessions: { skipLeakTests: true }
+      },
       test: function(done) {
         changeStream.next(() => {
           changeStream.next(() => {
@@ -1952,7 +1958,10 @@ describe('Change Streams', function() {
     });
 
     it('when invoked using eventEmitter API', {
-      metadata: { requires: { topology: 'replicaset', mongodb: '>=3.6' } },
+      metadata: {
+        requires: { topology: 'replicaset', mongodb: '>=3.6' },
+        sessions: { skipLeakTests: true }
+      },
       test: function(done) {
         let closed = false;
         const close = _err => {

From c671d7df3d66d0103d6f35bfbd9e5ebd2db4bb72 Mon Sep 17 00:00:00 2001
From: Neal Beeken <neal.beeken@mongodb.com>
Date: Mon, 13 Sep 2021 11:06:24 -0400
Subject: [PATCH 08/14] fix: clean up error code check function

---
 lib/core/error.js | 19 +++++--------------
 1 file changed, 5 insertions(+), 14 deletions(-)

diff --git a/lib/core/error.js b/lib/core/error.js
index 8272b11a30..350b31c5a2 100644
--- a/lib/core/error.js
+++ b/lib/core/error.js
@@ -292,7 +292,7 @@ const SDAM_NODE_SHUTTING_DOWN_ERROR_CODES = new Set([
 ]);
 
 function isRecoveringError(err) {
-  if (typeof err.code !== 'undefined') {
+  if (typeof err.code === 'number') {
     // If any error code exists, we ignore the error.message
     return SDAM_RECOVERING_CODES.has(err.code);
   }
@@ -301,7 +301,7 @@ function isRecoveringError(err) {
 }
 
 function isNotMasterError(err) {
-  if (typeof err.code !== 'undefined') {
+  if (typeof err.code === 'number') {
     // If any error code exists, we ignore the error.message
     return SDAM_NOTMASTER_CODES.has(err.code);
   }
@@ -321,10 +321,9 @@ function isNodeShuttingDownError(err) {
  * Determines whether SDAM can recover from a given error. If it cannot
  * then the pool will be cleared, and server state will completely reset
  * locally.
- *
- * @ignore
  * @see https://github.com/mongodb/specifications/blob/master/source/server-discovery-and-monitoring/server-discovery-and-monitoring.rst#not-master-and-node-is-recovering
- * @param {MongoError|Error} error
+ * @param {MongoError} error
+ * @returns {boolean}
  */
 function isSDAMUnrecoverableError(error) {
   // NOTE: null check is here for a strictly pre-CMAP world, a timeout or
@@ -333,15 +332,7 @@ function isSDAMUnrecoverableError(error) {
     return true;
   }
 
-  if (typeof error.code !== 'undefined') {
-    return isRecoveringError(error) || isNotMasterError(error);
-  }
-
-  if (isRecoveringError(error) || isNotMasterError(error)) {
-    return true;
-  }
-
-  return false;
+  return isRecoveringError(error) || isNotMasterError(error);
 }
 
 module.exports = {

From dfcda4d1fbed3136f7f02149ec800f5c8dc342ac Mon Sep 17 00:00:00 2001
From: Neal Beeken <neal.beeken@mongodb.com>
Date: Mon, 13 Sep 2021 11:25:17 -0400
Subject: [PATCH 09/14] docs: add comment to test skipping

---
 test/unit/sdam/spec.test.js | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/test/unit/sdam/spec.test.js b/test/unit/sdam/spec.test.js
index e02ee0ced6..3430cbe92b 100644
--- a/test/unit/sdam/spec.test.js
+++ b/test/unit/sdam/spec.test.js
@@ -166,6 +166,9 @@ function executeSDAMTest(testData, testDone) {
   parse(testData.uri, (err, parsedUri) => {
     if (err) {
       if (err.message.toLowerCase().indexOf('load balancer') !== -1) {
+        // currently we do not support load balancer in this driver version
+        // so we just report LB tests as passing without doing anything
+        // TODO: Actually mark these as skipped in mocha?
         return testDone();
       }
       return testDone(err);

From 61ce65753c8df6d91072753ca875ac9f2bcf748d Mon Sep 17 00:00:00 2001
From: Neal Beeken <neal.beeken@mongodb.com>
Date: Mon, 13 Sep 2021 13:36:24 -0400
Subject: [PATCH 10/14] fix: checks for LB mode made simple and skip test
 properly

---
 lib/core/uri_parser.js      | 12 ++----------
 lib/url_parser.js           |  8 ++------
 test/unit/sdam/spec.test.js | 10 ++++------
 3 files changed, 8 insertions(+), 22 deletions(-)

diff --git a/lib/core/uri_parser.js b/lib/core/uri_parser.js
index b867b80e68..434a836cad 100644
--- a/lib/core/uri_parser.js
+++ b/lib/core/uri_parser.js
@@ -107,11 +107,7 @@ function parseSrvConnectionString(uri, options, callback) {
 
         record = qs.parse(record[0].join(''));
 
-        if (
-          Object.keys(record)
-            .map(k => k.toLowerCase())
-            .indexOf('loadbalanced') !== -1
-        ) {
+        if (Object.keys(record).some(k => k.toLowerCase() === 'loadbalanced')) {
           return callback(new MongoParseError('Load balancer mode requires driver version 4+'));
         }
 
@@ -607,11 +603,7 @@ function parseConnectionString(uri, options, callback) {
 
   parsedOptions = Object.assign({}, parsedOptions, options);
 
-  if (
-    Object.keys(parsedOptions)
-      .map(k => k.toLowerCase())
-      .indexOf('loadbalanced') !== -1
-  ) {
+  if (Object.keys(parsedOptions).some(k => k.toLowerCase() === 'loadbalanced')) {
     return callback(new MongoParseError('Load balancer mode requires driver version 4+'));
   }
 
diff --git a/lib/url_parser.js b/lib/url_parser.js
index d9aaca33e0..52a9936fec 100644
--- a/lib/url_parser.js
+++ b/lib/url_parser.js
@@ -101,11 +101,7 @@ module.exports = function(url, options, callback) {
         record = record[0].join('');
         const parsedRecord = qs.parse(record);
         const items = Object.keys(parsedRecord);
-        if (
-          Object.keys(items)
-            .map(k => k.toLowerCase())
-            .indexOf('loadbalanced') !== -1
-        ) {
+        if (Object.keys(items).some(k => k.toLowerCase() === 'loadbalanced')) {
           return callback(new MongoParseError('Load balancer mode requires driver version 4+'));
         }
         if (items.some(item => item !== 'authSource' && item !== 'replicaSet')) {
@@ -386,7 +382,7 @@ function parseConnectionString(url, options) {
   // Split up all the options
   urlOptions = (query_string_part || '').split(/[&;]/);
 
-  if (urlOptions.map(k => k.toLowerCase()).indexOf('loadbalanced') !== -1) {
+  if (urlOptions.some(k => k.toLowerCase() === 'loadbalanced')) {
     throw new MongoParseError('Load balancer mode requires driver version 4+');
   }
 
diff --git a/test/unit/sdam/spec.test.js b/test/unit/sdam/spec.test.js
index 3430cbe92b..0419add913 100644
--- a/test/unit/sdam/spec.test.js
+++ b/test/unit/sdam/spec.test.js
@@ -65,7 +65,7 @@ describe('Server Discovery and Monitoring (spec)', function() {
         it(testData.description, {
           metadata: { requires: { topology: 'single' } },
           test: function(done) {
-            executeSDAMTest(testData, done);
+            executeSDAMTest(this, testData, done);
           }
         });
       });
@@ -162,14 +162,12 @@ function cloneForCompare(event) {
   return result;
 }
 
-function executeSDAMTest(testData, testDone) {
+function executeSDAMTest(ctx, testData, testDone) {
   parse(testData.uri, (err, parsedUri) => {
     if (err) {
-      if (err.message.toLowerCase().indexOf('load balancer') !== -1) {
+      if (err.message === 'Load balancer mode requires driver version 4+') {
         // currently we do not support load balancer in this driver version
-        // so we just report LB tests as passing without doing anything
-        // TODO: Actually mark these as skipped in mocha?
-        return testDone();
+        return ctx.skip();
       }
       return testDone(err);
     }

From 7fc800127e08631d3ae19d5d4dface131db538b4 Mon Sep 17 00:00:00 2001
From: Neal Beeken <neal.beeken@mongodb.com>
Date: Mon, 13 Sep 2021 15:06:33 -0400
Subject: [PATCH 11/14] fix: moved isWritablePrimary patch to ServerDescription
 constructor

---
 lib/core/sdam/server_description.js | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/lib/core/sdam/server_description.js b/lib/core/sdam/server_description.js
index 79ef18171f..6ddde1692f 100644
--- a/lib/core/sdam/server_description.js
+++ b/lib/core/sdam/server_description.js
@@ -70,6 +70,10 @@ class ServerDescription {
       ismaster
     );
 
+    if (ismaster.isWritablePrimary != null) {
+      ismaster.ismaster = ismaster.isWritablePrimary;
+    }
+
     this.address = address;
     this.error = options.error;
     this.roundTripTime = options.roundTripTime || -1;
@@ -79,6 +83,10 @@ class ServerDescription {
     this.type = parseServerType(ismaster);
     this.topologyVersion = options.topologyVersion || ismaster.topologyVersion;
 
+    if (ismaster.isWritablePrimary != null) {
+      ismaster.ismaster = ismaster.isWritablePrimary;
+    }
+
     // direct mappings
     ISMASTER_FIELDS.forEach(field => {
       if (typeof ismaster[field] !== 'undefined') this[field] = ismaster[field];
@@ -180,7 +188,7 @@ function parseServerType(ismaster) {
   if (ismaster.setName) {
     if (ismaster.hidden) {
       return ServerType.RSOther;
-    } else if (ismaster.ismaster || ismaster.isWritablePrimary) {
+    } else if (ismaster.ismaster) {
       return ServerType.RSPrimary;
     } else if (ismaster.secondary) {
       return ServerType.RSSecondary;

From 406df82c252803738d568a29fd839c3b00416b74 Mon Sep 17 00:00:00 2001
From: Neal Beeken <neal.beeken@mongodb.com>
Date: Mon, 13 Sep 2021 15:07:06 -0400
Subject: [PATCH 12/14] fix: remove duplicate patch

---
 lib/core/sdam/server_description.js | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/lib/core/sdam/server_description.js b/lib/core/sdam/server_description.js
index 6ddde1692f..262cafe9f7 100644
--- a/lib/core/sdam/server_description.js
+++ b/lib/core/sdam/server_description.js
@@ -83,10 +83,6 @@ class ServerDescription {
     this.type = parseServerType(ismaster);
     this.topologyVersion = options.topologyVersion || ismaster.topologyVersion;
 
-    if (ismaster.isWritablePrimary != null) {
-      ismaster.ismaster = ismaster.isWritablePrimary;
-    }
-
     // direct mappings
     ISMASTER_FIELDS.forEach(field => {
       if (typeof ismaster[field] !== 'undefined') this[field] = ismaster[field];

From e98f4db990ad758f1e21f00aa90485b2ac8411c5 Mon Sep 17 00:00:00 2001
From: Neal Beeken <neal.beeken@mongodb.com>
Date: Mon, 13 Sep 2021 15:07:41 -0400
Subject: [PATCH 13/14] fix: check for nullish ismaster object

---
 lib/core/sdam/server_description.js | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/core/sdam/server_description.js b/lib/core/sdam/server_description.js
index 262cafe9f7..7bdb791f0a 100644
--- a/lib/core/sdam/server_description.js
+++ b/lib/core/sdam/server_description.js
@@ -70,7 +70,7 @@ class ServerDescription {
       ismaster
     );
 
-    if (ismaster.isWritablePrimary != null) {
+    if (ismaster != null && ismaster.isWritablePrimary != null) {
       ismaster.ismaster = ismaster.isWritablePrimary;
     }
 

From 3d6267ee4a8942e93a6d7bab011160c92ea14c48 Mon Sep 17 00:00:00 2001
From: Neal Beeken <neal.beeken@mongodb.com>
Date: Mon, 13 Sep 2021 15:08:23 -0400
Subject: [PATCH 14/14] fix: no need to check for nullish ismaster

---
 lib/core/sdam/server_description.js | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/core/sdam/server_description.js b/lib/core/sdam/server_description.js
index 7bdb791f0a..262cafe9f7 100644
--- a/lib/core/sdam/server_description.js
+++ b/lib/core/sdam/server_description.js
@@ -70,7 +70,7 @@ class ServerDescription {
       ismaster
     );
 
-    if (ismaster != null && ismaster.isWritablePrimary != null) {
+    if (ismaster.isWritablePrimary != null) {
       ismaster.ismaster = ismaster.isWritablePrimary;
     }