ProcessHistoryRegistry_t.cc
Go to the documentation of this file.
1 #define BOOST_TEST_MODULE (ProcessHistoryRegistry_t)
2 #include "boost/test/unit_test.hpp"
3 
9 #include "hep_concurrency/simultaneous_function_spawner.h"
10 
11 #include <string>
12 
13 using namespace art;
14 using namespace std::string_literals;
16 
17 namespace {
19  makeProcessConfiguration(std::string const& process_name,
20  std::string const& module_label)
21  {
22  ParameterSet moduleParams;
23  moduleParams.put("module_type", "IntProducer"s);
24  moduleParams.put("module_label", module_label);
25 
26  ParameterSet processParams;
27  processParams.put("process_name", process_name);
28  processParams.put(module_label, moduleParams);
29 
30  return ProcessConfiguration{
31  process_name, processParams.id(), getReleaseVersion()};
32  }
33 } // namespace
34 
35 BOOST_AUTO_TEST_SUITE(ProcessHistoryTest)
36 
37 BOOST_AUTO_TEST_CASE(concurrent_insertion_reading)
38 {
39  std::vector<ProcessConfiguration> pcs;
40  pcs.push_back(makeProcessConfiguration("p1", "m1"));
41  pcs.push_back(makeProcessConfiguration("p2", "m2"));
42  pcs.push_back(makeProcessConfiguration("pA", "mA"));
43  pcs.push_back(makeProcessConfiguration("pB", "mB"));
44 
45  auto makeProcessHistory = [&pcs](std::size_t const first,
46  std::size_t const last) {
47  ProcessHistory ph;
48  ph.push_back(pcs.at(first));
49  ph.push_back(pcs.at(last));
50  return ph;
51  };
52 
53  std::vector<ProcessHistory> histories;
54  histories.push_back(makeProcessHistory(0, 1));
55  histories.push_back(makeProcessHistory(0, 3));
56  histories.push_back(makeProcessHistory(2, 1));
57  histories.push_back(makeProcessHistory(2, 3));
58 
59  // Insert histories in parallel
60  {
61  std::vector<std::function<void()>> tasks;
62  cet::transform_all(histories, std::back_inserter(tasks), [](auto const& h) {
63  return [&h] { ProcessHistoryRegistry::emplace(h.id(), h); };
64  });
65  hep::concurrency::simultaneous_function_spawner sfs{tasks};
66  }
67 
68  BOOST_TEST_REQUIRE(ProcessHistoryRegistry::get().size() == histories.size());
69 
70  // Retrieve histories in parallel
71  {
72  std::vector<ProcessHistory> retrievedHistories(histories.size());
73  std::vector<std::function<void()>> tasks;
75  histories,
76  [&retrievedHistories, &tasks](std::size_t const i, auto const& h) {
77  auto& entry = retrievedHistories[i];
78  tasks.push_back([&h, &entry] {
79  ProcessHistory retrievedHistory;
80  ProcessHistoryRegistry::get(h.id(), retrievedHistory);
81  entry = std::move(retrievedHistory);
82  });
83  });
84  hep::concurrency::simultaneous_function_spawner sfs{tasks};
85  BOOST_TEST(histories == retrievedHistories);
86  }
87 }
88 
89 BOOST_AUTO_TEST_SUITE_END()
QList< Entry > entry
BOOST_AUTO_TEST_CASE(concurrent_insertion_reading)
std::string string
Definition: nybbler.cc:12
void for_all_with_index(FwdCont &, Func)
BOOST_TEST_REQUIRE(static_cast< bool >(inFile))
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:92
static collection_type const & get()
def move(depos, offset)
Definition: depos.py:107
std::string const & getReleaseVersion()
auto transform_all(Container &, OutputIt, UnaryOp)
ParameterSetID id() const
void push_back(const_reference t)
static auto emplace(value_type const &value)
static QCString * s
Definition: config.cpp:1042
void put(std::string const &key)