We use tbsys multi-thread API for parallel testing In OceanBase. No so bad news is that tbsys has encapsulated an easy API for end user. The real bad news is that every tester should learn how to use the API and facing misuse risk.
What about writing parallel testing code like this:
TEST_F(ObTCFactoryTest, mt_basic_test) { // 第一次并发测试 BEGIN_THREAD_CODE(my_run, 50) { for (int i = 0; i < 1000000; ++i) { Base *b1 = base_tc_factory_t::get_instance()->get(0); ASSERT_TRUE(NULL != b1); } base_tc_factory_t::get_instance()->stat(); } END_THREAD_CODE(my_run); // 一些同步测试代码 // put your code here // 第二次并发测试 BEGIN_THREAD_CODE(my_run2, 50) { for (int i = 0; i < 1000000; ++i) { Base *b1 = base_tc_factory_t::get_instance()->get(0); ASSERT_TRUE(NULL != b1); } base_tc_factory_t::get_instance()->stat(); } END_THREAD_CODE(my_run2); }
#define BEGIN_THREAD_CODE(class_name, thread_count) \ class _##class_name : public tbsys::CDefaultRunnable \ { \ public: \ _##class_name() { _threadCount = thread_count; } \ void run(tbsys::CThread *thread, void *arg) { \ UNUSED(thread); UNUSED(arg); \ #define END_THREAD_CODE(class_name) \ }};\ _##class_name my_##class_name; \ my_##class_name.start(); my_##class_name.wait();
Notes: tbsys is required.