fix(orchestration): test poll/validate schedules carry the retry round
jobs.idempotency_key is globally unique, but test-poll:<pub>:<seq> and test-validate:<pub>:<seq> were reused verbatim by every manual retry. The first round's completed rows made ON CONFLICT DO NOTHING silently swallow the next round's schedule SQL: a retried publication re-uploaded, polled once, and then froze in pending/uploaded with no successor job and no error. Keys and job ids are now derived from (publication, retry_count, sequence) inside the schedule SQL so every retry round owns fresh orchestration rows.
This commit is contained in:
@@ -64,14 +64,14 @@ func TestRecordUploadAndSchedulePollIsAtomicAndIdempotent(t *testing.T) {
|
||||
if updateAt < 0 || insertAt < 0 || updateAt >= insertAt {
|
||||
t.Fatalf("atomic SQL missing ordered update/insert: %q", recordUploadAndSchedulePollSQL)
|
||||
}
|
||||
if db.queryRowSQL != recordUploadAndSchedulePollSQL || len(db.queryRowArgs) != 9 {
|
||||
if db.queryRowSQL != recordUploadAndSchedulePollSQL || len(db.queryRowArgs) != 7 {
|
||||
t.Fatalf("query = %q %#v", db.queryRowSQL, db.queryRowArgs)
|
||||
}
|
||||
if db.queryRowArgs[8] != "test-poll:publication-1:1" {
|
||||
t.Fatalf("idempotency key = %#v", db.queryRowArgs[8])
|
||||
if !strings.Contains(recordUploadAndSchedulePollSQL, "'test-poll:' || $1 || ':' || updated.retry_count || ':1'") {
|
||||
t.Fatalf("poll schedule key must carry the retry round: %q", recordUploadAndSchedulePollSQL)
|
||||
}
|
||||
var payload map[string]any
|
||||
if err := json.Unmarshal(db.queryRowArgs[4].([]byte), &payload); err != nil {
|
||||
if err := json.Unmarshal(db.queryRowArgs[3].([]byte), &payload); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(payload) != 2 || payload["publication_id"] != "publication-1" || payload["sequence"] != float64(1) {
|
||||
@@ -102,11 +102,11 @@ func TestRecordRemoteStatusSchedulesNextSequenceAtomically(t *testing.T) {
|
||||
if !strings.Contains(recordRemoteStatusAndScheduleNextPollSQL, "poll_sequence = $2") || !strings.Contains(recordRemoteStatusAndScheduleNextPollSQL, "INSERT INTO jobs") {
|
||||
t.Fatalf("SQL lacks sequence guard or atomic enqueue: %q", recordRemoteStatusAndScheduleNextPollSQL)
|
||||
}
|
||||
if db.queryRowSQL != recordRemoteStatusAndScheduleNextPollSQL || len(db.queryRowArgs) != 11 {
|
||||
if db.queryRowSQL != recordRemoteStatusAndScheduleNextPollSQL || len(db.queryRowArgs) != 9 {
|
||||
t.Fatalf("query = %q %#v", db.queryRowSQL, db.queryRowArgs)
|
||||
}
|
||||
if db.queryRowArgs[10] != "test-poll:publication-1:2" {
|
||||
t.Fatalf("idempotency key = %#v", db.queryRowArgs[10])
|
||||
if !strings.Contains(recordRemoteStatusAndScheduleNextPollSQL, "'test-poll:' || $1 || ':' || updated.retry_count || ':' || updated.poll_sequence") {
|
||||
t.Fatalf("next-poll schedule key must carry the retry round: %q", recordRemoteStatusAndScheduleNextPollSQL)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,17 +123,17 @@ func TestRecordCompletedSchedulesValidationAtomically(t *testing.T) {
|
||||
if !strings.Contains(recordCompletedAndScheduleValidationSQL, "processing_state = 'completed'") || !strings.Contains(recordCompletedAndScheduleValidationSQL, "'test.validate'") {
|
||||
t.Fatalf("SQL lacks completed update or validation enqueue: %q", recordCompletedAndScheduleValidationSQL)
|
||||
}
|
||||
if !strings.Contains(recordCompletedAndScheduleValidationSQL, "parser_generation = $11") || !strings.Contains(recordCompletedAndScheduleValidationSQL, "index_generation = $12") {
|
||||
if !strings.Contains(recordCompletedAndScheduleValidationSQL, "parser_generation = $7") || !strings.Contains(recordCompletedAndScheduleValidationSQL, "index_generation = $8") {
|
||||
t.Fatalf("SQL lacks release generation stamping: %q", recordCompletedAndScheduleValidationSQL)
|
||||
}
|
||||
if db.queryRowSQL != recordCompletedAndScheduleValidationSQL || len(db.queryRowArgs) != 12 {
|
||||
if db.queryRowSQL != recordCompletedAndScheduleValidationSQL || len(db.queryRowArgs) != 10 {
|
||||
t.Fatalf("query = %q %#v", db.queryRowSQL, db.queryRowArgs)
|
||||
}
|
||||
if db.queryRowArgs[9] != "test-validate:publication-1:3" {
|
||||
t.Fatalf("idempotency key = %#v", db.queryRowArgs[9])
|
||||
if db.queryRowArgs[6] != "weknora-v0.7.1-m74@2026-09-04T02:06:59Z" || db.queryRowArgs[7] != "weknora-v0.7.1-m74@2026-09-04T02:06:59Z" {
|
||||
t.Fatalf("generation args = %#v", db.queryRowArgs[6:])
|
||||
}
|
||||
if db.queryRowArgs[10] != "weknora-v0.7.1-m74@2026-09-04T02:06:59Z" || db.queryRowArgs[11] != "weknora-v0.7.1-m74@2026-09-04T02:06:59Z" {
|
||||
t.Fatalf("generation args = %#v", db.queryRowArgs[10:])
|
||||
if !strings.Contains(recordCompletedAndScheduleValidationSQL, "'test-validate:' || $1 || ':' || updated.retry_count || ':' || updated.poll_sequence") {
|
||||
t.Fatalf("validate schedule key must carry the retry round: %q", recordCompletedAndScheduleValidationSQL)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user