mirror of
https://github.com/go-gitea/gitea.git
synced 2026-11-02 09:25:35 +01:00
Default-branch pushes and Actions unit saves recreated the repository's schedules with `Next` recomputed from that moment, so a push between a cron's due minute and the scheduler's pass skipped the occurrence, and `@every` timers restarted. Re-registration now updates schedule rows in place and keeps the spec rows of unchanged crons, so their cursor survives and an in-flight scheduler pass still finds its schedule. Re-detection also clears schedules when no scheduled workflow remains. Fixes https://github.com/go-gitea/gitea/issues/40062 Written with AI assistance. --------- Co-authored-by: silverwind <me@silverwind.io> Co-authored-by: Claude (Opus 5.5) <noreply@anthropic.com>
44 lines
1.5 KiB
Go
44 lines
1.5 KiB
Go
// Copyright 2026 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package actions
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"gitea.dev/models/unittest"
|
|
"gitea.dev/modules/timeutil"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestReplaceScheduleTasksByRepo(t *testing.T) {
|
|
require.NoError(t, unittest.PrepareTestDatabase())
|
|
|
|
const repoID = 4711
|
|
register := func(commitSHA, spec string) {
|
|
require.NoError(t, ReplaceScheduleTasksByRepo(t.Context(), repoID, []*ActionSchedule{
|
|
{RepoID: repoID, WorkflowID: "nightly.yml", CommitSHA: commitSHA, Specs: []string{spec}},
|
|
}))
|
|
}
|
|
|
|
register("c1", "17 */6 * * *")
|
|
spec := unittest.AssertExistsAndLoadBean(t, &ActionScheduleSpec{RepoID: repoID})
|
|
spec.Next = timeutil.TimeStamp(time.Now().Add(-time.Minute).Unix())
|
|
require.NoError(t, UpdateScheduleSpec(t.Context(), spec, "next"))
|
|
|
|
register("c2", "17 */6 * * *")
|
|
unittest.AssertExistsAndLoadBean(t, &ActionSchedule{ID: spec.ScheduleID, CommitSHA: "c2"})
|
|
unittest.AssertExistsAndLoadBean(t, &ActionScheduleSpec{ID: spec.ID, ScheduleID: spec.ScheduleID, Next: spec.Next})
|
|
|
|
register("c3", "23 */6 * * *")
|
|
unittest.AssertNotExistsBean(t, &ActionScheduleSpec{ID: spec.ID})
|
|
assert.Greater(t, unittest.AssertExistsAndLoadBean(t, &ActionScheduleSpec{RepoID: repoID}).Next, spec.Next)
|
|
|
|
require.NoError(t, ReplaceScheduleTasksByRepo(t.Context(), repoID, nil))
|
|
unittest.AssertNotExistsBean(t, &ActionSchedule{RepoID: repoID})
|
|
unittest.AssertNotExistsBean(t, &ActionScheduleSpec{RepoID: repoID})
|
|
}
|