What about writing parallel testing code like this:
[cpp]
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);
}
With the help of my parallel testing framework, now you can!
[cpp]
#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();
Simple enough!
Notes: tbsys is required.