Ytai Ben-Tsvi | 1ea62c9 | 2021-11-10 14:38:27 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2021 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 | */ |
| 16 | |
| 17 | #include <chrono> |
| 18 | #include <thread> |
| 19 | #include <gtest/gtest.h> |
| 20 | #include <mediautils/TimerThread.h> |
| 21 | |
| 22 | using namespace std::chrono_literals; |
Andy Hung | a2a1ac3 | 2022-03-18 16:12:11 -0700 | [diff] [blame] | 23 | using namespace android::mediautils; |
Ytai Ben-Tsvi | 1ea62c9 | 2021-11-10 14:38:27 -0800 | [diff] [blame] | 24 | |
Ytai Ben-Tsvi | 1ea62c9 | 2021-11-10 14:38:27 -0800 | [diff] [blame] | 25 | namespace { |
| 26 | |
| 27 | constexpr auto kJitter = 10ms; |
| 28 | |
Andy Hung | a2a1ac3 | 2022-03-18 16:12:11 -0700 | [diff] [blame] | 29 | // Each task written by *ToString() will start with a left brace. |
| 30 | constexpr char REQUEST_START = '{'; |
| 31 | |
| 32 | inline size_t countChars(std::string_view s, char c) { |
| 33 | return std::count(s.begin(), s.end(), c); |
| 34 | } |
| 35 | |
Andy Hung | f8ab093 | 2022-06-13 19:49:43 -0700 | [diff] [blame] | 36 | |
| 37 | // Split msec time between timeout and second chance time |
| 38 | // This tests expiration times weighted between timeout and the second chance time. |
| 39 | #define DISTRIBUTE_TIMEOUT_SECONDCHANCE_MS_FRAC(msec, frac) \ |
| 40 | std::chrono::milliseconds(int((msec) * (frac)) + 1), \ |
| 41 | std::chrono::milliseconds(int((msec) * (1.f - (frac)))) |
| 42 | |
| 43 | // The TimerThreadTest is parameterized on a fraction between 0.f and 1.f which |
| 44 | // is how the total timeout time is split between the first timeout and the second chance time. |
| 45 | // |
| 46 | class TimerThreadTest : public ::testing::TestWithParam<float> { |
| 47 | protected: |
| 48 | |
| 49 | static void testBasic() { |
| 50 | const auto frac = GetParam(); |
| 51 | |
Ytai Ben-Tsvi | 1ea62c9 | 2021-11-10 14:38:27 -0800 | [diff] [blame] | 52 | std::atomic<bool> taskRan = false; |
| 53 | TimerThread thread; |
Andy Hung | 2aa1510 | 2022-06-13 19:49:43 -0700 | [diff] [blame] | 54 | TimerThread::Handle handle = |
Atneya Nair | f5b6851 | 2022-05-23 20:02:49 -0400 | [diff] [blame] | 55 | thread.scheduleTask("Basic", [&taskRan](TimerThread::Handle) { |
Andy Hung | f8ab093 | 2022-06-13 19:49:43 -0700 | [diff] [blame] | 56 | taskRan = true; }, DISTRIBUTE_TIMEOUT_SECONDCHANCE_MS_FRAC(100, frac)); |
Andy Hung | 2aa1510 | 2022-06-13 19:49:43 -0700 | [diff] [blame] | 57 | ASSERT_TRUE(TimerThread::isTimeoutHandle(handle)); |
Ytai Ben-Tsvi | 1ea62c9 | 2021-11-10 14:38:27 -0800 | [diff] [blame] | 58 | std::this_thread::sleep_for(100ms - kJitter); |
| 59 | ASSERT_FALSE(taskRan); |
| 60 | std::this_thread::sleep_for(2 * kJitter); |
Andy Hung | cb90d20 | 2022-05-23 18:19:42 -0700 | [diff] [blame] | 61 | ASSERT_TRUE(taskRan); // timed-out called. |
| 62 | ASSERT_EQ(1ul, countChars(thread.timeoutToString(), REQUEST_START)); |
| 63 | // nothing cancelled |
| 64 | ASSERT_EQ(0ul, countChars(thread.retiredToString(), REQUEST_START)); |
Ytai Ben-Tsvi | 1ea62c9 | 2021-11-10 14:38:27 -0800 | [diff] [blame] | 65 | } |
| 66 | |
Andy Hung | f8ab093 | 2022-06-13 19:49:43 -0700 | [diff] [blame] | 67 | static void testCancel() { |
| 68 | const auto frac = GetParam(); |
| 69 | |
Ytai Ben-Tsvi | 1ea62c9 | 2021-11-10 14:38:27 -0800 | [diff] [blame] | 70 | std::atomic<bool> taskRan = false; |
| 71 | TimerThread thread; |
Andy Hung | a2a1ac3 | 2022-03-18 16:12:11 -0700 | [diff] [blame] | 72 | TimerThread::Handle handle = |
Atneya Nair | f5b6851 | 2022-05-23 20:02:49 -0400 | [diff] [blame] | 73 | thread.scheduleTask("Cancel", [&taskRan](TimerThread::Handle) { |
Andy Hung | f8ab093 | 2022-06-13 19:49:43 -0700 | [diff] [blame] | 74 | taskRan = true; }, DISTRIBUTE_TIMEOUT_SECONDCHANCE_MS_FRAC(100, frac)); |
Andy Hung | 2aa1510 | 2022-06-13 19:49:43 -0700 | [diff] [blame] | 75 | ASSERT_TRUE(TimerThread::isTimeoutHandle(handle)); |
Ytai Ben-Tsvi | 1ea62c9 | 2021-11-10 14:38:27 -0800 | [diff] [blame] | 76 | std::this_thread::sleep_for(100ms - kJitter); |
| 77 | ASSERT_FALSE(taskRan); |
Andy Hung | a2a1ac3 | 2022-03-18 16:12:11 -0700 | [diff] [blame] | 78 | ASSERT_TRUE(thread.cancelTask(handle)); |
Ytai Ben-Tsvi | 1ea62c9 | 2021-11-10 14:38:27 -0800 | [diff] [blame] | 79 | std::this_thread::sleep_for(2 * kJitter); |
Andy Hung | cb90d20 | 2022-05-23 18:19:42 -0700 | [diff] [blame] | 80 | ASSERT_FALSE(taskRan); // timed-out did not call. |
| 81 | ASSERT_EQ(0ul, countChars(thread.timeoutToString(), REQUEST_START)); |
| 82 | // task cancelled. |
| 83 | ASSERT_EQ(1ul, countChars(thread.retiredToString(), REQUEST_START)); |
Ytai Ben-Tsvi | 1ea62c9 | 2021-11-10 14:38:27 -0800 | [diff] [blame] | 84 | } |
| 85 | |
Andy Hung | f8ab093 | 2022-06-13 19:49:43 -0700 | [diff] [blame] | 86 | static void testCancelAfterRun() { |
| 87 | const auto frac = GetParam(); |
| 88 | |
Ytai Ben-Tsvi | 1ea62c9 | 2021-11-10 14:38:27 -0800 | [diff] [blame] | 89 | std::atomic<bool> taskRan = false; |
| 90 | TimerThread thread; |
Andy Hung | a2a1ac3 | 2022-03-18 16:12:11 -0700 | [diff] [blame] | 91 | TimerThread::Handle handle = |
Andy Hung | 2aa1510 | 2022-06-13 19:49:43 -0700 | [diff] [blame] | 92 | thread.scheduleTask("CancelAfterRun", |
Atneya Nair | f5b6851 | 2022-05-23 20:02:49 -0400 | [diff] [blame] | 93 | [&taskRan](TimerThread::Handle) { |
Andy Hung | f8ab093 | 2022-06-13 19:49:43 -0700 | [diff] [blame] | 94 | taskRan = true; }, |
| 95 | DISTRIBUTE_TIMEOUT_SECONDCHANCE_MS_FRAC(100, frac)); |
Andy Hung | 2aa1510 | 2022-06-13 19:49:43 -0700 | [diff] [blame] | 96 | ASSERT_TRUE(TimerThread::isTimeoutHandle(handle)); |
Ytai Ben-Tsvi | 1ea62c9 | 2021-11-10 14:38:27 -0800 | [diff] [blame] | 97 | std::this_thread::sleep_for(100ms + kJitter); |
Andy Hung | cb90d20 | 2022-05-23 18:19:42 -0700 | [diff] [blame] | 98 | ASSERT_TRUE(taskRan); // timed-out called. |
Andy Hung | a2a1ac3 | 2022-03-18 16:12:11 -0700 | [diff] [blame] | 99 | ASSERT_FALSE(thread.cancelTask(handle)); |
Andy Hung | cb90d20 | 2022-05-23 18:19:42 -0700 | [diff] [blame] | 100 | ASSERT_EQ(1ul, countChars(thread.timeoutToString(), REQUEST_START)); |
| 101 | // nothing actually cancelled |
| 102 | ASSERT_EQ(0ul, countChars(thread.retiredToString(), REQUEST_START)); |
Ytai Ben-Tsvi | 1ea62c9 | 2021-11-10 14:38:27 -0800 | [diff] [blame] | 103 | } |
| 104 | |
Andy Hung | f8ab093 | 2022-06-13 19:49:43 -0700 | [diff] [blame] | 105 | static void testMultipleTasks() { |
| 106 | const auto frac = GetParam(); |
| 107 | |
Andy Hung | a2a1ac3 | 2022-03-18 16:12:11 -0700 | [diff] [blame] | 108 | std::array<std::atomic<bool>, 6> taskRan{}; |
Ytai Ben-Tsvi | 1ea62c9 | 2021-11-10 14:38:27 -0800 | [diff] [blame] | 109 | TimerThread thread; |
| 110 | |
| 111 | auto startTime = std::chrono::steady_clock::now(); |
| 112 | |
Atneya Nair | f5b6851 | 2022-05-23 20:02:49 -0400 | [diff] [blame] | 113 | thread.scheduleTask("0", [&taskRan](TimerThread::Handle) { |
Andy Hung | f8ab093 | 2022-06-13 19:49:43 -0700 | [diff] [blame] | 114 | taskRan[0] = true; }, DISTRIBUTE_TIMEOUT_SECONDCHANCE_MS_FRAC(300, frac)); |
Atneya Nair | f5b6851 | 2022-05-23 20:02:49 -0400 | [diff] [blame] | 115 | thread.scheduleTask("1", [&taskRan](TimerThread::Handle) { |
Andy Hung | f8ab093 | 2022-06-13 19:49:43 -0700 | [diff] [blame] | 116 | taskRan[1] = true; }, DISTRIBUTE_TIMEOUT_SECONDCHANCE_MS_FRAC(100, frac)); |
Atneya Nair | f5b6851 | 2022-05-23 20:02:49 -0400 | [diff] [blame] | 117 | thread.scheduleTask("2", [&taskRan](TimerThread::Handle) { |
Andy Hung | f8ab093 | 2022-06-13 19:49:43 -0700 | [diff] [blame] | 118 | taskRan[2] = true; }, DISTRIBUTE_TIMEOUT_SECONDCHANCE_MS_FRAC(200, frac)); |
Atneya Nair | f5b6851 | 2022-05-23 20:02:49 -0400 | [diff] [blame] | 119 | thread.scheduleTask("3", [&taskRan](TimerThread::Handle) { |
Andy Hung | f8ab093 | 2022-06-13 19:49:43 -0700 | [diff] [blame] | 120 | taskRan[3] = true; }, DISTRIBUTE_TIMEOUT_SECONDCHANCE_MS_FRAC(400, frac)); |
Atneya Nair | f5b6851 | 2022-05-23 20:02:49 -0400 | [diff] [blame] | 121 | auto handle4 = thread.scheduleTask("4", [&taskRan](TimerThread::Handle) { |
Andy Hung | f8ab093 | 2022-06-13 19:49:43 -0700 | [diff] [blame] | 122 | taskRan[4] = true; }, DISTRIBUTE_TIMEOUT_SECONDCHANCE_MS_FRAC(200, frac)); |
Atneya Nair | f5b6851 | 2022-05-23 20:02:49 -0400 | [diff] [blame] | 123 | thread.scheduleTask("5", [&taskRan](TimerThread::Handle) { |
Andy Hung | f8ab093 | 2022-06-13 19:49:43 -0700 | [diff] [blame] | 124 | taskRan[5] = true; }, DISTRIBUTE_TIMEOUT_SECONDCHANCE_MS_FRAC(200, frac)); |
Andy Hung | a2a1ac3 | 2022-03-18 16:12:11 -0700 | [diff] [blame] | 125 | |
| 126 | // 6 tasks pending |
Andy Hung | cb90d20 | 2022-05-23 18:19:42 -0700 | [diff] [blame] | 127 | ASSERT_EQ(6ul, countChars(thread.pendingToString(), REQUEST_START)); |
Andy Hung | a2a1ac3 | 2022-03-18 16:12:11 -0700 | [diff] [blame] | 128 | // 0 tasks completed |
Andy Hung | cb90d20 | 2022-05-23 18:19:42 -0700 | [diff] [blame] | 129 | ASSERT_EQ(0ul, countChars(thread.retiredToString(), REQUEST_START)); |
Ytai Ben-Tsvi | 1ea62c9 | 2021-11-10 14:38:27 -0800 | [diff] [blame] | 130 | |
Andy Hung | f8ab093 | 2022-06-13 19:49:43 -0700 | [diff] [blame] | 131 | // None of the tasks are expected to have finished at the start. |
| 132 | std::array<std::atomic<bool>, 6> expected{}; |
| 133 | |
Ytai Ben-Tsvi | 1ea62c9 | 2021-11-10 14:38:27 -0800 | [diff] [blame] | 134 | // Task 1 should trigger around 100ms. |
| 135 | std::this_thread::sleep_until(startTime + 100ms - kJitter); |
Andy Hung | f8ab093 | 2022-06-13 19:49:43 -0700 | [diff] [blame] | 136 | |
| 137 | ASSERT_EQ(expected, taskRan); |
| 138 | |
Ytai Ben-Tsvi | 1ea62c9 | 2021-11-10 14:38:27 -0800 | [diff] [blame] | 139 | |
| 140 | std::this_thread::sleep_until(startTime + 100ms + kJitter); |
Andy Hung | f8ab093 | 2022-06-13 19:49:43 -0700 | [diff] [blame] | 141 | |
| 142 | expected[1] = true; |
| 143 | ASSERT_EQ(expected, taskRan); |
Ytai Ben-Tsvi | 1ea62c9 | 2021-11-10 14:38:27 -0800 | [diff] [blame] | 144 | |
| 145 | // Cancel task 4 before it gets a chance to run. |
| 146 | thread.cancelTask(handle4); |
| 147 | |
| 148 | // Tasks 2 and 5 should trigger around 200ms. |
| 149 | std::this_thread::sleep_until(startTime + 200ms - kJitter); |
Andy Hung | f8ab093 | 2022-06-13 19:49:43 -0700 | [diff] [blame] | 150 | |
| 151 | ASSERT_EQ(expected, taskRan); |
| 152 | |
Ytai Ben-Tsvi | 1ea62c9 | 2021-11-10 14:38:27 -0800 | [diff] [blame] | 153 | |
| 154 | std::this_thread::sleep_until(startTime + 200ms + kJitter); |
Andy Hung | f8ab093 | 2022-06-13 19:49:43 -0700 | [diff] [blame] | 155 | |
| 156 | expected[2] = true; |
| 157 | expected[5] = true; |
| 158 | ASSERT_EQ(expected, taskRan); |
Ytai Ben-Tsvi | 1ea62c9 | 2021-11-10 14:38:27 -0800 | [diff] [blame] | 159 | |
| 160 | // Task 0 should trigger around 300ms. |
| 161 | std::this_thread::sleep_until(startTime + 300ms - kJitter); |
Andy Hung | f8ab093 | 2022-06-13 19:49:43 -0700 | [diff] [blame] | 162 | |
| 163 | ASSERT_EQ(expected, taskRan); |
Ytai Ben-Tsvi | 1ea62c9 | 2021-11-10 14:38:27 -0800 | [diff] [blame] | 164 | |
| 165 | std::this_thread::sleep_until(startTime + 300ms + kJitter); |
Andy Hung | f8ab093 | 2022-06-13 19:49:43 -0700 | [diff] [blame] | 166 | |
| 167 | expected[0] = true; |
| 168 | ASSERT_EQ(expected, taskRan); |
Ytai Ben-Tsvi | 1ea62c9 | 2021-11-10 14:38:27 -0800 | [diff] [blame] | 169 | |
Andy Hung | a2a1ac3 | 2022-03-18 16:12:11 -0700 | [diff] [blame] | 170 | // 1 task pending |
Andy Hung | cb90d20 | 2022-05-23 18:19:42 -0700 | [diff] [blame] | 171 | ASSERT_EQ(1ul, countChars(thread.pendingToString(), REQUEST_START)); |
| 172 | // 4 tasks called on timeout, and 1 cancelled |
| 173 | ASSERT_EQ(4ul, countChars(thread.timeoutToString(), REQUEST_START)); |
| 174 | ASSERT_EQ(1ul, countChars(thread.retiredToString(), REQUEST_START)); |
Andy Hung | a2a1ac3 | 2022-03-18 16:12:11 -0700 | [diff] [blame] | 175 | |
Ytai Ben-Tsvi | 1ea62c9 | 2021-11-10 14:38:27 -0800 | [diff] [blame] | 176 | // Task 3 should trigger around 400ms. |
| 177 | std::this_thread::sleep_until(startTime + 400ms - kJitter); |
Andy Hung | f8ab093 | 2022-06-13 19:49:43 -0700 | [diff] [blame] | 178 | |
| 179 | ASSERT_EQ(expected, taskRan); |
Ytai Ben-Tsvi | 1ea62c9 | 2021-11-10 14:38:27 -0800 | [diff] [blame] | 180 | |
Andy Hung | cb90d20 | 2022-05-23 18:19:42 -0700 | [diff] [blame] | 181 | // 4 tasks called on timeout and 1 cancelled |
| 182 | ASSERT_EQ(4ul, countChars(thread.timeoutToString(), REQUEST_START)); |
| 183 | ASSERT_EQ(1ul, countChars(thread.retiredToString(), REQUEST_START)); |
Andy Hung | a2a1ac3 | 2022-03-18 16:12:11 -0700 | [diff] [blame] | 184 | |
Ytai Ben-Tsvi | 1ea62c9 | 2021-11-10 14:38:27 -0800 | [diff] [blame] | 185 | std::this_thread::sleep_until(startTime + 400ms + kJitter); |
Andy Hung | f8ab093 | 2022-06-13 19:49:43 -0700 | [diff] [blame] | 186 | |
| 187 | expected[3] = true; |
| 188 | ASSERT_EQ(expected, taskRan); |
Andy Hung | a2a1ac3 | 2022-03-18 16:12:11 -0700 | [diff] [blame] | 189 | |
| 190 | // 0 tasks pending |
Andy Hung | cb90d20 | 2022-05-23 18:19:42 -0700 | [diff] [blame] | 191 | ASSERT_EQ(0ul, countChars(thread.pendingToString(), REQUEST_START)); |
| 192 | // 5 tasks called on timeout and 1 cancelled |
| 193 | ASSERT_EQ(5ul, countChars(thread.timeoutToString(), REQUEST_START)); |
| 194 | ASSERT_EQ(1ul, countChars(thread.retiredToString(), REQUEST_START)); |
Ytai Ben-Tsvi | 1ea62c9 | 2021-11-10 14:38:27 -0800 | [diff] [blame] | 195 | } |
| 196 | |
Andy Hung | f8ab093 | 2022-06-13 19:49:43 -0700 | [diff] [blame] | 197 | }; // class TimerThreadTest |
| 198 | |
| 199 | TEST_P(TimerThreadTest, Basic) { |
| 200 | testBasic(); |
| 201 | } |
| 202 | |
| 203 | TEST_P(TimerThreadTest, Cancel) { |
| 204 | testCancel(); |
| 205 | } |
| 206 | |
| 207 | TEST_P(TimerThreadTest, CancelAfterRun) { |
| 208 | testCancelAfterRun(); |
| 209 | } |
| 210 | |
| 211 | TEST_P(TimerThreadTest, MultipleTasks) { |
| 212 | testMultipleTasks(); |
| 213 | } |
| 214 | |
| 215 | INSTANTIATE_TEST_CASE_P( |
| 216 | TimerThread, |
| 217 | TimerThreadTest, |
| 218 | ::testing::Values(0.f, 0.5f, 1.f) |
| 219 | ); |
| 220 | |
Andy Hung | a2a1ac3 | 2022-03-18 16:12:11 -0700 | [diff] [blame] | 221 | TEST(TimerThread, TrackedTasks) { |
| 222 | TimerThread thread; |
| 223 | |
| 224 | auto handle0 = thread.trackTask("0"); |
| 225 | auto handle1 = thread.trackTask("1"); |
| 226 | auto handle2 = thread.trackTask("2"); |
| 227 | |
Andy Hung | 2aa1510 | 2022-06-13 19:49:43 -0700 | [diff] [blame] | 228 | ASSERT_TRUE(TimerThread::isNoTimeoutHandle(handle0)); |
| 229 | ASSERT_TRUE(TimerThread::isNoTimeoutHandle(handle1)); |
| 230 | ASSERT_TRUE(TimerThread::isNoTimeoutHandle(handle2)); |
| 231 | |
Andy Hung | a2a1ac3 | 2022-03-18 16:12:11 -0700 | [diff] [blame] | 232 | // 3 tasks pending |
Andy Hung | cb90d20 | 2022-05-23 18:19:42 -0700 | [diff] [blame] | 233 | ASSERT_EQ(3ul, countChars(thread.pendingToString(), REQUEST_START)); |
Andy Hung | a2a1ac3 | 2022-03-18 16:12:11 -0700 | [diff] [blame] | 234 | // 0 tasks retired |
Andy Hung | cb90d20 | 2022-05-23 18:19:42 -0700 | [diff] [blame] | 235 | ASSERT_EQ(0ul, countChars(thread.retiredToString(), REQUEST_START)); |
Andy Hung | a2a1ac3 | 2022-03-18 16:12:11 -0700 | [diff] [blame] | 236 | |
| 237 | ASSERT_TRUE(thread.cancelTask(handle0)); |
| 238 | ASSERT_TRUE(thread.cancelTask(handle1)); |
| 239 | |
| 240 | // 1 task pending |
Andy Hung | cb90d20 | 2022-05-23 18:19:42 -0700 | [diff] [blame] | 241 | ASSERT_EQ(1ul, countChars(thread.pendingToString(), REQUEST_START)); |
Andy Hung | a2a1ac3 | 2022-03-18 16:12:11 -0700 | [diff] [blame] | 242 | // 2 tasks retired |
Andy Hung | cb90d20 | 2022-05-23 18:19:42 -0700 | [diff] [blame] | 243 | ASSERT_EQ(2ul, countChars(thread.retiredToString(), REQUEST_START)); |
Andy Hung | a2a1ac3 | 2022-03-18 16:12:11 -0700 | [diff] [blame] | 244 | |
| 245 | // handle1 is stale, cancel returns false. |
| 246 | ASSERT_FALSE(thread.cancelTask(handle1)); |
| 247 | |
| 248 | // 1 task pending |
Andy Hung | cb90d20 | 2022-05-23 18:19:42 -0700 | [diff] [blame] | 249 | ASSERT_EQ(1ul, countChars(thread.pendingToString(), REQUEST_START)); |
Andy Hung | a2a1ac3 | 2022-03-18 16:12:11 -0700 | [diff] [blame] | 250 | // 2 tasks retired |
Andy Hung | cb90d20 | 2022-05-23 18:19:42 -0700 | [diff] [blame] | 251 | ASSERT_EQ(2ul, countChars(thread.retiredToString(), REQUEST_START)); |
Andy Hung | a2a1ac3 | 2022-03-18 16:12:11 -0700 | [diff] [blame] | 252 | |
| 253 | // Add another tracked task. |
| 254 | auto handle3 = thread.trackTask("3"); |
Andy Hung | 2aa1510 | 2022-06-13 19:49:43 -0700 | [diff] [blame] | 255 | ASSERT_TRUE(TimerThread::isNoTimeoutHandle(handle3)); |
Andy Hung | a2a1ac3 | 2022-03-18 16:12:11 -0700 | [diff] [blame] | 256 | |
| 257 | // 2 tasks pending |
Andy Hung | cb90d20 | 2022-05-23 18:19:42 -0700 | [diff] [blame] | 258 | ASSERT_EQ(2ul, countChars(thread.pendingToString(), REQUEST_START)); |
Andy Hung | a2a1ac3 | 2022-03-18 16:12:11 -0700 | [diff] [blame] | 259 | // 2 tasks retired |
Andy Hung | cb90d20 | 2022-05-23 18:19:42 -0700 | [diff] [blame] | 260 | ASSERT_EQ(2ul, countChars(thread.retiredToString(), REQUEST_START)); |
Andy Hung | a2a1ac3 | 2022-03-18 16:12:11 -0700 | [diff] [blame] | 261 | |
| 262 | ASSERT_TRUE(thread.cancelTask(handle2)); |
| 263 | |
| 264 | // 1 tasks pending |
Andy Hung | cb90d20 | 2022-05-23 18:19:42 -0700 | [diff] [blame] | 265 | ASSERT_EQ(1ul, countChars(thread.pendingToString(), REQUEST_START)); |
Andy Hung | a2a1ac3 | 2022-03-18 16:12:11 -0700 | [diff] [blame] | 266 | // 3 tasks retired |
Andy Hung | cb90d20 | 2022-05-23 18:19:42 -0700 | [diff] [blame] | 267 | ASSERT_EQ(3ul, countChars(thread.retiredToString(), REQUEST_START)); |
Andy Hung | a2a1ac3 | 2022-03-18 16:12:11 -0700 | [diff] [blame] | 268 | |
| 269 | ASSERT_TRUE(thread.cancelTask(handle3)); |
| 270 | |
| 271 | // 0 tasks pending |
Andy Hung | cb90d20 | 2022-05-23 18:19:42 -0700 | [diff] [blame] | 272 | ASSERT_EQ(0ul, countChars(thread.pendingToString(), REQUEST_START)); |
Andy Hung | a2a1ac3 | 2022-03-18 16:12:11 -0700 | [diff] [blame] | 273 | // 4 tasks retired |
Andy Hung | cb90d20 | 2022-05-23 18:19:42 -0700 | [diff] [blame] | 274 | ASSERT_EQ(4ul, countChars(thread.retiredToString(), REQUEST_START)); |
Andy Hung | a2a1ac3 | 2022-03-18 16:12:11 -0700 | [diff] [blame] | 275 | } |
Ytai Ben-Tsvi | 1ea62c9 | 2021-11-10 14:38:27 -0800 | [diff] [blame] | 276 | |
| 277 | } // namespace |