Skip to content

Commit 806b181

Browse files
committed
fix(libsinsp): fix failing UT THRD_TABLE_remove_inactive_threads
Force reset of last_access_time in remove_inactive_threads method of sinsp_with_test_input. Signed-off-by: irozzo-1A <iacopo@sysdig.com>
1 parent 9e6441b commit 806b181

2 files changed

Lines changed: 7 additions & 0 deletions

File tree

userspace/libsinsp/sinsp.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -782,6 +782,9 @@ class SINSP_PUBLIC sinsp : public capture_stats_source {
782782

783783
uint64_t get_lastevent_ts() const { return m_timestamper.get_cached_ts(); }
784784
void set_lastevent_ts(const uint64_t v) { m_timestamper.set_cached_ts(v); }
785+
/** Reset cached last-event timestamp so a subsequent set_lastevent_ts can set any value (e.g.
786+
* in tests). */
787+
void reset_lastevent_ts() { m_timestamper.reset(); }
785788

786789
inline const std::string& get_host_root() const { return m_host_root; }
787790
inline void set_host_root(const std::string& s) { m_host_root = s; }

userspace/libsinsp/test/sinsp_with_test_input.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,10 @@ void sinsp_with_test_input::remove_inactive_threads(uint64_t m_lastevent_ts,
703703
m_inspector.m_thread_manager->set_last_flush_time_ns(1);
704704
m_inspector.m_threads_purging_scan_time_ns = 2;
705705

706+
// set_lastevent_ts only updates when the new value is greater than the current (monotonic).
707+
// After processing events, the cached ts is the last event ts (e.g. from increasing_ts()).
708+
// Reset so the test can force the "current time" used by the purge logic.
709+
m_inspector.reset_lastevent_ts();
706710
m_inspector.set_lastevent_ts(m_lastevent_ts);
707711
m_inspector.m_thread_timeout_ns = thread_timeout;
708712
m_inspector.remove_inactive_threads();

0 commit comments

Comments
 (0)