void parseTest(fs::path testFilePath) {
        _testFilePath = testFilePath.string();
        LOGV2(4333507, "### Parsing Test ###", "testFilePath"_attr = testFilePath.string());
        {
            std::ifstream testFile(_testFilePath);
            std::ostringstream json;
            json << testFile.rdbuf();
            _jsonTest = fromjson(json.str());
        }

        // Do this first to save the state
        if (_jsonTest.hasField("error")) {
            LOGV2(5017004, "Expecting test case to generate an error.");
            _errorExpected = _jsonTest.getBoolField("error");
        }

        // The json tests pass in capitalized keywords for mode, but the server only accepts
        // lowercased keywords. Also, change the key "tags_set" to "tags".
        // This can throw for test cases that have invalid read preferences.
        auto readPrefObj = _jsonTest.getObjectField("read_preference");
        std::string mode = readPrefObj.getStringField("mode");
        mode[0] = std::tolower(mode[0]);
        auto tagSetsObj = readPrefObj["tag_sets"];
        auto tags = tagSetsObj ? BSONArray(readPrefObj["tag_sets"].Obj()) : BSONArray();


        auto topologyDescriptionObj = _jsonTest.getObjectField("topology_description");
        TopologyType initType =
            uassertStatusOK(parseTopologyType(topologyDescriptionObj.getStringField("type")));
        boost::optional<std::string> setName = boost::none;
        if (initType == TopologyType::kReplicaSetNoPrimary || initType == TopologyType::kSingle)
            setName = "replset";

        int maxStalenessSeconds = 0;
        if (readPrefObj.hasField("maxStalenessSeconds")) {
            maxStalenessSeconds = readPrefObj.getIntField("maxStalenessSeconds");
        }

        BSONObj readPref =
            BSON("mode" << mode << "tags" << tags << "maxStalenessSeconds" << maxStalenessSeconds);
        auto stalenessParseResult = ReadPreferenceSetting::fromInnerBSON(readPref);
        if (!_errorExpected &&
            stalenessParseResult.getStatus().code() == ErrorCodes::MaxStalenessOutOfRange &&
            (initType == TopologyType::kUnknown || initType == TopologyType::kSingle ||
             initType == TopologyType::kSharded)) {
            // Drivers tests expect no error for invalid maxStaleness values for Unknown, Single,
            // and Sharded topology types. The server code doesn't allow read preferences to be
            // created for invalid values for maxStaleness, so ignore it.
            readPref = BSON("mode" << mode << "tags" << tags << "maxStalenessSeconds" << 0);
            stalenessParseResult = ReadPreferenceSetting::fromInnerBSON(readPref);
        } else if (_errorExpected && maxStalenessSeconds == 0 &&
                   readPrefObj.hasField("maxStalenessSeconds")) {
            // Generate an error to pass test cases that set max staleness to zero since the server
            // interprets this as no maxStaleness is specified.
            uassert(ErrorCodes::MaxStalenessOutOfRange, "max staleness should be >= 0", false);
        }
        _readPreference = uassertStatusOK(stalenessParseResult);
        LOGV2(5017007, "Read Preference", "value"_attr = _readPreference);

        if (_jsonTest.hasField("heartbeatFrequencyMS")) {
            sdamHeartBeatFrequencyMs = _jsonTest.getIntField("heartbeatFrequencyMS");
            LOGV2(5017003, "Set heartbeatFrequencyMs", "value"_attr = sdamHeartBeatFrequencyMs);
        }

        std::vector<ServerDescriptionPtr> serverDescriptions;
        std::vector<HostAndPort> serverAddresses;
        const std::vector<BSONElement>& bsonServers = topologyDescriptionObj["servers"].Array();

        for (auto bsonServer : bsonServers) {
            auto server = bsonServer.Obj();

            int maxWireVersion = 9;
            if (server.hasField("maxWireVersion")) {
                maxWireVersion = server["maxWireVersion"].numberInt();
            }

            auto serverType = uassertStatusOK(parseServerType(server.getStringField("type")));
            auto serverDescription = ServerDescriptionBuilder()
                                         .withAddress(HostAndPort(server.getStringField("address")))
                                         .withType(serverType)
                                         .withRtt(Milliseconds(server["avg_rtt_ms"].numberInt()))
                                         .withMinWireVersion(5)
                                         .withMaxWireVersion(maxWireVersion);

            if (server.hasField("lastWrite")) {
                auto lastWriteDate =
                    server.getObjectField("lastWrite").getIntField("lastWriteDate");
                serverDescription.withLastWriteDate(Date_t::fromMillisSinceEpoch(lastWriteDate));
            }

            if (server.hasField("lastUpdateTime")) {
                auto lastUpdateTime = server.getIntField("lastUpdateTime");
                serverDescription.withLastUpdateTime(Date_t::fromMillisSinceEpoch(lastUpdateTime));
            }

            auto tagsObj = server.getObjectField("tags");
            const auto keys = tagsObj.getFieldNames<std::set<std::string>>();
            for (const auto key : keys) {
                serverDescription.withTag(key, tagsObj.getStringField(key));
            }

            serverDescriptions.push_back(serverDescription.instance());
            LOGV2(5017002,
                  "Server Description",
                  "description"_attr = serverDescriptions.back()->toBson());
            serverAddresses.push_back(HostAndPort(server.getStringField("address")));
        }


        boost::optional<std::vector<HostAndPort>> seedList = boost::none;
        if (serverAddresses.size() > 0)
            seedList = serverAddresses;

        auto config = SdamConfiguration(seedList,
                                        initType,
                                        Milliseconds{sdamHeartBeatFrequencyMs},
                                        Milliseconds{sdamConnectTimeoutMs},
                                        Milliseconds{sdamLocalThreshholdMs},
                                        setName);
        _topologyDescription = std::make_shared<TopologyDescription>(config);

        if (_jsonTest.hasField("in_latency_window")) {
            const std::vector<BSONElement>& bsonLatencyWindow =
                _jsonTest["in_latency_window"].Array();
            for (const auto& serverDescription : serverDescriptions) {
                _topologyDescription->installServerDescription(serverDescription);

                for (auto bsonServer : bsonLatencyWindow) {
                    auto server = bsonServer.Obj();
                    if (serverDescription->getAddress() ==
                        HostAndPort(server.getStringField("address"))) {
                        _inLatencyWindow.push_back(serverDescription);
                    }
                }
            }
        }
    }