Skip to content
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

fix: keploy fails to stop when tests end #156

Merged
merged 1 commit into from
Sep 28, 2023
Merged

Conversation

gouravkrosx
Copy link
Member

Related Issue

  • Keploy fails to stop when tests end. This happens in the case of Junit integration with keploy.

Closes: keploy/keploy#864

Describe the changes you've made

  • Added a function to not just kill the parent but child processes sharing the same running port.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Code style update (formatting, local variables)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist:

  • My code follows the style guidelines of this project.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas and used java doc.
  • I have made corresponding changes to the documentation.
  • My changes generate no new warnings.
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing unit tests pass locally with my changes.

Screenshots (if any)

Original Updated
original screenshot updated screenshot

try {
Process process = Runtime.getRuntime().exec(command);
Process process = new ProcessBuilder("sh", "-c", "lsof -t -i:" + port).start();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [checkstyle] <com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck> reported by reviewdog 🐶
Line is longer than 80 characters (found 91).

}
} catch (Exception e) {
e.printStackTrace();
System.err.println("Failed to fetch the process ID on port " + port);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [checkstyle] <com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck> reported by reviewdog 🐶
Line is longer than 80 characters (found 81).

}
}

public static void killProcessesAndTheirChildren(int parentPID) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [checkstyle] <com.puppycrawl.tools.checkstyle.checks.javadoc.MissingJavadocMethodCheck> reported by reviewdog 🐶
Missing a Javadoc comment.

}
}

public static void killProcessesAndTheirChildren(int parentPID) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [checkstyle] <com.puppycrawl.tools.checkstyle.checks.FinalParametersCheck> reported by reviewdog 🐶
Parameter parentPID should be final.

for (int childPID : pids) {
if (childPID != getCurrentPid()) {
try {
new ProcessBuilder("sudo", "kill", "-9", String.valueOf(childPID)).start();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [checkstyle] <com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck> reported by reviewdog 🐶
Line is longer than 80 characters (found 95).

}
}

private static void forceKillProcessByPID(String pid) {
public static void findAndCollectChildProcesses(String parentPID, List<Integer> pids) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [checkstyle] <com.puppycrawl.tools.checkstyle.checks.javadoc.MissingJavadocMethodCheck> reported by reviewdog 🐶
Missing a Javadoc comment.

}
}

private static void forceKillProcessByPID(String pid) {
public static void findAndCollectChildProcesses(String parentPID, List<Integer> pids) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [checkstyle] <com.puppycrawl.tools.checkstyle.checks.FinalParametersCheck> reported by reviewdog 🐶
Parameter parentPID should be final.

}
}

private static void forceKillProcessByPID(String pid) {
public static void findAndCollectChildProcesses(String parentPID, List<Integer> pids) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [checkstyle] <com.puppycrawl.tools.checkstyle.checks.FinalParametersCheck> reported by reviewdog 🐶
Parameter pids should be final.

logger.debug("cmd to kill:{}",cmd);
Runtime.getRuntime().exec("kill -9 " + pid);
pids.add(Integer.parseInt(parentPID));
Process process = new ProcessBuilder("pgrep", "-P", parentPID).start();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [checkstyle] <com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck> reported by reviewdog 🐶
Line is longer than 80 characters (found 83).

Runtime.getRuntime().exec("kill -9 " + pid);
pids.add(Integer.parseInt(parentPID));
Process process = new ProcessBuilder("pgrep", "-P", parentPID).start();
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [checkstyle] <com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck> reported by reviewdog 🐶
Line is longer than 80 characters (found 104).

@gouravkrosx gouravkrosx merged commit 48d2cfe into main Sep 28, 2023
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[bug]: keploy process doesn't stop after running tests along with unit tests in java
1 participant