mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/35525 [Changelog][Internal] Adds ability to invoke an async JS callback from a C++ native module, as a task with priority. This will allow native modules to schedule less important calls to JS thread with lower priority. One example use case is feeding collected perf metrics back to JS. Reviewed By: javache Differential Revision: D41492849 fbshipit-source-id: 12f738557972dc23398d9bb9a7a01125c79da070
48 lines
1.8 KiB
C++
48 lines
1.8 KiB
C++
/*
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*/
|
|
|
|
#include <gtest/gtest.h>
|
|
#include <react/renderer/runtimescheduler/SchedulerPriorityUtils.h>
|
|
#include <react/renderer/runtimescheduler/Task.h>
|
|
#include <chrono>
|
|
|
|
using namespace facebook::react;
|
|
|
|
TEST(SchedulerPriorityTest, fromRawValue) {
|
|
EXPECT_EQ(SchedulerPriority::ImmediatePriority, fromRawValue(1.0));
|
|
EXPECT_EQ(SchedulerPriority::UserBlockingPriority, fromRawValue(2.0));
|
|
EXPECT_EQ(SchedulerPriority::NormalPriority, fromRawValue(3.0));
|
|
EXPECT_EQ(SchedulerPriority::LowPriority, fromRawValue(4.0));
|
|
EXPECT_EQ(SchedulerPriority::IdlePriority, fromRawValue(5.0));
|
|
}
|
|
|
|
TEST(SchedulerPriorityTest, serialize) {
|
|
EXPECT_EQ(serialize(SchedulerPriority::ImmediatePriority), 1);
|
|
EXPECT_EQ(serialize(SchedulerPriority::UserBlockingPriority), 2);
|
|
EXPECT_EQ(serialize(SchedulerPriority::NormalPriority), 3);
|
|
EXPECT_EQ(serialize(SchedulerPriority::LowPriority), 4);
|
|
EXPECT_EQ(serialize(SchedulerPriority::IdlePriority), 5);
|
|
}
|
|
|
|
TEST(SchedulerPriorityTest, timeoutForSchedulerPriority) {
|
|
EXPECT_EQ(
|
|
timeoutForSchedulerPriority(SchedulerPriority::ImmediatePriority),
|
|
std::chrono::milliseconds(-1));
|
|
EXPECT_EQ(
|
|
timeoutForSchedulerPriority(SchedulerPriority::UserBlockingPriority),
|
|
std::chrono::milliseconds(250));
|
|
EXPECT_EQ(
|
|
timeoutForSchedulerPriority(SchedulerPriority::NormalPriority),
|
|
std::chrono::seconds(5));
|
|
EXPECT_EQ(
|
|
timeoutForSchedulerPriority(SchedulerPriority::LowPriority),
|
|
std::chrono::seconds(10));
|
|
EXPECT_EQ(
|
|
timeoutForSchedulerPriority(SchedulerPriority::IdlePriority),
|
|
std::chrono::milliseconds::max());
|
|
}
|