[MacrayKV] An innovative parallel testing framework

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

}

With the help of my parallel testing framework, now you can!

#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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值