1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

Log: Use object as context id for complex context

This commit is contained in:
winlin 2020-07-05 23:26:55 +08:00
parent bff7ef085d
commit 6624b8acca
34 changed files with 276 additions and 238 deletions

View file

@ -898,7 +898,7 @@ class MockOnCycleThread : public ISrsCoroutineHandler
public:
SrsSTCoroutine trd;
srs_cond_t cond;
MockOnCycleThread() : trd("mock", this, "0") {
MockOnCycleThread() : trd("mock", this) {
cond = srs_cond_new();
};
virtual ~MockOnCycleThread() {
@ -938,7 +938,7 @@ class MockOnCycleThread2 : public ISrsCoroutineHandler
public:
SrsSTCoroutine trd;
srs_mutex_t lock;
MockOnCycleThread2() : trd("mock", this, "0") {
MockOnCycleThread2() : trd("mock", this) {
lock = srs_mutex_new();
};
virtual ~MockOnCycleThread2() {
@ -979,7 +979,7 @@ class MockOnCycleThread3 : public ISrsCoroutineHandler
public:
SrsSTCoroutine trd;
srs_netfd_t fd;
MockOnCycleThread3() : trd("mock", this, "0") {
MockOnCycleThread3() : trd("mock", this) {
fd = NULL;
};
virtual ~MockOnCycleThread3() {
@ -1230,7 +1230,7 @@ class MockOnCycleThread4 : public ISrsCoroutineHandler
public:
SrsSTCoroutine trd;
srs_netfd_t fd;
MockOnCycleThread4() : trd("mock", this, "0") {
MockOnCycleThread4() : trd("mock", this) {
fd = NULL;
};
virtual ~MockOnCycleThread4() {
@ -1382,19 +1382,19 @@ VOID TEST(TCPServerTest, ContextUtility)
if (true) {
SrsThreadContext ctx;
EXPECT_TRUE("" == ctx.set_id("100"));
EXPECT_TRUE("100" == ctx.set_id("1000"));
EXPECT_TRUE("1000" == ctx.get_id());
EXPECT_TRUE(ctx.set_id(SrsContextId("100")).empty());
EXPECT_TRUE(ctx.set_id(SrsContextId("1000")).equals(SrsContextId("100")));
EXPECT_TRUE(ctx.get_id().equals(SrsContextId("1000")));
ctx.clear_cid();
EXPECT_TRUE("" == ctx.set_id("100"));
EXPECT_TRUE(ctx.set_id(SrsContextId("100")).empty());
}
int base_size = 0;
if (true) {
errno = 0;
int size = 0; char buf[1024]; HELPER_ARRAY_INIT(buf, 1024, 0);
ASSERT_TRUE(srs_log_header(buf, 1024, true, true, "SRS", "100", "Trace", &size));
ASSERT_TRUE(srs_log_header(buf, 1024, true, true, "SRS", SrsContextId("100"), "Trace", &size));
base_size = size;
EXPECT_TRUE(base_size > 0);
}
@ -1402,21 +1402,21 @@ VOID TEST(TCPServerTest, ContextUtility)
if (true) {
errno = 0;
int size = 0; char buf[1024]; HELPER_ARRAY_INIT(buf, 1024, 0);
ASSERT_TRUE(srs_log_header(buf, 1024, false, true, "SRS", "100", "Trace", &size));
ASSERT_TRUE(srs_log_header(buf, 1024, false, true, "SRS", SrsContextId("100"), "Trace", &size));
EXPECT_EQ(base_size, size);
}
if (true) {
errno = 0;
int size = 0; char buf[1024]; HELPER_ARRAY_INIT(buf, 1024, 0);
ASSERT_TRUE(srs_log_header(buf, 1024, false, true, NULL, "100", "Trace", &size));
ASSERT_TRUE(srs_log_header(buf, 1024, false, true, NULL, SrsContextId("100"), "Trace", &size));
EXPECT_EQ(base_size - 5, size);
}
if (true) {
errno = 0;
int size = 0; char buf[1024]; HELPER_ARRAY_INIT(buf, 1024, 0);
ASSERT_TRUE(srs_log_header(buf, 1024, false, false, NULL, "100", "Trace", &size));
ASSERT_TRUE(srs_log_header(buf, 1024, false, false, NULL, SrsContextId("100"), "Trace", &size));
EXPECT_EQ(base_size - 8, size);
}