aboutsummaryrefslogtreecommitdiffstats
path: root/fnet/src/tests/sync_execute/sync_execute.cpp
blob: 1b7c6c9ab6e60cea8061a3e421a351c2a56ccf3b (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include <vespa/vespalib/testkit/test_kit.h>
#include <vespa/vespalib/util/gate.h>
#include <vespa/vespalib/util/size_literals.h>
#include <vespa/fnet/transport.h>
#include <vespa/fnet/iexecutable.h>

struct DoIt : public FNET_IExecutable {
    vespalib::Gate gate;
    void execute() override {
        gate.countDown();
    }
};

TEST("sync execute") {
    DoIt exe1;
    DoIt exe2;
    DoIt exe3;
    DoIt exe4;
    DoIt exe5;
    DoIt exe6;
    FNET_Transport transport;
    ASSERT_TRUE(transport.execute(&exe1));
    ASSERT_TRUE(transport.Start());
    exe1.gate.await();
    ASSERT_TRUE(transport.execute(&exe2));
    transport.sync();
    ASSERT_TRUE(exe2.gate.getCount() == 0u);
    ASSERT_TRUE(transport.execute(&exe3));
    transport.ShutDown(false);
    uint32_t expect_cnt_4 = transport.execute(&exe4) ? 0 : 1;
    transport.sync();
    transport.WaitFinished();
    ASSERT_TRUE(!transport.execute(&exe5));
    transport.sync();
    ASSERT_TRUE(exe1.gate.getCount() == 0u);
    ASSERT_TRUE(exe2.gate.getCount() == 0u);
    ASSERT_TRUE(exe3.gate.getCount() == 0u);
    ASSERT_TRUE(exe4.gate.getCount() == expect_cnt_4);
    ASSERT_TRUE(exe5.gate.getCount() == 1u);
}

TEST_MAIN() { TEST_RUN_ALL(); }