You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@brpc.apache.org by ja...@apache.org on 2020/11/27 05:13:43 UTC
[incubator-brpc] branch fix_crash_of_ut updated: add debugging code
This is an automated email from the ASF dual-hosted git repository.
jamesge pushed a commit to branch fix_crash_of_ut
in repository https://gitbox.apache.org/repos/asf/incubator-brpc.git
The following commit(s) were added to refs/heads/fix_crash_of_ut by this push:
new 3e38b26 add debugging code
3e38b26 is described below
commit 3e38b26d9cb6e3a7a58d4765546e918af50bd6d2
Author: jamesge <jg...@gmail.com>
AuthorDate: Fri Nov 27 13:13:17 2020 +0800
add debugging code
---
src/brpc/controller.cpp | 19 ++++++++++++++++++-
src/brpc/controller.h | 1 +
test/brpc_controller_unittest.cpp | 8 +++++---
3 files changed, 24 insertions(+), 4 deletions(-)
diff --git a/src/brpc/controller.cpp b/src/brpc/controller.cpp
index f343edb..fa59919 100644
--- a/src/brpc/controller.cpp
+++ b/src/brpc/controller.cpp
@@ -21,6 +21,7 @@
#include <google/protobuf/descriptor.h>
#include <gflags/gflags.h>
#include "bthread/bthread.h"
+#include "butil/atomicops.h"
#include "butil/build_config.h" // OS_MACOSX
#include "butil/string_printf.h"
#include "butil/logging.h"
@@ -1542,14 +1543,30 @@ void Controller::FlushSessionKV(std::ostream& os) {
Controller::LogPostfixDummy::~LogPostfixDummy() {
if (osptr != nullptr) {
+ std::cout << "osptr=" << osptr << std::endl;
*osptr << postfix;
}
}
+static void testfn(std::ios::event ev, std::ios_base& stream, int index) {
+ switch (ev) {
+ case std::ios_base::copyfmt_event:
+ std::cout << "copyfmt_event"; break;
+ case std::ios_base::imbue_event:
+ std::cout << "imbue_event"; break;
+ case std::ios_base::erase_event:
+ std::cout << "erase_event"; break;
+ }
+ std::cout << " ptr=" << &stream << " index=" << index << std::endl;
+}
+butil::static_atomic<int> _counter;
std::ostream& operator<<(std::ostream& os, const Controller::LogPostfixDummy& p) {
+ const auto index = _counter.fetch_add(1, butil::memory_order_relaxed);
+ os.register_callback(testfn, index);
const_cast<brpc::Controller::LogPostfixDummy&>(p).osptr = &os;
+ os << "Index=" << index << ' ' ;
if (FLAGS_log_as_json) {
- os << "\"M\":\"";
+ os << "\"M\":\"" << index;
}
return os;
}
diff --git a/src/brpc/controller.h b/src/brpc/controller.h
index 8a75c54..761b5fb 100755
--- a/src/brpc/controller.h
+++ b/src/brpc/controller.h
@@ -493,6 +493,7 @@ public:
// Contextual prefixes for LOGD/LOGI/LOGW/LOGE/LOGF macros
struct LogPostfixDummy {
LogPostfixDummy() : osptr(nullptr) {}
+ LogPostfixDummy(const LogPostfixDummy&) : osptr(nullptr) {}
~LogPostfixDummy();
std::string postfix;
std::ostream* osptr;
diff --git a/test/brpc_controller_unittest.cpp b/test/brpc_controller_unittest.cpp
index 011928c..606b0f7 100644
--- a/test/brpc_controller_unittest.cpp
+++ b/test/brpc_controller_unittest.cpp
@@ -95,7 +95,6 @@ TEST_F(ControllerTest, SessionKV) {
FLAGS_log_as_json = false;
logging::StringSink sink1;
auto oldSink = logging::SetLogSink(&sink1);
- //brpc::SetGlobalSessionLogFormatter(new MyFormatter);
{
brpc::Controller cntl;
cntl.set_log_id(123); // not working now
@@ -104,18 +103,21 @@ TEST_F(ControllerTest, SessionKV) {
cntl.SessionKV().Set("Cisco", 33.3);
LOGW(&cntl) << "My WARNING Log";
- ASSERT_TRUE(endsWith(sink1, "] My WARNING Log")) << sink1;
+ //ASSERT_TRUE(endsWith(sink1, "] My WARNING Log")) << sink1;
ASSERT_TRUE(startsWith(sink1, "W")) << sink1;
+ std::cout << sink1 << std::endl;
sink1.clear();
cntl.http_request().SetHeader("x-request-id", "abcdEFG-456");
LOGE(&cntl) << "My ERROR Log";
- ASSERT_TRUE(endsWith(sink1, "] My ERROR Log @rid:abcdEFG-456")) << sink1;
+ //ASSERT_TRUE(endsWith(sink1, "] My ERROR Log @rid:abcdEFG-456")) << sink1;
ASSERT_TRUE(startsWith(sink1, "E")) << sink1;
+ std::cout << sink1 << std::endl;
sink1.clear();
FLAGS_log_as_json = true;
}
+ std::cout << sink1 << std::endl;
ASSERT_TRUE(endsWith(sink1, R"(,"M":"Session ends","@rid":"abcdEFG-456","Baidu":"22","Cisco":"33.300000","Apple":"1"})")) << sink1;
ASSERT_TRUE(startsWith(sink1, R"({"L":"I",)")) << sink1;
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org