diff --git a/test/clustertest/testplugin/TestPlugin.cpp b/test/clustertest/testplugin/TestPlugin.cpp index 784bb9d3d..9978f21ed 100644 --- a/test/clustertest/testplugin/TestPlugin.cpp +++ b/test/clustertest/testplugin/TestPlugin.cpp @@ -103,7 +103,6 @@ unique_ptr BedrockPlugin_TestPlugin::getCommand(SQLiteCommand&& }; for (auto& cmdName : supportedCommands) { if (SStartsWith(baseCommand.request.methodLine, cmdName)) { - SINFO("Called test plugin method " + baseCommand.request.methodLine); return make_unique(move(baseCommand), this); } } @@ -345,15 +344,8 @@ bool TestPluginCommand::peek(SQLite& db) { fileAppend(request["tempFile"], statString); return false; } else if (request.methodLine == "testquery") { - const string nodeName = plugin().server.args["-nodeName"]; - - // This line will generate the node list that processed the command. - // If the current node is on the right version of the cluster, then it will return the node itself - // If it's not on the right version, it will escalate to another follower - // The names will be generated in a way the the left-most node name is the last escalation step - response["nodesPath"] = string(response["nodesPath"]).empty() ? nodeName : nodeName + "," + response["nodesPath"]; - - if (SStartsWith(request["Query"], "select")) { + response["nodeRequestWasExecuted"] = plugin().server.args["-nodeName"]; + if (SStartsWith(request["Query"], "SELECT")) { db.read(request["Query"]); return true; } diff --git a/test/clustertest/tests/VersionMismatchTest.cpp b/test/clustertest/tests/VersionMismatchTest.cpp index c1b0f054c..3afff0086 100644 --- a/test/clustertest/tests/VersionMismatchTest.cpp +++ b/test/clustertest/tests/VersionMismatchTest.cpp @@ -12,7 +12,7 @@ struct VersionMismatchTest : tpunit::TestFixture { BedrockClusterTester* tester = nullptr; void setup() { - tester = new BedrockClusterTester(ClusterSize::FIVE_NODE_CLUSTER, {"CREATE TABLE test (id INTEGER NOT NULL PRIMARY KEY, value TEXT NOT NULL)"}, {}, {}, "testplugin"); + tester = new BedrockClusterTester(ClusterSize::FIVE_NODE_CLUSTER, {"CREATE TABLE test (id INTEGER NOT NULL PRIMARY KEY, value TEXT NOT NULL)"}); // Restart one of the followers on a new version. tester->getTester(2).stopServer(); tester->getTester(2).updateArgs({{"-versionOverride", "ABCDE"}}); @@ -35,59 +35,28 @@ struct VersionMismatchTest : tpunit::TestFixture { auto result = tester->getTester(i).executeWaitMultipleData({command})[0]; // For read commands sent directly to leader, or to a follower on the same version as leader, there - // should be no upstream times. However, on a follower on a different version to leader, it should - // escalates even read commands. - if (i == 2) { - ASSERT_TRUE(SStartsWith(result["nodesPath"], "cluster_node_2")); - ASSERT_EQUAL(result["nodesPath"].length(), 29); - } - if (i == 4) { - ASSERT_TRUE(SStartsWith(result["nodesPath"], "cluster_node_4")); - ASSERT_EQUAL(result["nodesPath"].length(), 29); + // we don't care about how they are executed. However, on a follower on a different version to leader, + // it should escalates even read commands to follower peers. + ASSERT_TRUE(result["nodeRequestWasExecuted"].length() > 0); + if (i == 2 || i == 4) { + // Confirm it didn't execute in leader + ASSERT_NOT_EQUAL(result["nodeRequestWasExecuted"], "cluster_node_0"); + + // Confirm it didn't execute in the server with version mismatch + ASSERT_NOT_EQUAL(result["nodeRequestWasExecuted"], "cluster_node_" + to_string(i)); } } } void testWriteEscalation() { - // Restart one of the followers on a new version. - tester->getTester(2).stopServer(); - tester->getTester(2).updateArgs({{"-versionOverride", "ABCDE"}}); - tester->getTester(2).startServer(); - for (int64_t i = 0; i < 5; i++) { SData command("testquery"); command["Query"] = "INSERT INTO test VALUES(" + SQ(i) + ", " + SQ("val") + ");"; auto result = tester->getTester(i).executeWaitMultipleData({command})[0]; - // For read commands sent directly to leader, or to a follower on the same version as leader, there - // should be no upstream times. However, on a follower on a different version to leader, it should - // escalates even read commands. - if (i == 0) { - ASSERT_EQUAL(result["nodesPath"], "cluster_node_0"); - } - if (i == 1) { - ASSERT_EQUAL(result["nodesPath"], "cluster_node_1,cluster_node_0"); - } - if (i == 2) { - ASSERT_TRUE(SEndsWith(result["nodesPath"], "cluster_node_0")); - - // Since the follower selection is ramdon, there's no way to guarantee which server will - // be the one in the middle. So let's just confirm that the string size is enough to do - // only 3 servers in the path. - // length: cluster_node_2,cluster_node_3,cluster_node_0 = 44 - ASSERT_EQUAL(result["nodesPath"].length(), 44); - } - if (i == 3) { - ASSERT_EQUAL(result["nodesPath"], "cluster_node_3,cluster_node_0"); - } - if (i == 4) { - ASSERT_TRUE(SEndsWith(result["nodesPath"], "cluster_node_0")); - // Since the follower selection is ramdon, there's no way to guarantee which server will - // be the one in the middle. So let's just confirm that the string size is enough to do - // only 3 servers in the path. - // length: cluster_node_4,cluster_node_3,cluster_node_0 = 44 - ASSERT_EQUAL(result["nodesPath"].length(), 44); - } + // For read commands sent directly to leader, or to a follower on the same version as leader, the one + // that will final execute the request should always be the leader + ASSERT_EQUAL(result["nodeRequestWasExecuted"], "cluster_node_0"); } } } __VersionMismatchTest;