From 73069ae9a0b2a3fabde1e141b134350657718290 Mon Sep 17 00:00:00 2001 From: binwiederhier Date: Fri, 17 Mar 2023 22:05:07 -0400 Subject: [PATCH] Fix test --- server/server_test.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/server/server_test.go b/server/server_test.go index fdda5d96..514616c7 100644 --- a/server/server_test.go +++ b/server/server_test.go @@ -1186,8 +1186,13 @@ func TestServer_PublishAndExpungeTopicAfter16Hours(t *testing.T) { "Cache": "no", }) require.Equal(t, 200, response.Code) - require.True(t, s.topics["mytopic"].lastAccess.Unix() >= time.Now().Unix()-2) - require.True(t, s.topics["mytopic"].lastAccess.Unix() <= time.Now().Unix()+2) + waitFor(t, func() bool { + // .lastAccess set in t.Publish() -> t.Keepalive() in Goroutine + s.topics["mytopic"].mu.RLock() + defer s.topics["mytopic"].mu.RUnlock() + return s.topics["mytopic"].lastAccess.Unix() >= time.Now().Unix()-2 && + s.topics["mytopic"].lastAccess.Unix() <= time.Now().Unix()+2 + }) // Topic won't get pruned s.execManager() @@ -1195,7 +1200,9 @@ func TestServer_PublishAndExpungeTopicAfter16Hours(t *testing.T) { // Fudge with last access, but subscribe, and see that it won't get pruned (because of subscriber) subID := s.topics["mytopic"].Subscribe(subFn, "", func() {}) + s.topics["mytopic"].mu.Lock() s.topics["mytopic"].lastAccess = time.Now().Add(-17 * time.Hour) + s.topics["mytopic"].mu.Unlock() s.execManager() require.NotNil(t, s.topics["mytopic"])