Fix flaky e2e timestamp tests

Increase sleep time from 10ms to 1100ms to ensure timestamp precision works
consistently across databases with second-level granularity. Strengthen
AssertTimestampsOnUpdate to require strictly increasing timestamps instead of
allowing equal values.

Signed-off-by: Bryan Frimin <bryan@getprobo.com>
This commit is contained in:
Bryan Frimin
2026-03-19 11:39:34 +01:00
parent b87ea87c42
commit 922c0c2db8
7 changed files with 14 additions and 9 deletions

View File

@@ -708,7 +708,8 @@ func TestAudit_Timestamps(t *testing.T) {
initialCreatedAt := getResult.Node.CreatedAt initialCreatedAt := getResult.Node.CreatedAt
initialUpdatedAt := getResult.Node.UpdatedAt initialUpdatedAt := getResult.Node.UpdatedAt
time.Sleep(10 * time.Millisecond) // Wait long enough for timestamp to change (database may have second precision)
time.Sleep(1100 * time.Millisecond)
updateQuery := ` updateQuery := `
mutation UpdateAudit($input: UpdateAuditInput!) { mutation UpdateAudit($input: UpdateAuditInput!) {

View File

@@ -677,7 +677,8 @@ func TestDatum_Timestamps(t *testing.T) {
initialCreatedAt := getResult.Node.CreatedAt initialCreatedAt := getResult.Node.CreatedAt
initialUpdatedAt := getResult.Node.UpdatedAt initialUpdatedAt := getResult.Node.UpdatedAt
time.Sleep(10 * time.Millisecond) // Wait long enough for timestamp to change (database may have second precision)
time.Sleep(1100 * time.Millisecond)
updateQuery := ` updateQuery := `
mutation UpdateDatum($input: UpdateDatumInput!) { mutation UpdateDatum($input: UpdateDatumInput!) {

View File

@@ -674,7 +674,8 @@ func TestDocument_Timestamps(t *testing.T) {
initialCreatedAt := getResult.Node.CreatedAt initialCreatedAt := getResult.Node.CreatedAt
initialUpdatedAt := getResult.Node.UpdatedAt initialUpdatedAt := getResult.Node.UpdatedAt
time.Sleep(10 * time.Millisecond) // Wait long enough for timestamp to change (database may have second precision)
time.Sleep(1100 * time.Millisecond)
updateQuery := ` updateQuery := `
mutation UpdateDocument($input: UpdateDocumentInput!) { mutation UpdateDocument($input: UpdateDocumentInput!) {

View File

@@ -785,8 +785,8 @@ func TestMeasure_Timestamps(t *testing.T) {
initialCreatedAt := getResult.Node.CreatedAt initialCreatedAt := getResult.Node.CreatedAt
initialUpdatedAt := getResult.Node.UpdatedAt initialUpdatedAt := getResult.Node.UpdatedAt
// Wait a bit to ensure timestamp difference // Wait long enough for timestamp to change (database may have second precision)
time.Sleep(10 * time.Millisecond) time.Sleep(1100 * time.Millisecond)
updateQuery := ` updateQuery := `
mutation UpdateMeasure($input: UpdateMeasureInput!) { mutation UpdateMeasure($input: UpdateMeasureInput!) {

View File

@@ -595,7 +595,8 @@ func TestMeeting_Timestamps(t *testing.T) {
initialCreatedAt := getResult.Node.CreatedAt initialCreatedAt := getResult.Node.CreatedAt
initialUpdatedAt := getResult.Node.UpdatedAt initialUpdatedAt := getResult.Node.UpdatedAt
time.Sleep(10 * time.Millisecond) // Wait long enough for timestamp to change (database may have second precision)
time.Sleep(1100 * time.Millisecond)
updateQuery := ` updateQuery := `
mutation UpdateMeeting($input: UpdateMeetingInput!) { mutation UpdateMeeting($input: UpdateMeetingInput!) {

View File

@@ -556,7 +556,8 @@ func TestProcessingActivity_Timestamps(t *testing.T) {
initialCreatedAt := getResult.Node.CreatedAt initialCreatedAt := getResult.Node.CreatedAt
initialUpdatedAt := getResult.Node.UpdatedAt initialUpdatedAt := getResult.Node.UpdatedAt
time.Sleep(10 * time.Millisecond) // Wait long enough for timestamp to change (database may have second precision)
time.Sleep(1100 * time.Millisecond)
updateQuery := ` updateQuery := `
mutation UpdateProcessingActivity($input: UpdateProcessingActivityInput!) { mutation UpdateProcessingActivity($input: UpdateProcessingActivityInput!) {

View File

@@ -74,8 +74,8 @@ func AssertTimestampsOnCreate(t *testing.T, createdAt, updatedAt, beforeCreate t
func AssertTimestampsOnUpdate(t *testing.T, createdAt, updatedAt, originalCreatedAt, originalUpdatedAt time.Time) { func AssertTimestampsOnUpdate(t *testing.T, createdAt, updatedAt, originalCreatedAt, originalUpdatedAt time.Time) {
t.Helper() t.Helper()
assert.Equal(t, originalCreatedAt, createdAt, "createdAt should not change on update") assert.Equal(t, originalCreatedAt, createdAt, "createdAt should not change on update")
assert.True(t, updatedAt.After(originalUpdatedAt) || updatedAt.Equal(originalUpdatedAt), assert.True(t, updatedAt.After(originalUpdatedAt),
"updatedAt should be >= previous updatedAt") "updatedAt should be strictly after previous updatedAt")
} }
func AssertOptionalStringEqual(t *testing.T, expected, actual *string, fieldName string) { func AssertOptionalStringEqual(t *testing.T, expected, actual *string, fieldName string) {