MCPcopy Create free account
hub / github.com/Snapchat/Valdi / TEST

Function TEST

valdi/test/integration/StandaloneRuntime_tests.cpp:40–72  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

38};
39
40TEST(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
74TEST(StandaloneRuntime, canPrecompileJs) {
75 auto jsContent = makeShared<ByteBuffer>("module.exports.hello = 42;");

Callers

nothing calls this directly

Calls 15

runUntilTrueMethod · 0.80
flushUpdatesSyncMethod · 0.80
descriptionMethod · 0.80
setListenerMethod · 0.65
flushMethod · 0.65
valueMethod · 0.65
createFunction · 0.50
getFunction · 0.50
postInitMethod · 0.45
setEnabledMethod · 0.45
getListenerMethod · 0.45

Tested by

no test coverage detected