Files
react-native/ReactCommon/react/renderer/runtimescheduler/tests/SchedulerPriorityTest.cpp
T
Andres Suarez 8bd3edec88 Update copyright headers from Facebook to Meta
Reviewed By: aaronabramov

Differential Revision: D33367752

fbshipit-source-id: 4ce94d184485e5ee0a62cf67ad2d3ba16e285c8f
2021-12-30 15:11:21 -08:00

47 lines
1.7 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/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());
}