blob: b9dd8af3a431b4c918c28080eca83e384e2cb108 [file] [log] [blame]
Tomáš Pecka261c8862020-11-05 11:23:08 +01001/*
2 * Copyright (C) 2020 CESNET, https://photonics.cesnet.cz/
3 *
4 * Written by Tomáš Pecka <tomas.pecka@fit.cvut.cz>
5 *
6*/
7
8#include "trompeloeil_doctest.h"
Tomáš Pecka261c8862020-11-05 11:23:08 +01009#include "health/manager/StateManager.h"
Tomáš Pecka339bc672020-11-11 15:59:03 +010010#include "mock/health.h"
Tomáš Pecka261c8862020-11-05 11:23:08 +010011#include "test_log_setup.h"
12
13TEST_CASE("State multiplexer")
14{
15 TEST_INIT_LOGS;
16 trompeloeil::sequence seq1;
17
18 auto mx = std::make_shared<velia::health::StateManager>();
19 auto o1 = std::make_shared<FakeOutput>();
20 mx->m_outputSignal.connect([&](const velia::health::State state) { o1->update(state); });
21
22 SECTION("One input")
23 {
24 REQUIRE_STATE_OUTPUT(OK);
25 auto i1 = std::make_shared<ManuallyInvokableInput>(mx);
26
27 SECTION("Nothing happens")
28 {
29 }
30
31 SECTION("State changes")
32 {
33 REQUIRE_STATE_OUTPUT(ERROR);
34 i1->invokeChangeState(velia::health::State::ERROR);
35
36 REQUIRE_STATE_OUTPUT(OK);
37 i1->invokeChangeState(velia::health::State::OK);
38 }
39 }
40
41 SECTION("Multiple inputs")
42 {
43 REQUIRE_STATE_OUTPUT(OK);
44 auto i1 = std::make_shared<ManuallyInvokableInput>(mx);
45
46 auto i2 = std::make_shared<ManuallyInvokableInput>(mx);
47
48 SECTION("Nothing happens")
49 {
50 }
51
52 SECTION("State changes")
53 {
54 i1->invokeChangeState(velia::health::State::OK); // [OK, OK]
55
56 i2->invokeChangeState(velia::health::State::OK); // [OK, OK]
57
58 {
59 REQUIRE_STATE_OUTPUT(ERROR);
60 i1->invokeChangeState(velia::health::State::ERROR); // [ERROR, OK]
61 }
62
63 {
64 REQUIRE_STATE_OUTPUT(WARNING);
65 i1->invokeChangeState(velia::health::State::WARNING); // [WARNING, OK]
66 }
67
68 i2->invokeChangeState(velia::health::State::OK); // [WARNING, OK]
69
70 {
71 REQUIRE_STATE_OUTPUT(OK);
72 i1->invokeChangeState(velia::health::State::OK); // [OK, OK]
73 }
74
75 {
76 REQUIRE_STATE_OUTPUT(ERROR);
77 i2->invokeChangeState(velia::health::State::ERROR); // [OK, ERROR]
78 }
79
80 {
81 REQUIRE_STATE_OUTPUT(WARNING);
82 i2->invokeChangeState(velia::health::State::WARNING); // [OK, WARNING]
83 }
84
85 i1->invokeChangeState(velia::health::State::WARNING); // [WARNING, WARNING]
86
87 {
88 REQUIRE_STATE_OUTPUT(ERROR);
89 i2->invokeChangeState(velia::health::State::ERROR); // [WARNING, ERROR]
90 }
91
92 {
93 REQUIRE_STATE_OUTPUT(WARNING);
94 i2->invokeChangeState(velia::health::State::WARNING); // [WARNING, WARNING]
95 }
96
97 i1->invokeChangeState(velia::health::State::OK); // [OK, WARNING]
98
99 {
100 REQUIRE_STATE_OUTPUT(OK);
101 i2->invokeChangeState(velia::health::State::OK); // [OK, OK]
102 }
103
104 i1.reset(); // [OK]
105 i2.reset(); // [], but no update because there's nothing new to report
106
107 {
108 REQUIRE_STATE_OUTPUT(OK);
109 i1 = std::make_shared<ManuallyInvokableInput>(mx); // [OK]
110 }
111
112 i1.reset(); // []
113 }
114 }
115}