patch 4.0

This commit is contained in:
wangzelin.wzl
2022-10-24 10:34:53 +08:00
parent 4ad6e00ec3
commit 93a1074b0c
10533 changed files with 2588271 additions and 2299373 deletions

View File

@ -13,20 +13,22 @@
#include <gtest/gtest.h>
#include <iostream>
#include "lib/thread/thread_pool.h"
#include "lib/time/ob_time_utility.h"
#include "../coro/testing.h"
using namespace oceanbase::lib;
using namespace oceanbase::common;
using namespace std;
TEST(TestThreadPool, Submit1)
TEST(TestThreadPool, DISABLED_Submit1)
{
// construct thread pool.
class : public ThreadPool {
class : public ThreadPool
{
void run1() override
{
while (!has_set_stop()) {
this_routine::usleep(100L * 1000L);
::usleep(100L * 1000L);
}
}
} tp;
@ -38,7 +40,7 @@ TEST(TestThreadPool, Submit1)
int ret = OB_SUCCESS;
ret = tp.submit([] {
cout << "ok2" << endl;
this_routine::usleep(1 * 1000L * 1000L);
::usleep(1 * 1000L * 1000L);
});
EXPECT_EQ(OB_SUCCESS, ret);
@ -49,15 +51,15 @@ TEST(TestThreadPool, Submit1)
// after 2s, previous task would be finished so that new task should
// be accepted.
this_routine::usleep(2 * 1000L * 1000L);
::usleep(2 * 1000L * 1000L);
ret = tp.submit([] { cout << "ok4" << endl; });
EXPECT_EQ(OB_SUCCESS, ret);
this_routine::usleep(1 * 1000L * 1000L);
::usleep(1 * 1000L * 1000L);
ret = tp.submit([] { cout << "ok5" << endl; });
EXPECT_EQ(OB_SUCCESS, ret);
this_routine::usleep(1 * 1000L * 1000L);
::usleep(1 * 1000L * 1000L);
ret = tp.submit([] { cout << "ok6" << endl; });
EXPECT_EQ(OB_SUCCESS, ret);
@ -69,11 +71,12 @@ TEST(TestThreadPool, Submit1)
TEST(TestThreadPool, DISABLED_SubmitX)
{
// construct thread pool.
class : public ThreadPool {
class : public ThreadPool
{
void run1() override
{
while (!has_set_stop()) {
this_routine::usleep(100L * 1000L);
::usleep(100L * 1000L);
}
}
} tp;
@ -81,24 +84,28 @@ TEST(TestThreadPool, DISABLED_SubmitX)
tp.set_thread_max_tasks(1);
tp.start();
TIME_LESS(100 * 1000L, [&tp] {
this_routine::usleep(10L * 1000L);
cout << co_current_time() << endl;
tp.submit([] { cout << co_current_time() << endl; });
TIME_LESS(100*1000L, [&tp] {
::usleep(10L * 1000L);
cout << ObTimeUtility::current_time() << endl;
tp.submit([] {
cout << ObTimeUtility::current_time() << endl;
});
});
tp.stop();
tp.wait();
tp.destroy();
}
TEST(TestThreadPool, Submit2)
TEST(TestThreadPool, DISABLED_Submit2)
{
// construct thread pool.
class : public ThreadPool {
class : public ThreadPool
{
void run1() override
{
this_routine::usleep(3 * 1000L * 1000L);
::usleep(3 * 1000L * 1000L);
}
} tp;
tp.init();
@ -109,12 +116,12 @@ TEST(TestThreadPool, Submit2)
int ret = OB_SUCCESS;
ret = tp.submit([] {
cout << "ok2" << endl;
this_routine::usleep(1 * 1000L * 1000L);
::usleep(1 * 1000L * 1000L);
});
EXPECT_EQ(OB_SUCCESS, ret);
ret = tp.submit([] {
cout << "ok2" << endl;
this_routine::usleep(1 * 1000L * 1000L);
::usleep(1 * 1000L * 1000L);
});
EXPECT_EQ(OB_SUCCESS, ret);
@ -125,7 +132,7 @@ TEST(TestThreadPool, Submit2)
// after 2s, previous task would be finished so that new task should
// be accepted.
this_routine::usleep(2 * 1000L * 1000L);
::usleep(2 * 1000L * 1000L);
ret = tp.submit([] { cout << "ok4" << endl; });
EXPECT_EQ(OB_SUCCESS, ret);
@ -134,13 +141,14 @@ TEST(TestThreadPool, Submit2)
tp.destroy();
}
TEST(TestThreadPool, SubmitN)
TEST(TestThreadPool, DISABLED_SubmitN)
{
// construct thread pool.
class : public ThreadPool {
class : public ThreadPool
{
void run1() override
{
this_routine::usleep(3 * 1000L * 1000L);
::usleep(3 * 1000L * 1000L);
}
} tp;
tp.init();
@ -153,40 +161,41 @@ TEST(TestThreadPool, SubmitN)
for (i = 0; i < 100; i++) {
ret = tp.submit([] {
cout << "ok2" << endl;
this_routine::usleep(1 * 1000L * 1000L);
::usleep(1 * 1000L * 1000L);
});
if (OB_FAIL(ret)) {
break;
}
}
EXPECT_EQ(8, i); // 2 * 4
EXPECT_EQ(8, i); // 2 * 4
// wait 2s for previous tasks finishing.
this_routine::usleep(2 * 1000L * 1000L);
::usleep(2 * 1000L * 1000L);
tp.set_thread_count(5);
for (i = 0; i < 100; i++) {
ret = tp.submit([] {
cout << "ok2" << endl;
this_routine::usleep(1 * 1000L * 1000L);
::usleep(1 * 1000L * 1000L);
});
if (OB_FAIL(ret)) {
break;
}
}
EXPECT_EQ(10, i); // 2 * 5
EXPECT_EQ(10, i); // 2 * 5
// tp.stop();
tp.wait();
tp.destroy();
}
TEST(TestThreadPool, LoopCheckConcurrency)
TEST(TestThreadPool, DISABLED_LoopCheckConcurrency)
{
class : public ThreadPool {
class : public ThreadPool
{
void run1() override
{
while (!has_set_stop()) {
this_routine::usleep(3 * 1000L * 1000L);
::usleep(3 * 1000L * 1000L);
}
}
} tp;
@ -202,7 +211,7 @@ TEST(TestThreadPool, LoopCheckConcurrency)
ASSERT_EQ(OB_SUCCESS, tp.submit([&n] { ATOMIC_INC(&n); }));
ASSERT_EQ(OB_SUCCESS, tp.submit([&n] { ATOMIC_INC(&n); }));
while (ATOMIC_LOAD(&n) != 3) {
this_routine::usleep(1 * 1000L);
::usleep(1*1000L);
}
cout << "loop: " << i << endl;
}
@ -212,7 +221,7 @@ TEST(TestThreadPool, LoopCheckConcurrency)
tp.destroy();
}
int main(int argc, char* argv[])
int main(int argc, char *argv[])
{
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();