Skip to content

Commit

Permalink
CCBC-1443: fix time-sensitive tests for scoped queries
Browse files Browse the repository at this point in the history
Change-Id: I8a9774fecb3d60ae651fe34ca3b84c2294aba392
Reviewed-on: http://review.couchbase.org/c/libcouchbase/+/158988
Tested-by: Build Bot <build@couchbase.com>
Reviewed-by: Sergey Avseyev <sergey.avseyev@gmail.com>
  • Loading branch information
avsej committed Aug 11, 2021
1 parent f65a64c commit fb6fab4
Show file tree
Hide file tree
Showing 5 changed files with 317 additions and 44 deletions.
9 changes: 5 additions & 4 deletions src/n1ql/query_handle.cc
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ lcb_STATUS lcb_QUERY_HANDLE_::issue_htreq(const std::string &body)
lcb_cmdhttp_content_type(htcmd, content_type.c_str(), content_type.size());
lcb_cmdhttp_method(htcmd, LCB_HTTP_METHOD_POST);
lcb_cmdhttp_streaming(htcmd, true);
lcb_cmdhttp_timeout(htcmd, timeout);
lcb_cmdhttp_timeout(htcmd, timeout + LCBT_SETTING(instance_, n1ql_grace_period));
lcb_cmdhttp_handle(htcmd, &http_request_);
lcb_cmdhttp_host(htcmd, endpoint.data(), endpoint.size());
if (use_multi_bucket_authentication_) {
Expand All @@ -416,6 +416,10 @@ lcb_STATUS lcb_QUERY_HANDLE_::issue_htreq(const std::string &body)
if (rc == LCB_SUCCESS) {
http_request_->set_callback(reinterpret_cast<lcb_RESPCALLBACK>(chunk_callback));
}
lcb_log(LOGARGS(this, TRACE),
LOGFMT "execute query: %.*s, idempotent=%s, timeout=%uus, grace_period=%uus, client_context_id=\"%s\"",
LOGID(this), (int)body.size(), body.c_str(), idempotent_ ? "true" : "false", timeout,
LCBT_SETTING(instance_, n1ql_grace_period), client_context_id.c_str());
return rc;
}

Expand Down Expand Up @@ -514,9 +518,6 @@ lcb_QUERY_HANDLE_::lcb_QUERY_HANDLE_(lcb_INSTANCE *obj, void *user_cookie, const
if (json.isMember("readonly") && json["readonly"].asBool()) {
idempotent_ = true;
}
lcb_log(LOGARGS(this, TRACE), LOGFMT "%.*s, idempotent=%s, timeout=%uus, grace_period=%uus", LOGID(this),
(int)statement_.size(), statement_.c_str(), idempotent_ ? "true" : "false", timeout,
LCBT_SETTING(obj, n1ql_grace_period));
timeout_timer_.rearm(timeout + LCBT_SETTING(obj, n1ql_grace_period));

// Determine if we need to add more credentials.
Expand Down
4 changes: 4 additions & 0 deletions tests/iotests/mock-environment.cc
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,10 @@ static void statsCallback(lcb_INSTANCE *instance, lcb_CALLBACK_TYPE, const lcb_R
{
MockEnvironment *me = nullptr;
lcb_respstats_cookie(resp, (void **)&me);
if (me->getServerVersion() != MockEnvironment::VERSION_UNKNOWN) {
// ignore all subsequent responses
return;
}
lcb_STATUS rc = lcb_respstats_status(resp);
ASSERT_EQ(LCB_SUCCESS, rc) << lcb_strerror_short(rc);

Expand Down
18 changes: 10 additions & 8 deletions tests/iotests/t_mutate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -840,9 +840,9 @@ TEST_F(MutateUnitTest, testMutateInPreservesExpiry)

lcb_CMDSTORE *cmd;
lcb_cmdstore_create(&cmd, LCB_STORE_UPSERT);
lcb_cmdstore_key(cmd, key.c_str(), key.size());
lcb_cmdstore_value(cmd, value.c_str(), value.size());
lcb_cmdstore_expiry(cmd, birthday);
ASSERT_STATUS_EQ(LCB_SUCCESS, lcb_cmdstore_key(cmd, key.c_str(), key.size()));
ASSERT_STATUS_EQ(LCB_SUCCESS, lcb_cmdstore_value(cmd, value.c_str(), value.size()));
ASSERT_STATUS_EQ(LCB_SUCCESS, lcb_cmdstore_expiry(cmd, birthday));
lcb_STATUS cookie = LCB_ERR_GENERIC;
ASSERT_STATUS_EQ(LCB_SUCCESS, lcb_store(instance, &cookie, cmd));
lcb_cmdstore_destroy(cmd);
Expand All @@ -860,8 +860,9 @@ TEST_F(MutateUnitTest, testMutateInPreservesExpiry)
lcb_cmdsubdoc_key(cmd, key.data(), key.size());
lcb_SUBDOCSPECS *ops;
lcb_subdocspecs_create(&ops, 1);
lcb_subdocspecs_get(ops, 0, LCB_SUBDOCSPECS_F_XATTRPATH, expiry_path.c_str(), expiry_path.size());
lcb_cmdsubdoc_specs(cmd, ops);
ASSERT_STATUS_EQ(LCB_SUCCESS, lcb_subdocspecs_get(ops, 0, LCB_SUBDOCSPECS_F_XATTRPATH, expiry_path.c_str(),
expiry_path.size()));
ASSERT_STATUS_EQ(LCB_SUCCESS, lcb_cmdsubdoc_specs(cmd, ops));
ASSERT_STATUS_EQ(LCB_SUCCESS, lcb_subdoc(instance, &expiry, cmd));
lcb_subdocspecs_destroy(ops);
lcb_cmdsubdoc_destroy(cmd);
Expand All @@ -879,9 +880,10 @@ TEST_F(MutateUnitTest, testMutateInPreservesExpiry)
lcb_cmdsubdoc_key(cmd, key.data(), key.size());
lcb_SUBDOCSPECS *ops;
lcb_subdocspecs_create(&ops, 1);
lcb_subdocspecs_replace(ops, 0, 0, path.c_str(), path.size(), value.c_str(), value.size());
lcb_cmdsubdoc_specs(cmd, ops);
lcb_cmdsubdoc_preserve_expiry(cmd, true);
ASSERT_STATUS_EQ(LCB_SUCCESS,
lcb_subdocspecs_replace(ops, 0, 0, path.c_str(), path.size(), value.c_str(), value.size()));
ASSERT_STATUS_EQ(LCB_SUCCESS, lcb_cmdsubdoc_specs(cmd, ops));
ASSERT_STATUS_EQ(LCB_SUCCESS, lcb_cmdsubdoc_preserve_expiry(cmd, true));
lcb_STATUS cookie = LCB_ERR_GENERIC;
ASSERT_STATUS_EQ(LCB_SUCCESS, lcb_subdoc(instance, &cookie, cmd));
lcb_subdocspecs_destroy(ops);
Expand Down
Loading

0 comments on commit fb6fab4

Please sign in to comment.