Repository navigation
[CELEBORN-2557] Fix CLI process exit status - #3974
huangxiaopingRD wants to merge 2 commits into
Conversation
ed4c079 to
c72a163
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3974 +/- ##
============================================
+ Coverage 62.64% 62.87% +0.24%
Complexity 451 451
============================================
Files 407 407
Lines 29032 29037 +5
Branches 2858 2861 +3
============================================
+ Hits 18185 18255 +70
+ Misses 9467 9398 -69
- Partials 1380 1384 +4 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
c72a163 to
c5c07e2
Compare
pan3793
left a comment
There was a problem hiding this comment.
Passing picocli's status through looks correct. However, a few failure paths still exit 0, so shell scripts still can't detect them. Since that's the goal of this PR, please cover them here too:
- No subcommand:
celeborn-cliwith no args only callslogErrorinCelebornCli.run()and returns, so it exits 0. Please make it a usage error, e.g. inject@Specand throwParameterException(exit 2). - Server-side rejections: for
--exclude-worker,--remove-excluded-worker,--remove-workers-unavailable-info,--send-worker-event,--update-interruption-noticesand--unregister-shuffles, the master returnsHandleResponsewithsuccess = falseand HTTP 200 (WorkerResource,ShuffleResource).MasterSubcommandImpl.run()only prints the response, so these exit 0. Please fail the command whengetSuccessis false. - Config write failures:
CliConfigManager.saveConfigcatches and logs every exception, so--add-cluster-alias/--remove-cluster-aliasreport success and exit 0 even when the config file wasn't written. Please let the exception propagate.
Tests:
- The
TestCelebornCliCommandshelpers discard the value returned byexecute. Please assertCommandLine.ExitCode.OKincaptureOutputAndValidateResponseandCommandLine.ExitCode.USAGEincaptureErrorAndValidateResponse(all current error cases are usage errors). CelebornCliExitCodeSuitecovers only picocli's defaults. Please add the no-args case and an execution failure (e.g.master --show-workers --hostport 127.0.0.1:1->ExitCode.SOFTWARE), and useCommandLine.ExitCode.*instead of the literal2.captureErrorAndValidateResponsecallsSystem.setErr(...)and never restores it, so stderr output from the rest of the suite is lost. Since this PR touches the helper, please saveSystem.errand restore it in afinallyblock, and reusestderrPrintStreaminstead of creating a secondPrintStream.
@pan3793 Thanks for the review! I’ve updated the code to address your comments. Could you please take another look? |
pan3793
left a comment
There was a problem hiding this comment.
Thanks, all addressed. Two more on the tests:
-
CliConfigManager.cliConfigFilePathis avalfixed at class load to$HOME/.celeborn-cli.conf, and a JVM cannot change its own env vars, so in-process tests have no way to redirect it. As a result,TestCelebornCliCommandswrites theunit-testalias into the developer's real config file, and itsafterAllthen deletes the whole file, wiping any aliases they had configured. The subprocessHOMEoverride in this PR works around this for the new suite only.Please make the path overridable in tests only, following the same idea as Spark's
SparkConfWithEnv, e.g.def cliConfigFilePath: String = sys.props.get("celeborn.testing.cli.config.file") .filter(_ => sys.props.contains("celeborn.testing")) .getOrElse(s"${sys.env("HOME")}/.celeborn-cli.conf")
celeborn.testingis set byCelebornFunSuite, so production behavior is unchanged. It must be adefrather than aval, so the property is picked up whenever it is set. Then let the CLI suites extendCelebornFunSuite, set the property to a file under a temp directory inbeforeAll, and clear the property and delete the temp directory inafterAll, so no test touches$HOME. -
CelebornCliExitCodeSuitenow starts 18 JVMs (12 in the rejection test alone), which is overkill. Only theSystem.exitwiring inmainneeds a separate process. With 1 in place, please keep a single subprocess case (e.g.--unknown-option->ExitCode.USAGE) and check the rest in-process viaCelebornCli.execute, including the config-save failure case.
What changes were proposed in this pull request?
Pass the exit code returned by picocli to
System.exitinCelebornCli.main. Extract command execution into a package-private method for the existing in-process tests, and add process-level exit code tests.Why are the changes needed?
The CLI currently discards picocli's return value. For example,
celeborn-cli --unknown-optionreports an error but exits with status 0, so shell scripts cannot detect the failure. This change returns picocli's status to the shell.JIRA: https://issues.apache.org/jira/browse/CELEBORN-2557
Does this PR resolve a correctness bug?
Does this PR introduce any user-facing change?
How was this patch tested?
CelebornCliExitCodeSuite: 2 tests passed, covering--help(0) and an unknown option (2) in separate JVM processes.TestCelebornCliCommands: 49 tests passed and 1 existing test was canceled; the suite ran with an isolatedHOME.mvn -o -pl cli spotless:checkpassed.Both test suites were run with Maven using
-pl cli -am test -Dtest=none -Dcheckstyle.skip -Drat.skip=trueand the corresponding-DwildcardSuitesvalue.