From 44ef4130267652268da5ee28300b77ac78dda06e Mon Sep 17 00:00:00 2001 From: gouravkrosx Date: Thu, 18 Apr 2024 19:46:43 +0530 Subject: [PATCH 1/2] feat: add closeDelay to support async calls coverage Signed-off-by: gouravkrosx --- v2/src/main/java/io/keploy/Keploy.java | 29 +++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/v2/src/main/java/io/keploy/Keploy.java b/v2/src/main/java/io/keploy/Keploy.java index 5aae90c..dca9777 100644 --- a/v2/src/main/java/io/keploy/Keploy.java +++ b/v2/src/main/java/io/keploy/Keploy.java @@ -30,12 +30,13 @@ public static class RunOptions { private int port; private String path; private String appCmd; + private int closeDelay; public RunOptions() { - this(10, false, 6789, "."); + this(10, false, 6789, ".",0); } - public RunOptions(int delay, boolean debug, int port, String path) { + public RunOptions(int delay, boolean debug, int port, String path,int closeDelay) { if (delay < 0) { throw new IllegalArgumentException("Delay must be a positive integer."); } @@ -52,6 +53,11 @@ public RunOptions(int delay, boolean debug, int port, String path) { throw new IllegalArgumentException("Port must be a positive integer."); } this.port = port; + + if (closeDelay < 0) { + throw new IllegalArgumentException("CloseDelay must be a positive integer."); + } + this.closeDelay = closeDelay; } // Getters and setters @@ -66,6 +72,17 @@ public void setDelay(int delay) { this.delay = delay; } + public int getCloseDelay() { + return closeDelay; + } + + public void setCloseDelay(int closeDelay) { + if (closeDelay < 0) { + throw new IllegalArgumentException("CloseDelay must be a positive integer."); + } + this.closeDelay = closeDelay; + } + public boolean isDebug() { return debug; } @@ -539,6 +556,12 @@ public static void runTests(String jarPath, RunOptions runOptions) { waitForTestRunCompletion(testRunId, testSet, appId); try { + if (runOptions.getCloseDelay() > 0){ + logger.info("waiting for {} seconds before closing the application in order to get coverage of async calls", runOptions.getCloseDelay()); + //wait for closeDelay in order to get coverage of async calls as well + Thread.sleep(runOptions.getCloseDelay() * 1000); + } + Keploy.FindCoverage(testSet); Thread.sleep(5000); @@ -546,7 +569,7 @@ public static void runTests(String jarPath, RunOptions runOptions) { } catch (Exception e) { e.printStackTrace(); } - + System.out.println("sleeping for 7 more seconds to get async call coverages"); String appErr = stopUserApplication(appId); if (appErr != null) { From e851ea5dc9ea99583b673f184e3666d9cb46c10c Mon Sep 17 00:00:00 2001 From: gouravkrosx Date: Thu, 18 Apr 2024 20:01:03 +0530 Subject: [PATCH 2/2] chore: format Signed-off-by: gouravkrosx --- v2/src/main/java/io/keploy/Keploy.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/v2/src/main/java/io/keploy/Keploy.java b/v2/src/main/java/io/keploy/Keploy.java index dca9777..cfd4c8c 100644 --- a/v2/src/main/java/io/keploy/Keploy.java +++ b/v2/src/main/java/io/keploy/Keploy.java @@ -33,7 +33,7 @@ public static class RunOptions { private int closeDelay; public RunOptions() { - this(10, false, 6789, ".",0); + this(10, false, 6789, ".", 0); } public RunOptions(int delay, boolean debug, int port, String path,int closeDelay) { @@ -569,7 +569,7 @@ public static void runTests(String jarPath, RunOptions runOptions) { } catch (Exception e) { e.printStackTrace(); } - System.out.println("sleeping for 7 more seconds to get async call coverages"); + String appErr = stopUserApplication(appId); if (appErr != null) {