-
Notifications
You must be signed in to change notification settings - Fork 80
Add heartbeat to background worker epoch sentinel #42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| -- Test: Worker heartbeat liveness (last_seen_at advances over time) | ||
| -- Validates that the background worker updates df._worker_epoch.last_seen_at | ||
| -- on each poll tick (~5 seconds). | ||
| -- Requires superuser: reads internal df._worker_epoch table. | ||
|
|
||
| DO $$ | ||
| DECLARE | ||
| ts1 TIMESTAMPTZ; | ||
| ts2 TIMESTAMPTZ; | ||
| attempts INT := 0; | ||
| BEGIN | ||
| -- Wait for sentinel row to appear (worker may still be initializing) | ||
| LOOP | ||
| SELECT last_seen_at INTO ts1 FROM df._worker_epoch LIMIT 1; | ||
| EXIT WHEN ts1 IS NOT NULL OR attempts >= 150; | ||
| PERFORM pg_sleep(0.1); | ||
| attempts := attempts + 1; | ||
| END LOOP; | ||
|
|
||
| IF ts1 IS NULL THEN | ||
| RAISE EXCEPTION 'TEST FAILED: no sentinel row after 15s — worker not running'; | ||
| END IF; | ||
|
|
||
| -- Wait for last_seen_at to advance (poll tick is ~5s, allow up to 15s) | ||
| attempts := 0; | ||
| LOOP | ||
| PERFORM pg_sleep(1); | ||
| attempts := attempts + 1; | ||
|
|
||
| SELECT last_seen_at INTO ts2 FROM df._worker_epoch LIMIT 1; | ||
| EXIT WHEN ts2 > ts1 OR attempts >= 15; | ||
| END LOOP; | ||
|
|
||
| IF ts2 <= ts1 THEN | ||
| RAISE EXCEPTION 'TEST FAILED: last_seen_at did not advance after 15s (ts1=%, ts2=%)', ts1, ts2; | ||
| END IF; | ||
|
|
||
| RAISE NOTICE 'PASSED: last_seen_at advanced from % to % after % seconds', ts1, ts2, attempts; | ||
| END $$; | ||
|
|
||
| SELECT 'TEST PASSED' AS result; |
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.
Uh oh!
There was an error while loading. Please reload this page.