Skip to content

Commit

Permalink
[testapp] Use "userConnection" in more tests
Browse files Browse the repository at this point in the history
And authenticate temporary connections created by getConnection()

Change-Id: I8f4079dc3f0f9d88758d18016dfca2644ef85b22
Reviewed-on: http://review.couchbase.org/c/kv_engine/+/162389
Tested-by: Build Bot <build@couchbase.com>
Reviewed-by: Dave Rigby <daver@couchbase.com>
  • Loading branch information
trondn committed Sep 28, 2021
1 parent d756ee6 commit f714e7c
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 40 deletions.
10 changes: 8 additions & 2 deletions tests/testapp/testapp_not_supported.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@

using cb::mcbp::ClientOpcode;

class NotSupportedTest : public TestappTest {};
class NotSupportedTest : public TestappTest {
public:
static void SetUpTestCase() {
TestappTest::SetUpTestCase();
createUserConnection = true;
}
};

TEST_F(NotSupportedTest, VerifyNotSupported) {
std::vector<ClientOpcode> opcodes = {
Expand Down Expand Up @@ -48,7 +54,7 @@ TEST_F(NotSupportedTest, VerifyNotSupported) {
ClientOpcode::DeregisterTapClient_Unsupported}};

for (const auto opcode : opcodes) {
auto rsp = getConnection().execute(BinprotGenericCommand(opcode));
const auto rsp = userConnection->execute(BinprotGenericCommand(opcode));
ASSERT_EQ(cb::mcbp::Status::NotSupported, rsp.getStatus())
<< "Unexpected response packet: "
<< rsp.getResponse().toJSON(false);
Expand Down
33 changes: 18 additions & 15 deletions tests/testapp/testapp_stats.cc
Original file line number Diff line number Diff line change
Expand Up @@ -101,24 +101,22 @@ TEST_P(StatsTest, StatsResetIsPrivileged) {
}

TEST_P(StatsTest, TestReset) {
MemcachedConnection& conn = getConnection();

auto stats = conn.stats("");
auto stats = userConnection->stats("");
ASSERT_FALSE(stats.empty());

auto before = stats["cmd_get"].get<size_t>();

for (int ii = 0; ii < 10; ++ii) {
EXPECT_THROW(conn.get("foo", Vbid(0)), ConnectionError);
EXPECT_THROW(userConnection->get("foo", Vbid(0)), ConnectionError);
}

stats = conn.stats("");
stats = userConnection->stats("");
EXPECT_NE(before, stats["cmd_get"].get<size_t>());

// the cmd_get counter does work.. now check that reset sets it back..
resetBucket();

stats = conn.stats("");
stats = userConnection->stats("");
EXPECT_EQ(0, stats["cmd_get"].get<size_t>());

// Just ensure that the "reset timings" is detected
Expand All @@ -144,7 +142,8 @@ TEST_P(StatsTest, TestReset) {
*/
TEST_P(StatsTest, Test_MB_17815) {
MemcachedConnection& conn = getConnection();

conn.authenticate("Luke", mcd_env->getPassword("Luke"));
conn.selectBucket(bucketName);
auto stats = conn.stats("");
EXPECT_EQ(0, stats["cmd_set"].get<size_t>());

Expand Down Expand Up @@ -183,6 +182,8 @@ TEST_P(StatsTest, Test_MB_17815) {
*/
TEST_P(StatsTest, Test_MB_17815_Append) {
MemcachedConnection& conn = getConnection();
conn.authenticate("Luke", mcd_env->getPassword("Luke"));
conn.selectBucket(bucketName);

auto stats = conn.stats("");
EXPECT_EQ(0, stats["cmd_set"].get<size_t>());
Expand Down Expand Up @@ -227,6 +228,8 @@ TEST_P(StatsTest, Test_MB_17815_Append) {
*/
TEST_P(StatsTest, Test_MB_29259_Append) {
MemcachedConnection& conn = getConnection();
conn.authenticate("Luke", mcd_env->getPassword("Luke"));
conn.selectBucket(bucketName);

auto stats = conn.stats("");
EXPECT_EQ(0, stats["cmd_set"].get<size_t>());
Expand All @@ -251,6 +254,8 @@ TEST_P(StatsTest, Test_MB_29259_Append) {

TEST_P(StatsTest, TestAppend) {
MemcachedConnection& conn = getConnection();
conn.authenticate("Luke", mcd_env->getPassword("Luke"));
conn.selectBucket(bucketName);

// Set a document
Document doc;
Expand Down Expand Up @@ -371,8 +376,7 @@ TEST_P(StatsTest, TestSchedulerInfo_InvalidSubcommand) {
}

TEST_P(StatsTest, TestAggregate) {
MemcachedConnection& conn = getConnection();
auto stats = conn.stats("aggregate");
auto stats = userConnection->stats("aggregate");
// Don't expect the entire stats set, but we should at least have
// the uptime
EXPECT_NE(stats.end(), stats.find("uptime"));
Expand Down Expand Up @@ -401,6 +405,7 @@ TEST_P(StatsTest, TestPrivilegedConnections) {
TEST_P(StatsTest, TestUnprivilegedConnections) {
// Everyone should be allowed to see its own connection details
MemcachedConnection& conn = getConnection();
conn.authenticate("Luke", mcd_env->getPassword("Luke"));
conn.setAgentName("TestUnprivilegedConnections 1.0");
conn.setFeatures({cb::mcbp::Feature::XERROR});
auto stats = conn.stats("connections");
Expand Down Expand Up @@ -438,8 +443,7 @@ TEST_P(StatsTest, TestConnectionsInvalidNumber) {
}

TEST_P(StatsTest, TestSubdocExecute) {
MemcachedConnection& conn = getConnection();
auto stats = conn.stats("subdoc_execute");
auto stats = userConnection->stats("subdoc_execute");

// json returned should have zero samples as no ops have been performed
EXPECT_TRUE(stats.is_object());
Expand Down Expand Up @@ -474,7 +478,6 @@ TEST_P(StatsTest, TestTracingStats) {
}

TEST_P(StatsTest, TestSingleBucketOpStats) {
auto& conn = getConnection();
std::string key = "key";

// Set a document
Expand All @@ -485,11 +488,11 @@ TEST_P(StatsTest, TestSingleBucketOpStats) {
doc.value = "asdf";

// mutate to bump stat
conn.mutate(doc, Vbid(0), MutationType::Set);
userConnection->mutate(doc, Vbid(0), MutationType::Set);
// lookup to bump stat
conn.get(key, Vbid(0));
userConnection->get(key, Vbid(0));

auto stats = conn.stats("");
auto stats = userConnection->stats("");

EXPECT_FALSE(stats.empty());

Expand Down
4 changes: 2 additions & 2 deletions tests/testapp/testapp_tls.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ class TlsTests : public TestappClientTest {
try {
connection->setTlsProtocol(version);
connection->reconnect();
const auto rsp = connection->execute(
BinprotGenericCommand(cb::mcbp::ClientOpcode::Noop));
const auto rsp = connection->execute(BinprotGenericCommand(
cb::mcbp::ClientOpcode::SaslListMechs));
ASSERT_TRUE(rsp.isSuccess()) << "Failed with version " << version;
} catch (const std::exception& e) {
FAIL() << "Failed with version \"" << version << "\": " << e.what();
Expand Down
38 changes: 17 additions & 21 deletions tests/testapp/testapp_tracing.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,69 +28,65 @@ class TracingTest : public TestappTest {
document.info.id = name;
document.info.expiration = 0;
document.value = memcached_cfg.dump();
userConnection->setFeature(cb::mcbp::Feature::Tracing, false);
}

static void SetUpTestCase() {
TestappTest::SetUpTestCase();
createUserConnection = true;
}

protected:
Document document;
};

TEST_F(TracingTest, NoDataUnlessRequested) {
MemcachedConnection& conn = getConnection();

// Enable Tracing feature on Server
setTracingFeatureOnServer(true);

// Turn OFF feature from client
conn.setFeature(cb::mcbp::Feature::Tracing, false);

// Tracing is NOT explicitly requested, so no trace data
conn.mutate(document, Vbid(0), MutationType::Add);
EXPECT_FALSE(conn.getTraceData());
EXPECT_FALSE(conn.hasFeature(cb::mcbp::Feature::Tracing));
userConnection->mutate(document, Vbid(0), MutationType::Add);
EXPECT_FALSE(userConnection->getTraceData());
EXPECT_FALSE(userConnection->hasFeature(cb::mcbp::Feature::Tracing));
}

TEST_F(TracingTest, ValidDataOnRequest) {
MemcachedConnection& conn = getConnection();
// Enable Tracing feature on Server
setTracingFeatureOnServer(true);

// Request Trace Info
conn.setFeature(cb::mcbp::Feature::Tracing, true);
userConnection->setFeature(cb::mcbp::Feature::Tracing, true);

// Expect some trace data
auto start = std::chrono::steady_clock::now();
conn.mutate(document, Vbid(0), MutationType::Add);
userConnection->mutate(document, Vbid(0), MutationType::Add);
auto end = std::chrono::steady_clock::now();
auto duration =
std::chrono::duration_cast<std::chrono::microseconds>(end - start);
auto traceData = conn.getTraceData();
auto traceData = userConnection->getTraceData();
EXPECT_TRUE(traceData);
EXPECT_TRUE(conn.hasFeature(cb::mcbp::Feature::Tracing));
EXPECT_TRUE(userConnection->hasFeature(cb::mcbp::Feature::Tracing));

// expect the above operation to complete in <= overall time
EXPECT_LE(*traceData, duration);
}

TEST_F(TracingTest, NoDataWhenDisabledOnServer) {
MemcachedConnection& conn = getConnection();

// Disable Tracing feature on Server
setTracingFeatureOnServer(false);

// Tracing is disabled on server, so no trace data
conn.mutate(document, Vbid(0), MutationType::Add);
EXPECT_FALSE(conn.getTraceData());
EXPECT_FALSE(conn.hasFeature(cb::mcbp::Feature::Tracing));
userConnection->mutate(document, Vbid(0), MutationType::Add);
EXPECT_FALSE(userConnection->getTraceData());
EXPECT_FALSE(userConnection->hasFeature(cb::mcbp::Feature::Tracing));
}

TEST_F(TracingTest, FailOnFeatureRequestWhenDisabledOnServer) {
MemcachedConnection& conn = getConnection();

// Disable Tracing feature on Server
setTracingFeatureOnServer(false);

// Request Tracing Data
// This will fail as the feature is disabled on Server
EXPECT_THROW(conn.setFeature(cb::mcbp::Feature::Tracing, true),
EXPECT_THROW(userConnection->setFeature(cb::mcbp::Feature::Tracing, true),
std::runtime_error);
}

0 comments on commit f714e7c

Please sign in to comment.