test: add missing coverage for getTaskDuration#198
Open
Harshil-Malisetty wants to merge 2 commits intoNetflix:masterfrom
Open
test: add missing coverage for getTaskDuration#198Harshil-Malisetty wants to merge 2 commits intoNetflix:masterfrom
Harshil-Malisetty wants to merge 2 commits intoNetflix:masterfrom
Conversation
getTaskDuration had no test coverage despite handling multiple cases: completed tasks, running tasks (elapsed time), tasks with no timing fields, and the edge case where a completed task should not use elapsed time even when started_at is present.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Requirements for a pull request
Adds 10 Cypress component-level tests for the two pure utility functions in
src/utils/task.ts:getTaskId— resolves a display-friendly task identifiergetTaskDuration— returns a duration in milliseconds, with live-elapsed-time handling for running tasksNo production code was changed. This is a test-only PR.
Why this matters
getTaskDurationis called on every task row in the Timeline, DAG, and Task List views. A subtle regression (e.g. returningNaNor a negative number) would silently break duration columns across the UI. These tests lock down the existing behaviour so future changes — like addingkilledstatus support — can be made safely with regression coverage.What was added
getTaskIdreturnstask_namewhen present{ task_name: 'hello', task_id: 123 }'hello'getTaskIdfalls back totask_id{ task_id: 123 }'123'{ status: 'completed', duration: 5000 }5000{ status: 'completed', duration: undefined, finished_at: undefined }null{ status: 'failed', duration: undefined }nullstarted_at→ elapsed time{ status: 'running', started_at: Date.now() - 3000 }≈ 3000(±200 ms tolerance)started_at{ status: 'running', started_at: undefined }nullstarted_at{ status: 'completed', duration: 1000, started_at: Date.now() - 9999 }1000{ status: 'killed', duration: 4200 }4200{ status: 'killed', duration: undefined }nullTest infrastructure
createTask()fromsrc/utils/testhelper.ts— a factory that spreads partial overrides onto a defaultTaskobject, keeping each test focused on the fields under test.cypress.config.ts), executed vianpx cypress run --component.expect(...).to.equal(...)withgreaterThan/lessThanfor the elapsed-time tolerance window.Files changed
src/utils/__tests__/task.test.cypress.tsgetTaskIdandgetTaskDurationHow to verify
All 10 tests should pass green.
Design decisions
Killed-status tests (cases 9–10): The current
getTaskDurationimplementation doesn't branch on'killed'explicitly — killed tasks fall through to thetask.duration ? task.duration : nullpath. The tests document this existing behaviour so that whenkilledis added as a first-class status (PR feat: distinguish externally killed tasks from code failures (#84) #187), any logic change is caught by CI.Elapsed-time tolerance (±200 ms): Test 6 asserts the running-task elapsed duration is between 2800–3200 ms rather than an exact value, accounting for CI/test-execution jitter.
No mocking of
Date.now(): The tolerance approach was chosen over mocking to keep the test simple and closer to real runtime behaviour.