-
Notifications
You must be signed in to change notification settings - Fork 123
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
base: main
Are you sure you want to change the base?
Changes from all commits
3a3b6f5
617d1d3
ba053c3
8bd1547
1ad08e2
e0d4150
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| 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 |
| 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" | ||
| 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.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
|
|
||
| >>> errcode [CLI] current-user me | ||
| [PROCESS_KILLED] | ||
|
|
||
| Exit code: [KILLED] | ||
| Me attempt 1 done | ||
|
|
||
| >>> errcode [CLI] current-user me | ||
| [PROCESS_KILLED] | ||
|
|
||
| Exit code: [KILLED] | ||
| Me attempt 2 done | ||
|
|
||
| >>> [CLI] current-user me | ||
| { | ||
| "id":"123", | ||
| "userName":"test@example.com" | ||
| } | ||
| Me attempt 3 done - success! | ||
|
|
||
| >>> errcode [CLI] workspace list / | ||
| [PROCESS_KILLED] | ||
|
|
||
| Exit code: [KILLED] | ||
| Workspace attempt 1 done | ||
|
|
||
| >>> [CLI] workspace list / | ||
| ID Type Language Path | ||
| Workspace attempt 2 done - success! |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| # Test pattern 1: /Me endpoint (kills first 2, then allows) | ||
| trace errcode $CLI current-user me | ||
| echo "Me attempt 1 done" | ||
|
|
||
| trace errcode $CLI current-user me | ||
| echo "Me attempt 2 done" | ||
|
|
||
| trace $CLI current-user me | ||
| echo "Me attempt 3 done - success!" | ||
|
|
||
| # Test pattern 2: /workspace/list endpoint (kills first 1, then allows) | ||
| trace errcode $CLI workspace list / | ||
| echo "Workspace attempt 1 done" | ||
|
|
||
| trace $CLI workspace list / | ||
| echo "Workspace attempt 2 done - success!" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| # Test that multiple patterns can have independent KillCaller counts | ||
| # Pattern 1: Kill first 2 requests to /Me endpoint | ||
| # Pattern 2: Kill first 1 request to /workspace/list endpoint | ||
|
|
||
| [[Server]] | ||
| Pattern = "GET /api/2.0/preview/scim/v2/Me" | ||
| KillCaller = 2 | ||
| Response.Body = ''' | ||
| { | ||
| "id": "123", | ||
| "userName": "test@example.com" | ||
| } | ||
| ''' | ||
|
|
||
| [[Server]] | ||
| Pattern = "GET /api/2.0/workspace/list" | ||
| KillCaller = 1 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| 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! |
| 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!" |
| 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" | ||
| } | ||
| ''' |
| 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.
| 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 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| trace errcode $CLI workspace list / | ||
| echo "Script continued after kill" |
| 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 |
| 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())) | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.