LCOV - code coverage report
Current view: top level - tests - separator_suite.cpp (source / functions) Hit Total Coverage
Test: wrtstat-coverage.info Lines: 75 76 98.7 %
Date: 2019-09-13 Functions: 16 16 100.0 %

          Line data    Source code
       1             : #include <fas/testing.hpp>
       2             : #include <wrtstat/separator.hpp>
       3             : 
       4             : namespace {
       5             :   
       6           3 : UNIT(separator0, "")
       7             : {
       8             :   using namespace fas::testing;
       9             :   using namespace wrtstat;
      10             : 
      11           1 :   t << equal<expect, time_type>( std::time(nullptr), separator::now_t<std::chrono::seconds>() ) << FAS_FL;
      12             :   
      13           1 :   separator_options opt;
      14           1 :   opt.reducer_levels = 1;
      15           1 :   opt.reducer_limit  = 8;
      16           1 :   opt.resolution = resolutions::none;
      17           1 :   opt.aggregation_step_ts = 10;
      18           1 :   separator sep(0, opt);
      19           1 :   time_t tc = sep.current_time();
      20           1 :   t << equal<expect>( tc, 0 ) << FAS_FL;
      21         101 :   for (int i = 0 ; i < 100; i++)
      22             :   {
      23         100 :     t << is_true<expect>( sep.add(i, i, 1) ) << "i=" << i  << FAS_FL;
      24         100 :     t << equal<expect>( sep.current_time(), (i/10)*10 ) << "i=" << i << FAS_FL;
      25         100 :     t << equal<expect>( sep.next_time(), (i/10)*10 + 10 ) << "i=" << i << FAS_FL;
      26             :   }
      27           1 :   sep.separate(100, nullptr, true);
      28           1 :   t << equal<expect>( sep.size(), 10ul ) << FAS_FL;
      29           1 :   t << is_true<expect>( sep.ready() ) << FAS_FL;
      30          11 :   for (int i = 0 ; i < 10; i++)
      31             :   {
      32          10 :     auto s = sep.pop();
      33          10 :     t << is_true<assert>( s!=nullptr ) << "i=" << i << FAS_FL;
      34          10 :     t << stop;
      35          10 :     t << equal<expect>( s->ts, i*10 ) << "i=" << i << FAS_FL;
      36             :   }
      37             : 
      38           1 :   t << nothing;
      39           1 : }
      40             : 
      41           3 : UNIT(separator1, "")
      42             : {
      43             :   using namespace fas::testing;
      44             :   using namespace wrtstat;
      45             : 
      46           1 :   t << equal<expect, time_type>( std::time(nullptr), separator::now_t<std::chrono::seconds>() ) << FAS_FL;
      47             :   
      48           1 :   separator_options opt;
      49           1 :   opt.reducer_levels = 1;
      50           1 :   opt.reducer_limit  = 8;
      51           1 :   opt.resolution = resolutions::none;
      52           1 :   opt.aggregation_step_ts = 10;
      53           1 :   separator sep(0, opt);
      54         101 :   for (int i = 10 ; i < 110; i++)
      55             :   {
      56         100 :     t << is_true<expect>( sep.add(i, i, 1) ) << "i=" << i  << FAS_FL;
      57         100 :     t << equal<expect>( sep.current_time(), (i/10)*10 ) << "i=" << i << FAS_FL;
      58         100 :     t << equal<expect>( sep.next_time(), (i/10)*10 + 10 ) << "i=" << i << FAS_FL;
      59             :   }
      60           1 :   sep.separate(110, nullptr, true);
      61           1 :   t << equal<expect>( sep.size(), 10ul ) << FAS_FL;
      62           1 :   t << is_true<expect>( sep.ready() ) << FAS_FL;
      63          11 :   for (int i = 0 ; i < 10; i++)
      64             :   {
      65          10 :     auto s = sep.pop();
      66          10 :     t << is_true<assert>( s!=nullptr ) << "i=" << i << FAS_FL;
      67          10 :     t << stop;
      68          10 :     t << equal<expect>( s->ts, (i+1)*10 ) << "i=" << i << FAS_FL;
      69           1 :   }
      70           1 : }
      71             : 
      72           3 : UNIT(separator2, "")
      73             : {
      74             :   using namespace fas::testing;
      75             :   using namespace wrtstat;
      76             : 
      77           2 :   t << equal<expect, time_type>( std::time(nullptr)*1000000000, (separator::now_t<std::chrono::nanoseconds>()/1000000000 * 1000000000) ) 
      78           1 :     << FAS_FL;
      79             :   
      80           1 :   separator_options opt;
      81           1 :   opt.reducer_levels = 1;
      82           1 :   opt.reducer_limit  = 8;
      83           1 :   opt.resolution = resolutions::nanoseconds;
      84           1 :   opt.aggregation_step_ts = 1000;
      85           1 :   separator sep(0, opt);
      86           1 :   time_t now_stub = time(nullptr);
      87          11 :   for (int j = 0 ; j < 10; ++j)
      88             :   {
      89        1010 :     for (int i = 0 ; i < 100; i++)
      90             :     {
      91        1000 :       if ( time(nullptr) > now_stub + 1  )
      92             :       {
      93           0 :         t << warning("Сработала заглушка. Под valgrind?");
      94           1 :         return; // заглушка для valgrind( очень долго )
      95             :       }
      96        1000 :       auto now = separator::now_t<std::chrono::nanoseconds>();
      97        1000 :       t << is_true<expect>( sep.add(now, i, 1) ) << "i=" << i  << FAS_FL;
      98        1000 :       t << equal<expect>( sep.current_time(), (now/opt.aggregation_step_ts)*opt.aggregation_step_ts ) << "i=" << i << FAS_FL;
      99        1000 :       t << equal<expect>( sep.next_time(), (now/opt.aggregation_step_ts + 1)*opt.aggregation_step_ts ) << "i=" << i << FAS_FL;
     100             :     }
     101             :   }
     102           1 :   t << flush;
     103           1 :   sep.separate(0, nullptr, true);
     104           1 :   t << equal<expect>( sep.size(), 1000ul ) << FAS_FL;
     105           1 :   t << is_true<expect>( sep.ready() ) << FAS_FL;
     106        1001 :   for (int i = 0 ; i < 1000; i++)
     107             :   {
     108        1000 :     auto s = sep.pop();
     109        1000 :     t << is_true<assert>( s!=nullptr ) << "i=" << i << FAS_FL;
     110        1000 :     t << stop;
     111             :   }
     112             : 
     113           1 :   t << nothing;
     114             : }
     115             : }
     116             : 
     117           1 : BEGIN_SUITE(separator, "")
     118             :   ADD_UNIT(separator0)
     119             :   ADD_UNIT(separator1)
     120             :   ADD_UNIT(separator2)
     121           7 : END_SUITE(separator)
     122             : 

Generated by: LCOV version 1.10