走偏的一版

This commit is contained in:
2026-08-14 09:12:42 +08:00
parent cb32f72bc9
commit f5873855a3
24 changed files with 2428 additions and 1800 deletions
@@ -1,4 +1,7 @@
#include <gtest/gtest.h>
#include <atomic>
#include <chrono>
#include <future>
#include <limits>
#include <stdexcept>
#include "Low_Latency_Strategy_Test_Types.hpp"
@@ -36,6 +39,69 @@ TEST(low_latency_strategy_test, abandons_unconsumed_cached_frame) {
}
EXPECT_EQ(strategy.counter_statistics().abandoned_frame_count, 1);
}
TEST(low_latency_strategy_test, replacement_disabled_preserves_pending_frame_and_wakes_after_renderer_release) {
using namespace std::chrono_literals;
Low_Latency_Test_Time_Source time_source;
Low_Latency_Test_Observer observer;
Low_Latency_Test_Strategy strategy{
Low_Latency_Test_Observer_State(observer, time_source), {60.0, false}};
{
auto frame = strategy.acquire_painter();
frame->value = 1;
}
EXPECT_EQ(strategy.pending_frame_count(), 1U);
std::promise<void> producer_started;
auto producer_started_future = producer_started.get_future();
auto producer = std::async(std::launch::async, [&] {
producer_started.set_value();
auto frame = strategy.acquire_painter();
frame->value = 2;
});
producer_started_future.wait();
EXPECT_EQ(producer.wait_for(50ms), std::future_status::timeout);
{
auto frame = strategy.acquire_renderer();
ASSERT_TRUE(frame);
EXPECT_EQ(frame->value, 1);
}
ASSERT_EQ(producer.wait_for(1s), std::future_status::ready);
producer.get();
EXPECT_EQ(strategy.pending_frame_count(), 1U);
{
auto frame = strategy.acquire_renderer();
ASSERT_TRUE(frame);
EXPECT_EQ(frame->value, 2);
}
EXPECT_EQ(strategy.counter_statistics().abandoned_frame_count, 0u);
}
TEST(low_latency_strategy_test, replacement_disabled_wakes_blocked_producer_after_explicit_discard) {
using namespace std::chrono_literals;
Low_Latency_Test_Time_Source time_source;
Low_Latency_Test_Observer observer;
Low_Latency_Test_Strategy strategy{
Low_Latency_Test_Observer_State(observer, time_source), {60.0, false}};
{
auto frame = strategy.acquire_painter();
frame->value = 1;
}
std::promise<void> producer_started;
auto producer_started_future = producer_started.get_future();
auto producer = std::async(std::launch::async, [&] {
producer_started.set_value();
auto frame = strategy.acquire_painter();
frame->value = 2;
});
producer_started_future.wait();
EXPECT_EQ(producer.wait_for(50ms), std::future_status::timeout);
EXPECT_TRUE(strategy.discard_pending_frame());
ASSERT_EQ(producer.wait_for(1s), std::future_status::ready);
producer.get();
EXPECT_EQ(strategy.counter_statistics().abandoned_frame_count, 0u);
EXPECT_EQ(strategy.counter_statistics().manually_discarded_frame_count, 1u);
}
TEST(low_latency_strategy_test, manually_discards_stale_latest_data_frame) {
Low_Latency_Test_Time_Source time_source;
Low_Latency_Test_Observer observer;