Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

test(handler): use database clock for timestamp fallback bounds (#8570)

YYClawd62048f4470e
diff --git a/server/internal/handler/task_message_batch_test.go b/server/internal/handler/task_message_batch_test.go
index f23a36697f..9f09bc8aea 100644
--- a/server/internal/handler/task_message_batch_test.go
+++ b/server/internal/handler/task_message_batch_test.go
@@ -142,7 +142,10 @@ func TestReportTaskMessagesFallsBackWholeBatchForClockSkew(t *testing.T) {
taskID := seedBatchTask(t, "batch-clock-skew")
validAt := time.Now().UTC().Add(-time.Second)
invalidAt := validAt.Add(-maxTaskMessageClockSkew - time.Minute)
- fallbackBefore := time.Now().UTC()
+ // The fallback is generated by PostgreSQL, whose clock may differ from
+ // the test host (for example, a local container VM). Bound it on that clock.
+ var fallbackBefore time.Time
+ dbfx.QueryRow(t, `SELECT clock_timestamp()`).Scan(&fallbackBefore)
testutil.Call(t, testHandler.ReportTaskMessages, batchMessagesRequest(t, taskID, []any{
map[string]any{
@@ -158,7 +161,8 @@ func TestReportTaskMessagesFallsBackWholeBatchForClockSkew(t *testing.T) {
"created_at": invalidAt.Format(time.RFC3339Nano),
},
})).Want(http.StatusOK)
- fallbackAfter := time.Now().UTC()
+ var fallbackAfter time.Time
+ dbfx.QueryRow(t, `SELECT clock_timestamp()`).Scan(&fallbackAfter)
stored, err := testHandler.Queries.ListTaskMessages(context.Background(), util.MustParseUUID(taskID))
if err != nil {