From 74f39b7d1d22a28f33a87cc16867192f7a6644a7 Mon Sep 17 00:00:00 2001 From: acuadros95 Date: Thu, 16 Jun 2022 11:10:01 +0200 Subject: [PATCH 1/3] Fix wait_session_status listen timeout Signed-off-by: acuadros95 --- src/c/core/session/session.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/c/core/session/session.c b/src/c/core/session/session.c index c676fed2..d0333755 100644 --- a/src/c/core/session/session.c +++ b/src/c/core/session/session.c @@ -748,7 +748,15 @@ bool wait_session_status( for (size_t i = 0; i < attempts && session->info.last_requested_status == UXR_STATUS_NONE; ++i) { send_message(session, buffer, length); - listen_message(session, UXR_CONFIG_MIN_SESSION_CONNECTION_INTERVAL); + + int64_t start_timestamp = uxr_millis(); + int remaining_time = UXR_CONFIG_MIN_SESSION_CONNECTION_INTERVAL; + + do + { + listen_message(session, remaining_time); + remaining_time -= (int)(uxr_millis() - start_timestamp); + } while (remaining_time > 0 && session->info.last_requested_status == UXR_STATUS_NONE); } return session->info.last_requested_status != UXR_STATUS_NONE; From aa576ae9655038dbcac1a3df9c67a74f47543f37 Mon Sep 17 00:00:00 2001 From: acuadros95 Date: Thu, 16 Jun 2022 11:52:51 +0200 Subject: [PATCH 2/3] Update timeout calc and test --- src/c/core/session/session.c | 2 +- test/unitary/session/Session.cpp | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/c/core/session/session.c b/src/c/core/session/session.c index d0333755..d0a37ef0 100644 --- a/src/c/core/session/session.c +++ b/src/c/core/session/session.c @@ -755,7 +755,7 @@ bool wait_session_status( do { listen_message(session, remaining_time); - remaining_time -= (int)(uxr_millis() - start_timestamp); + remaining_time = UXR_CONFIG_MIN_SESSION_CONNECTION_INTERVAL - (int)(uxr_millis() - start_timestamp); } while (remaining_time > 0 && session->info.last_requested_status == UXR_STATUS_NONE); } diff --git a/test/unitary/session/Session.cpp b/test/unitary/session/Session.cpp index 936da846..508fc914 100644 --- a/test/unitary/session/Session.cpp +++ b/test/unitary/session/Session.cpp @@ -361,9 +361,15 @@ TEST_F(SessionTest, WaitSessionStatusBad) uint8_t buffer[MTU]; size_t length = 0; size_t attempts = 10; + int64_t start_timestamp = uxr_millis(); bool found = wait_session_status(&session, buffer, length, attempts); EXPECT_FALSE(found); - EXPECT_EQ(attempts, size_t(SessionTest::listening_counter)); + EXPECT_GE(size_t(SessionTest::listening_counter), attempts); + + // Check elapsed time with 10 ms tolerance + int64_t final_time = uxr_millis() - start_timestamp; + int64_t expected_time = (int64_t) (UXR_CONFIG_MIN_SESSION_CONNECTION_INTERVAL * attempts); + EXPECT_NEAR((double) final_time, (double) expected_time, 10); } TEST_F(SessionTest, SendMessageOk) From de481c1a82364502dd3773d8a60b8bcde194b83b Mon Sep 17 00:00:00 2001 From: acuadros95 Date: Thu, 16 Jun 2022 12:02:06 +0200 Subject: [PATCH 3/3] Increase time tolerance Signed-off-by: acuadros95 --- test/unitary/session/Session.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/unitary/session/Session.cpp b/test/unitary/session/Session.cpp index 508fc914..12a44204 100644 --- a/test/unitary/session/Session.cpp +++ b/test/unitary/session/Session.cpp @@ -366,10 +366,10 @@ TEST_F(SessionTest, WaitSessionStatusBad) EXPECT_FALSE(found); EXPECT_GE(size_t(SessionTest::listening_counter), attempts); - // Check elapsed time with 10 ms tolerance + // Check elapsed time with 100 ms tolerance int64_t final_time = uxr_millis() - start_timestamp; int64_t expected_time = (int64_t) (UXR_CONFIG_MIN_SESSION_CONNECTION_INTERVAL * attempts); - EXPECT_NEAR((double) final_time, (double) expected_time, 10); + EXPECT_NEAR((double) final_time, (double) expected_time, 100); } TEST_F(SessionTest, SendMessageOk)