• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

STEllAR-GROUP / hpx / #880

05 Feb 2023 12:51AM UTC coverage: 85.952% (-0.6%) from 86.575%
#880

push

StellarBot
Merge #6129

6129: Modernize module from levels 22, 23 r=hkaiser a=hkaiser

working towards https://github.com/STEllAR-GROUP/hpx/issues/5497

Modules:
- core/executors
- core/async_local
- core/timed_execution

Co-authored-by: Hartmut Kaiser <hartmut.kaiser@gmail.com>

45 of 45 new or added lines in 13 files covered. (100.0%)

173593 of 201964 relevant lines covered (85.95%)

1868047.33 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

20.51
/libs/full/async_distributed/tests/unit/async_cb_remote_client.cpp
1
//  Copyright (c) 2007-2015 Hartmut Kaiser
2
//
3
//  SPDX-License-Identifier: BSL-1.0
4
//  Distributed under the Boost Software License, Version 1.0. (See accompanying
5
//  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6

7
#include <hpx/config.hpp>
8
#if !defined(HPX_COMPUTE_DEVICE_CODE)
9
#include <hpx/hpx_init.hpp>
10
#include <hpx/include/actions.hpp>
11
#include <hpx/include/async.hpp>
12
#include <hpx/include/components.hpp>
13
#include <hpx/include/lcos.hpp>
14
#include <hpx/include/runtime.hpp>
15
#include <hpx/modules/testing.hpp>
16

17
#include <atomic>
18
#include <chrono>
19
#include <cstdint>
20
#include <system_error>
21
#include <vector>
22

23
///////////////////////////////////////////////////////////////////////////////
24
struct decrement_server
4✔
25
  : hpx::components::managed_component_base<decrement_server>
26
{
27
    std::int32_t call(std::int32_t i) const
4✔
28
    {
29
        return i - 1;
4✔
30
    }
31

32
    HPX_DEFINE_COMPONENT_ACTION(decrement_server, call)
33
};
34

35
typedef hpx::components::managed_component<decrement_server> server_type;
36
HPX_REGISTER_COMPONENT(server_type, decrement_server)
45✔
37

38
typedef decrement_server::call_action call_action;
39
HPX_REGISTER_ACTION_DECLARATION(call_action)
40
HPX_REGISTER_ACTION(call_action)
7✔
41

42
///////////////////////////////////////////////////////////////////////////////
43
std::atomic<int> callback_called(0);
44

45
#if defined(HPX_HAVE_NETWORKING)
46
void cb(std::error_code const&, hpx::parcelset::parcel const&)
×
47
{
48
    ++callback_called;
×
49
}
×
50
#else
51
void cb()
52
{
53
    ++callback_called;
54
}
55
#endif
56

57
///////////////////////////////////////////////////////////////////////////////
58
void test_remote_async_cb(hpx::id_type const& target)
×
59
{
60
    typedef hpx::components::client<decrement_server> decrement_client;
61

62
    {
63
        decrement_client dec_f =
64
            hpx::components::new_<decrement_client>(target);
×
65

66
        call_action call;
67

68
        callback_called.store(0);
×
69
        hpx::future<std::int32_t> f1 = hpx::async_cb(call, dec_f, &cb, 42);
×
70
        HPX_TEST_EQ(f1.get(), 41);
×
71

72
        hpx::future<std::int32_t> f2 =
73
            hpx::async_cb(hpx::launch::all, call, dec_f, &cb, 42);
×
74
        HPX_TEST_EQ(f2.get(), 41);
×
75

76
        // The callback should have been called 2 times. wait for a short period
77
        // of time, to allow it for it to be fully executed
78
        hpx::this_thread::sleep_for(std::chrono::milliseconds(100));
×
79
        HPX_TEST_EQ(callback_called.load(), 2);
×
80
    }
×
81

82
    {
83
        decrement_client dec_f =
84
            hpx::components::new_<decrement_client>(target);
×
85
        hpx::id_type dec = dec_f.get_id();
×
86

87
        callback_called.store(0);
×
88
        hpx::future<std::int32_t> f1 =
89
            hpx::async_cb<call_action>(dec_f, &cb, 42);
×
90
        HPX_TEST_EQ(f1.get(), 41);
×
91

92
        hpx::future<std::int32_t> f2 =
93
            hpx::async_cb<call_action>(hpx::launch::all, dec_f, &cb, 42);
×
94
        HPX_TEST_EQ(f2.get(), 41);
×
95

96
        // The callback should have been called 2 times. wait for a short period
97
        // of time, to allow it for it to be fully executed
98
        hpx::this_thread::sleep_for(std::chrono::milliseconds(100));
×
99
        HPX_TEST_EQ(callback_called.load(), 2);
×
100
    }
×
101
}
×
102

103
int hpx_main()
×
104
{
105
    std::vector<hpx::id_type> localities = hpx::find_all_localities();
×
106
    for (hpx::id_type const& id : localities)
×
107
    {
108
        test_remote_async_cb(id);
×
109
    }
110
    return hpx::finalize();
×
111
}
×
112

113
int main(int argc, char* argv[])
1✔
114
{
115
    // Initialize and run HPX
116
    HPX_TEST_EQ_MSG(
1✔
117
        hpx::init(argc, argv), 0, "HPX main exited with non-zero status");
118

119
    return hpx::util::report_errors();
1✔
120
}
×
121
#endif
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc