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

@ -36,7 +36,7 @@ VOID TEST(AppCoroutineTest, Dummy)
SrsDummyCoroutine dc;
if (true) {
EXPECT_EQ("", dc.cid());
EXPECT_TRUE(dc.cid().empty());
srs_error_t err = dc.pull();
EXPECT_TRUE(err != srs_success);
@ -52,7 +52,7 @@ VOID TEST(AppCoroutineTest, Dummy)
if (true) {
dc.stop();
EXPECT_EQ("", dc.cid());
EXPECT_TRUE(dc.cid().empty());
srs_error_t err = dc.pull();
EXPECT_TRUE(err != srs_success);
@ -68,7 +68,7 @@ VOID TEST(AppCoroutineTest, Dummy)
if (true) {
dc.interrupt();
EXPECT_EQ("", dc.cid());
EXPECT_TRUE(dc.cid().empty());
srs_error_t err = dc.pull();
EXPECT_TRUE(err != srs_success);
@ -88,7 +88,7 @@ public:
srs_error_t err;
srs_cond_t running;
srs_cond_t exited;
std::string cid;
SrsContextId cid;
// Quit without error.
bool quit;
public:
@ -128,12 +128,12 @@ VOID TEST(AppCoroutineTest, StartStop)
MockCoroutineHandler ch;
SrsSTCoroutine sc("test", &ch);
ch.trd = ≻
EXPECT_EQ("", sc.cid());
EXPECT_TRUE(sc.cid().empty());
// Thread stop after created.
sc.stop();
EXPECT_EQ("", sc.cid());
EXPECT_TRUE(sc.cid().empty());
srs_error_t err = sc.pull();
EXPECT_TRUE(srs_success != err);
@ -151,7 +151,7 @@ VOID TEST(AppCoroutineTest, StartStop)
MockCoroutineHandler ch;
SrsSTCoroutine sc("test", &ch);
ch.trd = ≻
EXPECT_EQ("", sc.cid());
EXPECT_TRUE(sc.cid().empty());
EXPECT_TRUE(srs_success == sc.start());
EXPECT_TRUE(srs_success == sc.pull());
@ -178,7 +178,7 @@ VOID TEST(AppCoroutineTest, StartStop)
MockCoroutineHandler ch;
SrsSTCoroutine sc("test", &ch);
ch.trd = ≻
EXPECT_EQ("", sc.cid());
EXPECT_TRUE(sc.cid().empty());
EXPECT_TRUE(srs_success == sc.start());
EXPECT_TRUE(srs_success == sc.pull());
@ -220,16 +220,16 @@ VOID TEST(AppCoroutineTest, Cycle)
if (true) {
MockCoroutineHandler ch;
SrsSTCoroutine sc("test", &ch, "250");
SrsSTCoroutine sc("test", &ch, SrsContextId("250"));
ch.trd = ≻
EXPECT_TRUE("250" == sc.cid());
EXPECT_TRUE(sc.cid().equals(SrsContextId("250")));
EXPECT_TRUE(srs_success == sc.start());
EXPECT_TRUE(srs_success == sc.pull());
// After running, the cid in cycle should equal to the thread.
srs_cond_timedwait(ch.running, 100 * SRS_UTIME_MILLISECONDS);
EXPECT_TRUE("250" == ch.cid);
EXPECT_TRUE(ch.cid.equals(SrsContextId("250")));
}
if (true) {

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);
}