-
Notifications
You must be signed in to change notification settings - Fork 5k
[Improvement-18034][alert] Add configurable timeout for script alert plugin #18050
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: dev
Are you sure you want to change the base?
Changes from all commits
124bf56
357592b
9b55f6c
0ace319
c824269
06d3685
b90a5bf
bffaefd
571b35a
7fae4d9
7dedc08
7093e8f
cd820d7
a11d3d5
d473c62
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,23 +17,54 @@ | |
|
|
||
| package org.apache.dolphinscheduler.plugin.alert.script; | ||
|
|
||
| import java.io.File; | ||
|
|
||
| import org.junit.jupiter.api.Assertions; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| /** | ||
| * ProcessUtilsTest | ||
| */ | ||
| public class ProcessUtilsTest { | ||
|
|
||
| private static final String rootPath = System.getProperty("user.dir"); | ||
| @Test | ||
| public void testExecuteScript() { | ||
| String javaBin = getJavaBin(); | ||
| String[] cmd = {javaBin, "-cp", System.getProperty("java.class.path"), | ||
| ProcessUtilsTest.class.getName() + "$SimpleMain"}; | ||
| ProcessUtils.ProcessExecutionResult executionResult = ProcessUtils.executeScript(60, cmd); | ||
| Assertions.assertFalse(executionResult.isTimedOut()); | ||
| Assertions.assertEquals(0, executionResult.getExitCode()); | ||
| } | ||
|
|
||
| private static final String shellFilPath = | ||
| rootPath + "/dolphinscheduler-alert-plugins/dolphinscheduler-alert-script/src/test/script/shell/test.sh"; | ||
| @Test | ||
| public void testExecuteScriptTimeout() { | ||
| String javaBin = getJavaBin(); | ||
| String[] sleepCmd = {javaBin, "-cp", System.getProperty("java.class.path"), | ||
| ProcessUtilsTest.class.getName() + "$SleepMain"}; | ||
| ProcessUtils.ProcessExecutionResult executionResult = ProcessUtils.executeScript(2, sleepCmd); | ||
| Assertions.assertTrue(executionResult.isTimedOut()); | ||
| Assertions.assertNull(executionResult.getExitCode()); | ||
| } | ||
|
SbloodyS marked this conversation as resolved.
|
||
|
|
||
| private String[] cmd = {"/bin/sh", "-c", shellFilPath + " -t 1"}; | ||
| private static String getJavaBin() { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as #18050 (comment)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||
| String executableName = System.getProperty("os.name").toLowerCase().contains("win") | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as #18050 (comment) |
||
| ? "java.exe" | ||
| : "java"; | ||
| return System.getProperty("java.home") + File.separator + "bin" + File.separator + executableName; | ||
| } | ||
|
|
||
| @Test | ||
| public void testExecuteScript() { | ||
| int code = ProcessUtils.executeScript(cmd); | ||
| assert code != -1; | ||
| public static class SimpleMain { | ||
|
|
||
| public static void main(String[] args) { | ||
| // Intentionally empty, returning with 0 means success. | ||
| } | ||
| } | ||
|
|
||
| public static class SleepMain { | ||
|
|
||
| public static void main(String[] args) throws InterruptedException { | ||
| Thread.sleep(30_000L); | ||
| } | ||
| } | ||
| } | ||
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.
It is best to tell the user the meaning of the exit code in the document.