ATLAS Offline Software
Public Member Functions | Static Public Member Functions | List of all members
ParallelCallTest Class Referenceabstract

Provides interface and helper functions to perform stress testing of the thread-safe code. More...

#include <ParallelCallTest.h>

Inheritance diagram for ParallelCallTest:
Collaboration diagram for ParallelCallTest:

Public Member Functions

virtual ~ParallelCallTest ()
 
bool run (size_t nrepeats)
 runs the stress test by invoking it the firstCall and then repetitively the callAndCompare More...
 
virtual void firstCall ()=0
 a method that will be called to obtain first results from the service It should set the reference quantities More...
 
virtual bool callAndCompare () const =0
 a function that performs request, and compares the results obtained with the result of the first execution When result differ this function is supposed to return false, otherwise true More...
 

Static Public Member Functions

static bool launchTests (size_t nrepeats, const std::vector< ParallelCallTest * > &tests)
 Method to run launch number of tests in parallel (increasing the stress of the calle) It has a potential that also the "first" calls can be launched in parallel and thus be the worse case compared to a situation when the first calls are invoked sequentially while further calls in parallel. More...
 

Detailed Description

Provides interface and helper functions to perform stress testing of the thread-safe code.

It is applicable to services which are meant to return identical reposnse to the same request/query independently of the order of execution. Examples of such services are all sort of cache handlers.

Testing idea is that the implementation of the ParallelCallTest interface provides two methods. The firstCall which performs request/query of the service and treats the response as a reference. The callAndCompare (called several times in parallel) repeats the query and compares the result to the reference. When successive responses differ from the reference it means that the service is not thread-safe.

Typically one shoudl construct several (compeeting) call scenarios and launch them all in parallel. The helper function launchTests facilitates this task.

An example of testing is available in the tests/PrallelCalltest_example.cxx Implementation uses tbb::parallel_* so in order to make the testing effective a tbb thread pool has to be > 1.

Definition at line 30 of file ParallelCallTest.h.

Constructor & Destructor Documentation

◆ ~ParallelCallTest()

virtual ParallelCallTest::~ParallelCallTest ( )
inlinevirtual

Definition at line 32 of file ParallelCallTest.h.

32 {}

Member Function Documentation

◆ callAndCompare()

virtual bool ParallelCallTest::callAndCompare ( ) const
pure virtual

a function that performs request, and compares the results obtained with the result of the first execution When result differ this function is supposed to return false, otherwise true

Implemented in AskForRoI, and AskForROBs.

◆ firstCall()

virtual void ParallelCallTest::firstCall ( )
pure virtual

a method that will be called to obtain first results from the service It should set the reference quantities

Implemented in AskForRoI, and AskForROBs.

◆ launchTests()

bool ParallelCallTest::launchTests ( size_t  nrepeats,
const std::vector< ParallelCallTest * > &  tests 
)
static

Method to run launch number of tests in parallel (increasing the stress of the calle) It has a potential that also the "first" calls can be launched in parallel and thus be the worse case compared to a situation when the first calls are invoked sequentially while further calls in parallel.

Definition at line 83 of file ParallelCallTest.cxx.

83  {
84  // Suppress undefined behavior warning resulting from a tbb bug.
85  // /cvmfs/atlas-nightlies.cern.ch/repo/sw/master/sw/lcg/releases/LCG_88/tbb/44_20160413/x86_64-slc6-gcc62-dbg/include/tbb/parallel_reduce.h:177:32: runtime error: member call on address 0x2aab14047b40 which does not point to an object of type 'task'
86  //0x2aab14047b40: note: object has invalid vptr
87  // 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0
88  // cf. https://github.com/RcppCore/RcppParallel/issues/36
89  RedirStderr redir;
90 
91  //std::vector<ParallelCallTest*> tests( testList.begin(), testList.end() );
92  return tbb::parallel_reduce( tbb::blocked_range< std::vector<ParallelCallTest*>::const_iterator >( tests.begin(), tests.end() ),
93  true, // initial value
94  [&]( tbb::blocked_range< std::vector<ParallelCallTest*>::const_iterator > groupOfTests, bool statusSoFar ) -> bool {
95  bool success = true;
96  for ( auto test : groupOfTests ) {
97  success = test->run( nrepeats ) and success;
98  }
99  return statusSoFar and success;
100  },
101  []( bool allCallsStatus, bool thisCallStatus ) -> bool { // result accumulation
102  return allCallsStatus and thisCallStatus;
103  } );
104 }

◆ run()

bool ParallelCallTest::run ( size_t  nrepeats)

runs the stress test by invoking it the firstCall and then repetitively the callAndCompare

  • nrepeats times (>=1) A single failure of the callAndCompare would result in the whole execution failed

Definition at line 69 of file ParallelCallTest.cxx.

69  {
70  firstCall();
71 
72  return tbb::parallel_reduce( tbb::blocked_range<int>( 0, nrepeats, 1 ),
73  true, // initial value
74  [&]( tbb::blocked_range<int>, bool statusSoFar ) -> bool {
75  return callAndCompare() and statusSoFar;
76  },
77  []( bool allCallsStatus, bool thisCallStatus ) -> bool { // result accumulation
78  return allCallsStatus and thisCallStatus;
79  } );
80 }

The documentation for this class was generated from the following files:
ParallelCallTest::firstCall
virtual void firstCall()=0
a method that will be called to obtain first results from the service It should set the reference qua...
python.setupRTTAlg.tests
list tests
Definition: setupRTTAlg.py:40
ParallelCallTest::callAndCompare
virtual bool callAndCompare() const =0
a function that performs request, and compares the results obtained with the result of the first exec...