aboutsummaryrefslogtreecommitdiffstats
path: root/messagebus/src/tests/messenger/messenger.cpp
blob: acd4406a7dc5b611633b643c21d638b55372d58c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include <vespa/messagebus/messenger.h>
#include <vespa/vespalib/util/barrier.h>
#include <vespa/vespalib/testkit/testapp.h>

using namespace mbus;

class ThrowException : public Messenger::ITask {
public:
    void run() override {
        throw std::exception();
    }

    uint8_t priority() const override {
        return 0;
    }
};

class BarrierTask : public Messenger::ITask {
private:
    vespalib::Barrier &_barrier;

public:
    BarrierTask(vespalib::Barrier &barrier)
        : _barrier(barrier)
    {
        // empty
    }

    void run() override {
        _barrier.await();
    }

    uint8_t priority() const override {
        return 0;
    }
};

TEST("messenger_test") {

    Messenger msn;
    msn.start();

    vespalib::Barrier barrier(2);
    msn.enqueue(std::make_unique<ThrowException>());
    msn.enqueue(std::make_unique<BarrierTask>(barrier));

    barrier.await();
    ASSERT_TRUE(msn.isEmpty());
}

TEST_MAIN() { TEST_RUN_ALL(); }