| Alex Deymo | aea4c1c | 2015-08-19 20:24:43 -0700 | [diff] [blame] | 1 | // | 
|  | 2 | // Copyright (C) 2009 The Android Open Source Project | 
|  | 3 | // | 
|  | 4 | // Licensed under the Apache License, Version 2.0 (the "License"); | 
|  | 5 | // you may not use this file except in compliance with the License. | 
|  | 6 | // You may obtain a copy of the License at | 
|  | 7 | // | 
|  | 8 | //      http://www.apache.org/licenses/LICENSE-2.0 | 
|  | 9 | // | 
|  | 10 | // Unless required by applicable law or agreed to in writing, software | 
|  | 11 | // distributed under the License is distributed on an "AS IS" BASIS, | 
|  | 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
|  | 13 | // See the License for the specific language governing permissions and | 
|  | 14 | // limitations under the License. | 
|  | 15 | // | 
| rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 16 |  | 
| Alex Deymo | 39910dc | 2015-11-09 17:04:30 -0800 | [diff] [blame] | 17 | #include "update_engine/common/action_processor.h" | 
| Alex Deymo | aab50e3 | 2014-11-10 19:55:35 -0800 | [diff] [blame] | 18 |  | 
| Alex Deymo | 39910dc | 2015-11-09 17:04:30 -0800 | [diff] [blame] | 19 | #include <string> | 
| Amin Hassani | d3f4bea | 2018-04-30 14:52:40 -0700 | [diff] [blame] | 20 | #include <utility> | 
| Alex Deymo | 14fd1ec | 2016-02-24 22:03:57 -0800 | [diff] [blame] | 21 |  | 
|  | 22 | #include <gtest/gtest.h> | 
|  | 23 |  | 
| Alex Deymo | 39910dc | 2015-11-09 17:04:30 -0800 | [diff] [blame] | 24 | #include "update_engine/common/action.h" | 
| Alex Deymo | 14fd1ec | 2016-02-24 22:03:57 -0800 | [diff] [blame] | 25 | #include "update_engine/common/mock_action.h" | 
| rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 26 |  | 
| Andrew de los Reyes | 4fe15d0 | 2009-12-10 19:01:36 -0800 | [diff] [blame] | 27 | using std::string; | 
|  | 28 |  | 
| rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 29 | namespace chromeos_update_engine { | 
|  | 30 |  | 
|  | 31 | using chromeos_update_engine::ActionPipe; | 
|  | 32 |  | 
|  | 33 | class ActionProcessorTestAction; | 
|  | 34 |  | 
| Amin Hassani | b268959 | 2019-01-13 17:04:28 -0800 | [diff] [blame] | 35 | template <> | 
| rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 36 | class ActionTraits<ActionProcessorTestAction> { | 
|  | 37 | public: | 
|  | 38 | typedef string OutputObjectType; | 
|  | 39 | typedef string InputObjectType; | 
|  | 40 | }; | 
|  | 41 |  | 
|  | 42 | // This is a simple Action class for testing. | 
| Yunlian Jiang | a178e5e | 2013-04-05 14:41:56 -0700 | [diff] [blame] | 43 | class ActionProcessorTestAction : public Action<ActionProcessorTestAction> { | 
|  | 44 | public: | 
| rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 45 | typedef string InputObjectType; | 
|  | 46 | typedef string OutputObjectType; | 
|  | 47 | ActionPipe<string>* in_pipe() { return in_pipe_.get(); } | 
|  | 48 | ActionPipe<string>* out_pipe() { return out_pipe_.get(); } | 
|  | 49 | ActionProcessor* processor() { return processor_; } | 
|  | 50 | void PerformAction() {} | 
|  | 51 | void CompleteAction() { | 
|  | 52 | ASSERT_TRUE(processor()); | 
| Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 53 | processor()->ActionComplete(this, ErrorCode::kSuccess); | 
| rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 54 | } | 
|  | 55 | string Type() const { return "ActionProcessorTestAction"; } | 
|  | 56 | }; | 
|  | 57 |  | 
| rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 58 | namespace { | 
|  | 59 | class MyActionProcessorDelegate : public ActionProcessorDelegate { | 
|  | 60 | public: | 
|  | 61 | explicit MyActionProcessorDelegate(const ActionProcessor* processor) | 
| Andrew de los Reyes | 3270f74 | 2010-07-15 22:28:14 -0700 | [diff] [blame] | 62 | : processor_(processor), | 
|  | 63 | processing_done_called_(false), | 
|  | 64 | processing_stopped_called_(false), | 
|  | 65 | action_completed_called_(false), | 
| Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 66 | action_exit_code_(ErrorCode::kError) {} | 
| rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 67 |  | 
| Darin Petkov | c1a8b42 | 2010-07-19 11:34:49 -0700 | [diff] [blame] | 68 | virtual void ProcessingDone(const ActionProcessor* processor, | 
| David Zeuthen | a99981f | 2013-04-29 13:42:47 -0700 | [diff] [blame] | 69 | ErrorCode code) { | 
| rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 70 | EXPECT_EQ(processor_, processor); | 
|  | 71 | EXPECT_FALSE(processing_done_called_); | 
|  | 72 | processing_done_called_ = true; | 
|  | 73 | } | 
|  | 74 | virtual void ProcessingStopped(const ActionProcessor* processor) { | 
|  | 75 | EXPECT_EQ(processor_, processor); | 
|  | 76 | EXPECT_FALSE(processing_stopped_called_); | 
|  | 77 | processing_stopped_called_ = true; | 
|  | 78 | } | 
| adlr@google.com | c98a7ed | 2009-12-04 18:54:03 +0000 | [diff] [blame] | 79 | virtual void ActionCompleted(ActionProcessor* processor, | 
|  | 80 | AbstractAction* action, | 
| David Zeuthen | a99981f | 2013-04-29 13:42:47 -0700 | [diff] [blame] | 81 | ErrorCode code) { | 
| rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 82 | EXPECT_EQ(processor_, processor); | 
|  | 83 | EXPECT_FALSE(action_completed_called_); | 
|  | 84 | action_completed_called_ = true; | 
| Darin Petkov | c1a8b42 | 2010-07-19 11:34:49 -0700 | [diff] [blame] | 85 | action_exit_code_ = code; | 
| rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 86 | } | 
|  | 87 |  | 
|  | 88 | const ActionProcessor* processor_; | 
|  | 89 | bool processing_done_called_; | 
|  | 90 | bool processing_stopped_called_; | 
|  | 91 | bool action_completed_called_; | 
| David Zeuthen | a99981f | 2013-04-29 13:42:47 -0700 | [diff] [blame] | 92 | ErrorCode action_exit_code_; | 
| rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 93 | }; | 
| Alex Vakulenko | d2779df | 2014-06-16 13:19:00 -0700 | [diff] [blame] | 94 | }  // namespace | 
| rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 95 |  | 
| Alex Deymo | 14fd1ec | 2016-02-24 22:03:57 -0800 | [diff] [blame] | 96 | class ActionProcessorTest : public ::testing::Test { | 
|  | 97 | void SetUp() override { | 
|  | 98 | action_processor_.set_delegate(&delegate_); | 
|  | 99 | // Silence Type() calls used for logging. | 
| Amin Hassani | d3f4bea | 2018-04-30 14:52:40 -0700 | [diff] [blame] | 100 | mock_action_.reset(new testing::StrictMock<MockAction>()); | 
|  | 101 | mock_action_ptr_ = mock_action_.get(); | 
|  | 102 | action_.reset(new ActionProcessorTestAction()); | 
|  | 103 | action_ptr_ = action_.get(); | 
|  | 104 | EXPECT_CALL(*mock_action_, Type()).Times(testing::AnyNumber()); | 
| Alex Deymo | 14fd1ec | 2016-02-24 22:03:57 -0800 | [diff] [blame] | 105 | } | 
| rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 106 |  | 
| Amin Hassani | b268959 | 2019-01-13 17:04:28 -0800 | [diff] [blame] | 107 | void TearDown() override { action_processor_.set_delegate(nullptr); } | 
| Alex Deymo | 14fd1ec | 2016-02-24 22:03:57 -0800 | [diff] [blame] | 108 |  | 
|  | 109 | protected: | 
|  | 110 | // The ActionProcessor under test. | 
|  | 111 | ActionProcessor action_processor_; | 
|  | 112 |  | 
|  | 113 | MyActionProcessorDelegate delegate_{&action_processor_}; | 
|  | 114 |  | 
|  | 115 | // Common actions used during most tests. | 
| Amin Hassani | d3f4bea | 2018-04-30 14:52:40 -0700 | [diff] [blame] | 116 | std::unique_ptr<testing::StrictMock<MockAction>> mock_action_; | 
|  | 117 | testing::StrictMock<MockAction>* mock_action_ptr_; | 
|  | 118 | std::unique_ptr<ActionProcessorTestAction> action_; | 
|  | 119 | ActionProcessorTestAction* action_ptr_; | 
| Alex Deymo | 14fd1ec | 2016-02-24 22:03:57 -0800 | [diff] [blame] | 120 | }; | 
|  | 121 |  | 
|  | 122 | TEST_F(ActionProcessorTest, SimpleTest) { | 
|  | 123 | EXPECT_FALSE(action_processor_.IsRunning()); | 
| Amin Hassani | d3f4bea | 2018-04-30 14:52:40 -0700 | [diff] [blame] | 124 | action_processor_.EnqueueAction(std::move(action_)); | 
| Alex Deymo | 14fd1ec | 2016-02-24 22:03:57 -0800 | [diff] [blame] | 125 | EXPECT_FALSE(action_processor_.IsRunning()); | 
| Amin Hassani | d3f4bea | 2018-04-30 14:52:40 -0700 | [diff] [blame] | 126 | EXPECT_FALSE(action_ptr_->IsRunning()); | 
| Alex Deymo | 14fd1ec | 2016-02-24 22:03:57 -0800 | [diff] [blame] | 127 | action_processor_.StartProcessing(); | 
|  | 128 | EXPECT_TRUE(action_processor_.IsRunning()); | 
| Amin Hassani | d3f4bea | 2018-04-30 14:52:40 -0700 | [diff] [blame] | 129 | EXPECT_TRUE(action_ptr_->IsRunning()); | 
|  | 130 | action_ptr_->CompleteAction(); | 
| Alex Deymo | 14fd1ec | 2016-02-24 22:03:57 -0800 | [diff] [blame] | 131 | EXPECT_FALSE(action_processor_.IsRunning()); | 
| Amin Hassani | d3f4bea | 2018-04-30 14:52:40 -0700 | [diff] [blame] | 132 | EXPECT_EQ(action_processor_.current_action(), nullptr); | 
| rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 133 | } | 
|  | 134 |  | 
| Alex Deymo | 14fd1ec | 2016-02-24 22:03:57 -0800 | [diff] [blame] | 135 | TEST_F(ActionProcessorTest, DelegateTest) { | 
| Amin Hassani | d3f4bea | 2018-04-30 14:52:40 -0700 | [diff] [blame] | 136 | action_processor_.EnqueueAction(std::move(action_)); | 
| Alex Deymo | 14fd1ec | 2016-02-24 22:03:57 -0800 | [diff] [blame] | 137 | action_processor_.StartProcessing(); | 
| Amin Hassani | d3f4bea | 2018-04-30 14:52:40 -0700 | [diff] [blame] | 138 | action_ptr_->CompleteAction(); | 
| Alex Deymo | 14fd1ec | 2016-02-24 22:03:57 -0800 | [diff] [blame] | 139 | EXPECT_TRUE(delegate_.processing_done_called_); | 
|  | 140 | EXPECT_TRUE(delegate_.action_completed_called_); | 
| rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 141 | } | 
|  | 142 |  | 
| Alex Deymo | 14fd1ec | 2016-02-24 22:03:57 -0800 | [diff] [blame] | 143 | TEST_F(ActionProcessorTest, StopProcessingTest) { | 
| Amin Hassani | d3f4bea | 2018-04-30 14:52:40 -0700 | [diff] [blame] | 144 | action_processor_.EnqueueAction(std::move(action_)); | 
| Alex Deymo | 14fd1ec | 2016-02-24 22:03:57 -0800 | [diff] [blame] | 145 | action_processor_.StartProcessing(); | 
|  | 146 | action_processor_.StopProcessing(); | 
|  | 147 | EXPECT_TRUE(delegate_.processing_stopped_called_); | 
|  | 148 | EXPECT_FALSE(delegate_.action_completed_called_); | 
|  | 149 | EXPECT_FALSE(action_processor_.IsRunning()); | 
|  | 150 | EXPECT_EQ(nullptr, action_processor_.current_action()); | 
|  | 151 | } | 
|  | 152 |  | 
|  | 153 | TEST_F(ActionProcessorTest, ChainActionsTest) { | 
|  | 154 | // This test doesn't use a delegate since it terminates several actions. | 
|  | 155 | action_processor_.set_delegate(nullptr); | 
|  | 156 |  | 
| Amin Hassani | d3f4bea | 2018-04-30 14:52:40 -0700 | [diff] [blame] | 157 | auto action0 = std::make_unique<ActionProcessorTestAction>(); | 
|  | 158 | auto action1 = std::make_unique<ActionProcessorTestAction>(); | 
|  | 159 | auto action2 = std::make_unique<ActionProcessorTestAction>(); | 
|  | 160 | auto action0_ptr = action0.get(); | 
|  | 161 | auto action1_ptr = action1.get(); | 
|  | 162 | auto action2_ptr = action2.get(); | 
|  | 163 | action_processor_.EnqueueAction(std::move(action0)); | 
|  | 164 | action_processor_.EnqueueAction(std::move(action1)); | 
|  | 165 | action_processor_.EnqueueAction(std::move(action2)); | 
|  | 166 |  | 
| Amin Hassani | 667cf7b | 2018-07-25 14:32:00 -0700 | [diff] [blame] | 167 | EXPECT_EQ(action_processor_.actions_.size(), 3u); | 
| Amin Hassani | d3f4bea | 2018-04-30 14:52:40 -0700 | [diff] [blame] | 168 | EXPECT_EQ(action_processor_.actions_[0].get(), action0_ptr); | 
|  | 169 | EXPECT_EQ(action_processor_.actions_[1].get(), action1_ptr); | 
|  | 170 | EXPECT_EQ(action_processor_.actions_[2].get(), action2_ptr); | 
|  | 171 |  | 
| Alex Deymo | 14fd1ec | 2016-02-24 22:03:57 -0800 | [diff] [blame] | 172 | action_processor_.StartProcessing(); | 
| Amin Hassani | d3f4bea | 2018-04-30 14:52:40 -0700 | [diff] [blame] | 173 | EXPECT_EQ(action0_ptr, action_processor_.current_action()); | 
| Alex Deymo | 14fd1ec | 2016-02-24 22:03:57 -0800 | [diff] [blame] | 174 | EXPECT_TRUE(action_processor_.IsRunning()); | 
| Amin Hassani | d3f4bea | 2018-04-30 14:52:40 -0700 | [diff] [blame] | 175 | action0_ptr->CompleteAction(); | 
|  | 176 | EXPECT_EQ(action1_ptr, action_processor_.current_action()); | 
| Alex Deymo | 14fd1ec | 2016-02-24 22:03:57 -0800 | [diff] [blame] | 177 | EXPECT_TRUE(action_processor_.IsRunning()); | 
| Amin Hassani | d3f4bea | 2018-04-30 14:52:40 -0700 | [diff] [blame] | 178 | action1_ptr->CompleteAction(); | 
|  | 179 | EXPECT_EQ(action2_ptr, action_processor_.current_action()); | 
|  | 180 | EXPECT_TRUE(action_processor_.actions_.empty()); | 
|  | 181 | EXPECT_TRUE(action_processor_.IsRunning()); | 
|  | 182 | action2_ptr->CompleteAction(); | 
| Alex Deymo | 14fd1ec | 2016-02-24 22:03:57 -0800 | [diff] [blame] | 183 | EXPECT_EQ(nullptr, action_processor_.current_action()); | 
| Amin Hassani | d3f4bea | 2018-04-30 14:52:40 -0700 | [diff] [blame] | 184 | EXPECT_TRUE(action_processor_.actions_.empty()); | 
| Alex Deymo | 14fd1ec | 2016-02-24 22:03:57 -0800 | [diff] [blame] | 185 | EXPECT_FALSE(action_processor_.IsRunning()); | 
| rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 186 | } | 
|  | 187 |  | 
| Alex Deymo | 14fd1ec | 2016-02-24 22:03:57 -0800 | [diff] [blame] | 188 | TEST_F(ActionProcessorTest, DefaultDelegateTest) { | 
| Amin Hassani | d3f4bea | 2018-04-30 14:52:40 -0700 | [diff] [blame] | 189 | // Just make sure it doesn't crash. | 
|  | 190 | action_processor_.EnqueueAction(std::move(action_)); | 
| Alex Deymo | 14fd1ec | 2016-02-24 22:03:57 -0800 | [diff] [blame] | 191 | action_processor_.StartProcessing(); | 
| Amin Hassani | d3f4bea | 2018-04-30 14:52:40 -0700 | [diff] [blame] | 192 | action_ptr_->CompleteAction(); | 
| rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 193 |  | 
| Amin Hassani | d3f4bea | 2018-04-30 14:52:40 -0700 | [diff] [blame] | 194 | action_.reset(new ActionProcessorTestAction()); | 
|  | 195 | action_processor_.EnqueueAction(std::move(action_)); | 
| Alex Deymo | 14fd1ec | 2016-02-24 22:03:57 -0800 | [diff] [blame] | 196 | action_processor_.StartProcessing(); | 
|  | 197 | action_processor_.StopProcessing(); | 
|  | 198 | } | 
| rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 199 |  | 
| Amin Hassani | d3f4bea | 2018-04-30 14:52:40 -0700 | [diff] [blame] | 200 | // This test suspends and resume the action processor while running one action. | 
| Alex Deymo | 14fd1ec | 2016-02-24 22:03:57 -0800 | [diff] [blame] | 201 | TEST_F(ActionProcessorTest, SuspendResumeTest) { | 
| Amin Hassani | d3f4bea | 2018-04-30 14:52:40 -0700 | [diff] [blame] | 202 | action_processor_.EnqueueAction(std::move(mock_action_)); | 
| rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 203 |  | 
| Alex Deymo | 14fd1ec | 2016-02-24 22:03:57 -0800 | [diff] [blame] | 204 | testing::InSequence s; | 
| Amin Hassani | d3f4bea | 2018-04-30 14:52:40 -0700 | [diff] [blame] | 205 | EXPECT_CALL(*mock_action_ptr_, PerformAction()); | 
| Alex Deymo | 14fd1ec | 2016-02-24 22:03:57 -0800 | [diff] [blame] | 206 | action_processor_.StartProcessing(); | 
|  | 207 |  | 
| Amin Hassani | d3f4bea | 2018-04-30 14:52:40 -0700 | [diff] [blame] | 208 | EXPECT_CALL(*mock_action_ptr_, SuspendAction()); | 
| Alex Deymo | 14fd1ec | 2016-02-24 22:03:57 -0800 | [diff] [blame] | 209 | action_processor_.SuspendProcessing(); | 
|  | 210 | // Suspending the processor twice should not suspend the action twice. | 
|  | 211 | action_processor_.SuspendProcessing(); | 
|  | 212 |  | 
|  | 213 | // IsRunning should return whether there's is an action doing some work, even | 
|  | 214 | // if it is suspended. | 
|  | 215 | EXPECT_TRUE(action_processor_.IsRunning()); | 
| Amin Hassani | d3f4bea | 2018-04-30 14:52:40 -0700 | [diff] [blame] | 216 | EXPECT_EQ(mock_action_ptr_, action_processor_.current_action()); | 
| Alex Deymo | 14fd1ec | 2016-02-24 22:03:57 -0800 | [diff] [blame] | 217 |  | 
| Amin Hassani | d3f4bea | 2018-04-30 14:52:40 -0700 | [diff] [blame] | 218 | EXPECT_CALL(*mock_action_ptr_, ResumeAction()); | 
| Alex Deymo | 14fd1ec | 2016-02-24 22:03:57 -0800 | [diff] [blame] | 219 | action_processor_.ResumeProcessing(); | 
|  | 220 |  | 
|  | 221 | // Calling ResumeProcessing twice should not affect the action_. | 
|  | 222 | action_processor_.ResumeProcessing(); | 
| Amin Hassani | d3f4bea | 2018-04-30 14:52:40 -0700 | [diff] [blame] | 223 | action_processor_.ActionComplete(mock_action_ptr_, ErrorCode::kSuccess); | 
| Alex Deymo | 14fd1ec | 2016-02-24 22:03:57 -0800 | [diff] [blame] | 224 | } | 
|  | 225 |  | 
|  | 226 | // This test suspends an action that presumably doesn't support suspend/resume | 
|  | 227 | // and it finished before being resumed. | 
|  | 228 | TEST_F(ActionProcessorTest, ActionCompletedWhileSuspendedTest) { | 
| Amin Hassani | d3f4bea | 2018-04-30 14:52:40 -0700 | [diff] [blame] | 229 | action_processor_.EnqueueAction(std::move(mock_action_)); | 
| Alex Deymo | 14fd1ec | 2016-02-24 22:03:57 -0800 | [diff] [blame] | 230 |  | 
|  | 231 | testing::InSequence s; | 
| Amin Hassani | d3f4bea | 2018-04-30 14:52:40 -0700 | [diff] [blame] | 232 | EXPECT_CALL(*mock_action_ptr_, PerformAction()); | 
| Alex Deymo | 14fd1ec | 2016-02-24 22:03:57 -0800 | [diff] [blame] | 233 | action_processor_.StartProcessing(); | 
|  | 234 |  | 
| Amin Hassani | d3f4bea | 2018-04-30 14:52:40 -0700 | [diff] [blame] | 235 | EXPECT_CALL(*mock_action_ptr_, SuspendAction()); | 
| Alex Deymo | 14fd1ec | 2016-02-24 22:03:57 -0800 | [diff] [blame] | 236 | action_processor_.SuspendProcessing(); | 
|  | 237 |  | 
|  | 238 | // Simulate the action completion while suspended. No other call to | 
|  | 239 | // |mock_action_| is expected at this point. | 
| Amin Hassani | d3f4bea | 2018-04-30 14:52:40 -0700 | [diff] [blame] | 240 | action_processor_.ActionComplete(mock_action_ptr_, ErrorCode::kSuccess); | 
| Alex Deymo | 14fd1ec | 2016-02-24 22:03:57 -0800 | [diff] [blame] | 241 |  | 
|  | 242 | // The processing should not be done since the ActionProcessor is suspended | 
|  | 243 | // and the processing is considered to be still running until resumed. | 
|  | 244 | EXPECT_FALSE(delegate_.processing_done_called_); | 
|  | 245 | EXPECT_TRUE(action_processor_.IsRunning()); | 
|  | 246 |  | 
|  | 247 | action_processor_.ResumeProcessing(); | 
|  | 248 | EXPECT_TRUE(delegate_.processing_done_called_); | 
|  | 249 | EXPECT_FALSE(delegate_.processing_stopped_called_); | 
|  | 250 | } | 
|  | 251 |  | 
|  | 252 | TEST_F(ActionProcessorTest, StoppedWhileSuspendedTest) { | 
| Amin Hassani | d3f4bea | 2018-04-30 14:52:40 -0700 | [diff] [blame] | 253 | action_processor_.EnqueueAction(std::move(mock_action_)); | 
| Alex Deymo | 14fd1ec | 2016-02-24 22:03:57 -0800 | [diff] [blame] | 254 |  | 
|  | 255 | testing::InSequence s; | 
| Amin Hassani | d3f4bea | 2018-04-30 14:52:40 -0700 | [diff] [blame] | 256 | EXPECT_CALL(*mock_action_ptr_, PerformAction()); | 
| Alex Deymo | 14fd1ec | 2016-02-24 22:03:57 -0800 | [diff] [blame] | 257 | action_processor_.StartProcessing(); | 
| Amin Hassani | d3f4bea | 2018-04-30 14:52:40 -0700 | [diff] [blame] | 258 | EXPECT_CALL(*mock_action_ptr_, SuspendAction()); | 
| Alex Deymo | 14fd1ec | 2016-02-24 22:03:57 -0800 | [diff] [blame] | 259 | action_processor_.SuspendProcessing(); | 
|  | 260 |  | 
| Amin Hassani | d3f4bea | 2018-04-30 14:52:40 -0700 | [diff] [blame] | 261 | EXPECT_CALL(*mock_action_ptr_, TerminateProcessing()); | 
| Alex Deymo | 14fd1ec | 2016-02-24 22:03:57 -0800 | [diff] [blame] | 262 | action_processor_.StopProcessing(); | 
|  | 263 | // Stopping the processing should abort the current execution no matter what. | 
|  | 264 | EXPECT_TRUE(delegate_.processing_stopped_called_); | 
|  | 265 | EXPECT_FALSE(delegate_.processing_done_called_); | 
|  | 266 | EXPECT_FALSE(delegate_.action_completed_called_); | 
|  | 267 | EXPECT_FALSE(action_processor_.IsRunning()); | 
|  | 268 | EXPECT_EQ(nullptr, action_processor_.current_action()); | 
| rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 269 | } | 
|  | 270 |  | 
|  | 271 | }  // namespace chromeos_update_engine |