-
Notifications
You must be signed in to change notification settings - Fork 25
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
WFQ Tests & Utilities #641
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a471a2b
Code in place, doesn't work yet
chuck-dbos 1ac2d93
Check more
chuck-dbos 4d46cb5
Remove console
chuck-dbos c908461
Utility function to query wfq
chuck-dbos 58b2259
Add a test for another interesting timing spot
chuck-dbos 32dece0
Merge remote-tracking branch 'origin/main' into chuck/debugpoint
chuck-dbos 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 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 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 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,76 @@ | ||
import { sleepms } from "./utils"; | ||
|
||
export function getCallSiteInfo(): { fileName: string; lineNumber: number } { | ||
const err = new Error(); | ||
const stack = err.stack?.split("\n"); | ||
|
||
if (stack && stack.length > 2) { | ||
// The third line usually contains the callsite information. | ||
// Different environments (Node, browser) format the stack trace differently. | ||
// Adjust the regex to your environment as needed. | ||
const match = stack[2].match(/at\s+(.*):(\d+):(\d+)/); | ||
if (match) { | ||
const fileName = match[1]; | ||
const lineNumber = parseInt(match[2], 10); | ||
return { fileName, lineNumber }; | ||
} | ||
} | ||
return { fileName: "unknown", lineNumber: -1 }; | ||
} | ||
|
||
export interface DebugPoint | ||
{ | ||
name: string; | ||
fileName: string; | ||
lineNumber: number; | ||
hitCount: number; | ||
} | ||
|
||
export class DebugAction | ||
{ | ||
sleepms?: number; // Sleep at point | ||
awaitEvent?: Promise<void>; // Wait at point | ||
callback?: () => void; | ||
asyncCallback?: () => Promise<void>; | ||
} | ||
|
||
export const pointTriggers: Map<string, DebugAction> = new Map() | ||
export const pointLocations: Map<string, DebugPoint> = new Map() | ||
|
||
export async function debugTriggerPoint(name: string): Promise<void> { | ||
const cpi = getCallSiteInfo() | ||
if (!pointLocations.has(name)) { | ||
pointLocations.set(name, {name, ...cpi, hitCount: 0}) | ||
} | ||
const p = pointLocations.get(name)! | ||
if (p.fileName !== cpi.fileName || cpi.lineNumber !== p.lineNumber) { | ||
throw new Error(`Duplicate debug point name: ${name}`); | ||
} | ||
|
||
if (pointTriggers.has(name)) { | ||
const pt = pointTriggers.get(name)!; | ||
if (pt.sleepms) { | ||
await sleepms(pt.sleepms); | ||
} | ||
if (pt.asyncCallback) { | ||
await pt.asyncCallback(); | ||
} | ||
if (pt.callback) { | ||
pt.callback(); | ||
} | ||
if (pt.awaitEvent) { | ||
await pt.awaitEvent; | ||
} | ||
} | ||
} | ||
|
||
export function setDebugTrigger(name: string, action: DebugAction) { | ||
pointTriggers.set(name, action); | ||
} | ||
|
||
export function clearDebugTriggers() { | ||
pointTriggers.clear(); | ||
} | ||
|
||
export const DEBUG_TRIGGER_WORKFLOW_QUEUE_START = "DEBUG_TRIGGER_WORKFLOW_QUEUE_START"; | ||
export const DEBUG_TRIGGER_WORKFLOW_ENQUEUE = "DEBUG_TRIGGER_WORKFLOW_ENQUEUE"; |
This file contains 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 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 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 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 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 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if this will add overhead to non-debug production workloads? If so, can we disable this in prod?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be extremely surprised if the overhead is measurable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case, where it is against several database updates, I agree. However, disabling in prod is not a bad idea.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could get it down to a boolean check pretty easily. But we can do it later.