| 38 | }; |
| 39 | |
| 40 | TEST(StandaloneRuntime, exitCoordinatorStopsMainQueueWhenAllQueuesAreEmpty) { |
| 41 | auto mainQueue = makeShared<MainQueue>(); |
| 42 | auto jsQueue = DispatchQueue::create(STRING_LITERAL("Valdi JS Queue"), ThreadQoSClassMax); |
| 43 | |
| 44 | auto exitCoordinator = makeShared<StandaloneExitCoordinator>(jsQueue, mainQueue); |
| 45 | exitCoordinator->postInit(); |
| 46 | exitCoordinator->setEnabled(true); |
| 47 | |
| 48 | auto group = makeShared<AsyncGroup>(); |
| 49 | jsQueue->setListener(makeShared<TestQueueListener>(group, jsQueue->getListener())); |
| 50 | mainQueue->setListener(makeShared<TestQueueListener>(group, mainQueue->getListener())); |
| 51 | |
| 52 | int ranTasksCount = 0; |
| 53 | int expectedTasksCount = 5; |
| 54 | |
| 55 | for (int i = 0; i < expectedTasksCount; i++) { |
| 56 | jsQueue->async([&]() { mainQueue->enqueue([&]() { ranTasksCount++; }); }); |
| 57 | } |
| 58 | |
| 59 | ASSERT_FALSE(mainQueue->isDisposed()); |
| 60 | |
| 61 | mainQueue->runUntilTrue([&]() { return ranTasksCount == expectedTasksCount; }); |
| 62 | |
| 63 | mainQueue->flush(); |
| 64 | |
| 65 | ASSERT_TRUE(group->blockingWaitWithTimeout(std::chrono::seconds(5))); |
| 66 | |
| 67 | exitCoordinator->flushUpdatesSync(); |
| 68 | |
| 69 | // The main queue should have been disposed as all the JS tasks and main queue tasks have been flushed |
| 70 | |
| 71 | ASSERT_TRUE(mainQueue->isDisposed()); |
| 72 | } |
| 73 | |
| 74 | TEST(StandaloneRuntime, canPrecompileJs) { |
| 75 | auto jsContent = makeShared<ByteBuffer>("module.exports.hello = 42;"); |
nothing calls this directly
no test coverage detected