MCPcopy Create free account
hub / github.com/apache/mesos / TEST

Function TEST

3rdparty/libprocess/src/tests/state_machine_tests.cpp:42–108  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

40
41
42TEST(StateMachineTest, Transition)
43{
44 StateMachine<State> state(State::INITIAL);
45
46 Try<int> i = state.transition<State::INITIAL, State::STARTING>(
47 []() {
48 return 42;
49 });
50
51 EXPECT_SOME_EQ(42, i);
52
53 Try<Nothing> error = state.transition<State::INITIAL, State::STARTING>();
54
55 EXPECT_ERROR(error);
56
57 Try<Try<int>> t = state.transition<State::STARTING, State::RUNNING>(
58 []() -> Try<int> {
59 return 42;
60 });
61
62 ASSERT_SOME(t);
63 EXPECT_SOME_EQ(42, t.get());
64
65 error = state.transition<State::STARTING, State::RUNNING>();
66
67 EXPECT_ERROR(error);
68
69 t = state.transition<State::RUNNING, State::STOPPING>(
70 []() -> Try<int> {
71 return Error("Error");
72 });
73
74 ASSERT_SOME(t);
75 ASSERT_ERROR(t.get());
76 EXPECT_EQ("Error", t->error());
77
78 error = state.transition<State::RUNNING, State::STOPPING>();
79
80 EXPECT_ERROR(error);
81
82 Promise<int> promise;
83
84 Try<Future<int>> f = state.transition<State::STOPPING, State::STOPPED>(
85 [&]() -> Future<int> {
86 return promise.future();
87 });
88
89 ASSERT_SOME(f);
90 EXPECT_TRUE(f->isPending());
91
92 promise.set(42);
93
94 AWAIT_EXPECT_EQ(42, f.get());
95
96 error = state.transition<State::STOPPING, State::STOPPED>();
97
98 EXPECT_ERROR(error);
99

Callers

nothing calls this directly

Calls 9

FailureClass · 0.85
isFailedMethod · 0.80
failureMethod · 0.80
errorMethod · 0.65
ErrorClass · 0.50
getMethod · 0.45
futureMethod · 0.45
isPendingMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected