From 7f9c0dec3e90a0e3d94d461984b03092a5c2cdfa Mon Sep 17 00:00:00 2001 From: Steven van der Vegt Date: Wed, 9 Sep 2026 11:00:19 +0200 Subject: [PATCH] test(discovery): fix second-boundary race in refresh error timestamp check LastOccurrence is stored as whole seconds. The assertion compared it with "now minus one second", also truncated, using strict greater-than. When the store happens at the end of a second and the check runs in the next one, both truncate to the same value and the assertion fails. Compare against a timestamp taken before the call instead. Assisted-by: AI (cherry picked from commit 33d918750d89e08d43647718be3e91564b89e156) --- discovery/store_test.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/discovery/store_test.go b/discovery/store_test.go index 8239aa0a8..511a16e82 100644 --- a/discovery/store_test.go +++ b/discovery/store_test.go @@ -372,6 +372,10 @@ func Test_sqlStore_setPresentationRefreshError(t *testing.T) { t.Run("store", func(t *testing.T) { c := setupStore(t, storageEngine.GetSQLDatabase()) + // LastOccurrence is stored in whole seconds, so compare against a timestamp + // taken before the call instead of "now minus a second": the latter fails + // when the call and the assertion straddle a second boundary. + before := int(time.Now().Unix()) require.NoError(t, c.updatePresentationRefreshTime(testServiceID, aliceSubject, nil, to.Ptr(time.Now().Add(time.Second)))) require.NoError(t, c.setPresentationRefreshError(testServiceID, aliceSubject, assert.AnError)) @@ -379,7 +383,7 @@ func Test_sqlStore_setPresentationRefreshError(t *testing.T) { refreshError := getPresentationRefreshError(t, c.db, testServiceID, aliceSubject) assert.Equal(t, refreshError.Error, assert.AnError.Error()) - assert.True(t, refreshError.LastOccurrence > int(time.Now().Add(-1*time.Second).Unix())) + assert.GreaterOrEqual(t, refreshError.LastOccurrence, before) }) t.Run("deletePresentationRecord", func(t *testing.T) { c := setupStore(t, storageEngine.GetSQLDatabase())