Repair duration display for bad stopped timestamps (#37121)
Workflow run, job, task, and step durations could show **negative** values (e.g. `-50s`) when `Stopped` was missing, zero (epoch), or **before** `Started` (clock skew, races, reruns). The UI used `calculateDuration` with no validation. This change: - Uses each row`s **Updated** timestamp as a **fallback end time** when `Stopped` is invalid but the status is terminal, so duration approximates elapsed time instead of `0s` or a negative. - Keeps **`ActionRun.Duration()`** clamped to **≥ 0** when `PreviousDuration` plus the current segment would still be negative (legacy bad data). Fixes #34582. Co-authored-by: Composer <composer@cursor.com> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
@@ -5,10 +5,12 @@ package actions
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
"code.gitea.io/gitea/modules/timeutil"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
@@ -33,3 +35,13 @@ func TestUpdateRepoRunsNumbers(t *testing.T) {
|
||||
assert.Equal(t, 5, repo.NumActionRuns)
|
||||
assert.Equal(t, 3, repo.NumClosedActionRuns)
|
||||
}
|
||||
|
||||
func TestActionRun_Duration_NonNegative(t *testing.T) {
|
||||
run := &ActionRun{
|
||||
Started: timeutil.TimeStamp(100),
|
||||
Stopped: timeutil.TimeStamp(200),
|
||||
Status: StatusSuccess,
|
||||
PreviousDuration: -time.Hour,
|
||||
}
|
||||
assert.Equal(t, time.Duration(0), run.Duration())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user