| 229 | * pendingTaskCountMax + 1th task. Verify that we unblock when a task completes */ |
| 230 | |
| 231 | bool blockTest(int64_t timeout = 100LL, size_t workerCount = 2) { |
| 232 | (void)timeout; |
| 233 | bool success = false; |
| 234 | |
| 235 | try { |
| 236 | |
| 237 | Monitor entryMonitor; // not used by this test |
| 238 | Monitor blockMonitor; |
| 239 | bool blocked[] = {true, true, true}; |
| 240 | Monitor doneMonitor; |
| 241 | |
| 242 | size_t pendingTaskMaxCount = workerCount; |
| 243 | |
| 244 | size_t activeCounts[] = {workerCount, pendingTaskMaxCount, 1}; |
| 245 | |
| 246 | shared_ptr<ThreadManager> threadManager |
| 247 | = ThreadManager::newSimpleThreadManager(workerCount, pendingTaskMaxCount); |
| 248 | |
| 249 | shared_ptr<ThreadFactory> threadFactory |
| 250 | = shared_ptr<ThreadFactory>(new ThreadFactory()); |
| 251 | |
| 252 | threadManager->threadFactory(threadFactory); |
| 253 | |
| 254 | threadManager->start(); |
| 255 | |
| 256 | std::vector<shared_ptr<ThreadManagerTests::BlockTask> > tasks; |
| 257 | tasks.reserve(workerCount + pendingTaskMaxCount); |
| 258 | |
| 259 | for (size_t ix = 0; ix < workerCount; ix++) { |
| 260 | |
| 261 | tasks.push_back(shared_ptr<ThreadManagerTests::BlockTask>( |
| 262 | new ThreadManagerTests::BlockTask(entryMonitor, blockMonitor, blocked[0], doneMonitor, activeCounts[0]))); |
| 263 | } |
| 264 | |
| 265 | for (size_t ix = 0; ix < pendingTaskMaxCount; ix++) { |
| 266 | |
| 267 | tasks.push_back(shared_ptr<ThreadManagerTests::BlockTask>( |
| 268 | new ThreadManagerTests::BlockTask(entryMonitor, blockMonitor, blocked[1], doneMonitor, activeCounts[1]))); |
| 269 | } |
| 270 | |
| 271 | for (auto ix = tasks.begin(); |
| 272 | ix != tasks.end(); |
| 273 | ix++) { |
| 274 | threadManager->add(*ix); |
| 275 | } |
| 276 | |
| 277 | if (!(success = (threadManager->totalTaskCount() == pendingTaskMaxCount + workerCount))) { |
| 278 | throw TException("Unexpected pending task count"); |
| 279 | } |
| 280 | |
| 281 | shared_ptr<ThreadManagerTests::BlockTask> extraTask( |
| 282 | new ThreadManagerTests::BlockTask(entryMonitor, blockMonitor, blocked[2], doneMonitor, activeCounts[2])); |
| 283 | |
| 284 | try { |
| 285 | threadManager->add(extraTask, 1); |
| 286 | throw TException("Unexpected success adding task in excess of pending task count"); |
| 287 | } catch (TooManyPendingTasksException&) { |
| 288 | throw TException("Should have timed out adding task in excess of pending task count"); |
no test coverage detected