@@ -1956,6 +1956,60 @@ TEST_F(
19561956 check_read_and_write_cycles (false );
19571957}
19581958
1959+ TEST_F (
1960+ ResourceManagerTestReadWriteDifferentReadWriteRate,
1961+ test_components_with_different_read_write_freq_not_exact_timing)
1962+ {
1963+ setup_resource_manager_and_do_initial_checks ();
1964+
1965+ const auto test_jitter = std::chrono::milliseconds{1 };
1966+
1967+ const auto read = [&]()
1968+ {
1969+ const auto [ok, failed_hardware_names] = rm->read (time, duration);
1970+ EXPECT_TRUE (ok);
1971+ EXPECT_TRUE (failed_hardware_names.empty ());
1972+ };
1973+ const auto write = [&]()
1974+ {
1975+ const auto [ok, failed_hardware_names] = rm->write (time, duration);
1976+ EXPECT_TRUE (ok);
1977+ EXPECT_TRUE (failed_hardware_names.empty ());
1978+ };
1979+
1980+ // t = 1 * duration
1981+ // State interface should not update
1982+ read ();
1983+ EXPECT_DOUBLE_EQ (state_itfs[0 ].get_optional ().value (), 0.0 );
1984+ EXPECT_TRUE (claimed_itfs[0 ].set_value (10 ));
1985+ write ();
1986+ node_.get_clock ()->sleep_until (time + duration + test_jitter);
1987+ time = node_.get_clock ()->now ();
1988+
1989+ // t = 2 * duration + test_jitter
1990+ // State interface should update
1991+ read ();
1992+ EXPECT_DOUBLE_EQ (state_itfs[0 ].get_optional ().value (), 5.0 );
1993+ EXPECT_TRUE (claimed_itfs[0 ].set_value (20 ));
1994+ write ();
1995+ node_.get_clock ()->sleep_until (time + duration - test_jitter);
1996+ time = node_.get_clock ()->now ();
1997+
1998+ // t = 3 * duration
1999+ // State interface should not update
2000+ read ();
2001+ EXPECT_DOUBLE_EQ (state_itfs[0 ].get_optional ().value (), 5.0 );
2002+ EXPECT_TRUE (claimed_itfs[0 ].set_value (30 ));
2003+ write ();
2004+ node_.get_clock ()->sleep_until (time + duration - test_jitter);
2005+ time = node_.get_clock ()->now ();
2006+
2007+ // t = 4 * duration - test_jitter
2008+ // State interface should update
2009+ read ();
2010+ EXPECT_DOUBLE_EQ (state_itfs[0 ].get_optional ().value (), 15.0 );
2011+ }
2012+
19592013class ResourceManagerTestAsyncReadWrite : public ResourceManagerTest
19602014{
19612015public:
0 commit comments