-
Notifications
You must be signed in to change notification settings - Fork 122
Add KillCaller feature to test server for CLI crash recovery testing #4146
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
Open
varundeepsaini
wants to merge
5
commits into
databricks:main
Choose a base branch
from
varundeepsaini:ft/server-crash-acceptance
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
3a3b6f5
Add KillCaller feature to test server for CLI crash recovery testing
varundeepsaini 617d1d3
Removed other signals and now only killing is supported
varundeepsaini ba053c3
Fixed windows tests
varundeepsaini 8bd1547
Updated KillCaller to int and addressed comments
varundeepsaini 1ad08e2
cleanup
varundeepsaini 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,6 @@ | ||
|
|
||
| >>> errcode [CLI] current-user me | ||
| [PROCESS_KILLED] | ||
|
|
||
| Exit code: [KILLED] | ||
| Script continued after kill |
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,2 @@ | ||
| trace errcode $CLI current-user me | ||
| echo "Script continued after kill" | ||
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,4 @@ | ||
| # Kill the CLI when it calls /Me endpoint (once, then allow) | ||
| [[Server]] | ||
| Pattern = "GET /api/2.0/preview/scim/v2/Me" | ||
| KillCaller = 1 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,25 @@ | ||
|
|
||
| >>> errcode [CLI] current-user me | ||
| [PROCESS_KILLED] | ||
|
|
||
| Exit code: [KILLED] | ||
| Attempt 1 done | ||
|
|
||
| >>> errcode [CLI] current-user me | ||
| [PROCESS_KILLED] | ||
|
|
||
| Exit code: [KILLED] | ||
| Attempt 2 done | ||
|
|
||
| >>> errcode [CLI] current-user me | ||
| [PROCESS_KILLED] | ||
|
|
||
| Exit code: [KILLED] | ||
| Attempt 3 done | ||
|
|
||
| >>> [CLI] current-user me | ||
| { | ||
| "id":"123", | ||
| "userName":"test@example.com" | ||
| } | ||
| Attempt 4 done - success! |
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,13 @@ | ||
| # First 3 attempts should be killed | ||
| trace errcode $CLI current-user me | ||
| echo "Attempt 1 done" | ||
|
|
||
| trace errcode $CLI current-user me | ||
| echo "Attempt 2 done" | ||
|
|
||
| trace errcode $CLI current-user me | ||
| echo "Attempt 3 done" | ||
|
|
||
| # 4th attempt should succeed | ||
| trace $CLI current-user me | ||
| echo "Attempt 4 done - success!" |
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,10 @@ | ||
| # Kill the CLI 3 times, then allow the 4th request to succeed | ||
| [[Server]] | ||
| Pattern = "GET /api/2.0/preview/scim/v2/Me" | ||
| KillCaller = 3 | ||
| Response.Body = ''' | ||
| { | ||
| "id": "123", | ||
| "userName": "test@example.com" | ||
| } | ||
| ''' |
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,30 @@ | ||
| # KillCaller tests verify the test server's ability to terminate CLI processes mid-request. | ||
| # This enables testing crash recovery scenarios, e.g., "bundle deploy" fails on first attempt | ||
| # but succeeds on retry. Each subdirectory tests a different endpoint or retry count. | ||
|
|
||
| Local = true | ||
varundeepsaini marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Env.DATABRICKS_CLI_TEST_PID = "1" | ||
|
|
||
| [[Repls]] | ||
| # macOS bash shows "Killed: 9" (with signal number), Linux shows "Killed" | ||
| # Normalize the whole killed line to a placeholder | ||
| Old = 'script: line \d+:\s+\d+ Killed(: 9)?\s+"\$@"' | ||
| New = '[PROCESS_KILLED]' | ||
|
|
||
| [[Repls]] | ||
| # On Windows, there's no "Killed" message - just empty line before Exit code | ||
| # Insert [PROCESS_KILLED] placeholder for consistency | ||
| Old = '(\n>>> errcode [^\n]+\n)\nExit code:' | ||
| New = """${1}[PROCESS_KILLED] | ||
|
|
||
| Exit code:""" | ||
|
|
||
| [[Repls]] | ||
| # Normalize exit code: 137 on Unix (128 + SIGKILL), 1 on Windows | ||
| Old = 'Exit code: (137|1)' | ||
| New = 'Exit code: [KILLED]' | ||
|
|
||
| [[Repls]] | ||
| # Normalize Windows line endings (CRLF -> LF) - must be LAST | ||
| Old = "\r" | ||
| New = '' | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,6 @@ | ||
|
|
||
| >>> errcode [CLI] workspace list / | ||
| [PROCESS_KILLED] | ||
|
|
||
| Exit code: [KILLED] | ||
| Script continued after kill |
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,2 @@ | ||
| trace errcode $CLI workspace list / | ||
| echo "Script continued after kill" |
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,4 @@ | ||
| # Kill the CLI when it calls workspace list endpoint (once, then allow) | ||
| [[Server]] | ||
| Pattern = "GET /api/2.0/workspace/list" | ||
| KillCaller = 1 |
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,28 @@ | ||
| package root | ||
|
|
||
| import ( | ||
| "context" | ||
| "os" | ||
| "strconv" | ||
|
|
||
| "github.com/databricks/cli/libs/env" | ||
| "github.com/databricks/databricks-sdk-go/useragent" | ||
| ) | ||
|
|
||
| const ( | ||
| // TestPidEnvVar is the environment variable that enables PID injection into the user agent. | ||
| // When set to "1", the CLI will include its process ID in the user agent string. | ||
| // This is used by the test server to identify and signal the CLI process. | ||
| TestPidEnvVar = "DATABRICKS_CLI_TEST_PID" | ||
| testPidKey = "test-pid" | ||
| ) | ||
|
|
||
| // InjectTestPidToUserAgent adds the current process ID to the user agent if | ||
| // DATABRICKS_CLI_TEST_PID=1 is set. This enables the test server to identify | ||
| // and signal this process during acceptance tests. | ||
| func InjectTestPidToUserAgent(ctx context.Context) context.Context { | ||
| if env.Get(ctx, TestPidEnvVar) != "1" { | ||
| return ctx | ||
| } | ||
| return useragent.InContext(ctx, testPidKey, strconv.Itoa(os.Getpid())) | ||
| } |
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
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.