Skip to content

Commit 288579f

Browse files
Arjun-Parmaniwillr3
authored andcommitted
Manually updating Executor delay by calculating total round trip time taken for shSync
1 parent 0c5f680 commit 288579f

2 files changed

Lines changed: 94 additions & 0 deletions

File tree

  • qDup-core/src
    • main/java/io/hyperfoil/tools/qdup/cmd/impl
    • test/java/io/hyperfoil/tools/qdup/cmd/impl

qDup-core/src/main/java/io/hyperfoil/tools/qdup/cmd/impl/Sh.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
import java.util.*;
1212

13+
import static io.hyperfoil.tools.qdup.stream.SuffixStream.DEFAULT_DELAY;
14+
1315
public class Sh extends Cmd {
1416

1517
private String command;
@@ -121,6 +123,7 @@ public String getLogOutput(String output,Context context){
121123

122124
@Override
123125
public void postRun(String output,Context context){
126+
124127
//turn off stream logging if enabled
125128
if(context.getCoordinator().getGlobals().getSetting(Globals.STREAM_LOGGING,false)){
126129
context.getShell().removeLineObserver("stream");
@@ -133,10 +136,27 @@ public void postRun(String output,Context context){
133136
context.getShell().isPromptShell(getPreviousPrompt()) &&
134137
context.getShell().getHost().isShell())
135138
{
139+
140+
long start = System.currentTimeMillis();
141+
136142
// Combined exit code capture + pwd + exit code restore in a single shSync
137143
// to reduce per-command overhead from 3 round-trips to 1
138144
String combined = context.getShell().shSync("export __qdup_ec=$?; echo \"${__qdup_ec}:::$(pwd)\"; (exit $__qdup_ec)");
139145

146+
long round_trip_time = System.currentTimeMillis() - start;
147+
148+
round_trip_time = round_trip_time - context.getShell().getDelay();
149+
150+
151+
if(round_trip_time > DEFAULT_DELAY){
152+
round_trip_time = DEFAULT_DELAY;
153+
}
154+
155+
if(round_trip_time > 0){
156+
context.getShell().setDelay((int) round_trip_time);
157+
}
158+
159+
140160
String response = "";
141161
String pwd = "";
142162
boolean parsed = false;
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package io.hyperfoil.tools.qdup.cmd.impl;
2+
3+
4+
import com.oracle.truffle.api.library.GenerateLibrary;
5+
import io.hyperfoil.tools.qdup.*;
6+
import io.hyperfoil.tools.qdup.cmd.*;
7+
import io.hyperfoil.tools.qdup.config.RunConfig;
8+
import io.hyperfoil.tools.qdup.config.RunConfigBuilder;
9+
import io.hyperfoil.tools.qdup.config.yaml.Parser;
10+
11+
import io.hyperfoil.tools.qdup.shell.AbstractShell;
12+
import io.hyperfoil.tools.qdup.shell.SshShell;
13+
import io.hyperfoil.tools.qdup.stream.SuffixStream;
14+
15+
import java.util.concurrent.CountDownLatch;
16+
import java.util.concurrent.TimeUnit;
17+
18+
import static org.junit.Assert.*;
19+
import org.junit.Test;
20+
21+
public class ShTest extends SshTestBase {
22+
23+
@Test
24+
public void testExecutorDelay() throws InterruptedException {
25+
26+
AbstractShell shell = getSession();
27+
28+
Sh command = new Sh("echo Hello World");
29+
30+
RunConfigBuilder builder = getBuilder();
31+
RunConfig runConfig = builder.buildConfig(Parser.getInstance());
32+
Run run = new Run(
33+
"/tmp/",
34+
runConfig,
35+
new Dispatcher()
36+
);
37+
38+
CountDownLatch latch = new CountDownLatch(1);
39+
40+
ScriptContext context = new ScriptContext(
41+
shell,
42+
new State(""),
43+
run,
44+
new Profiles().get("ScriptContextTest"),
45+
command,
46+
false
47+
)
48+
{
49+
@Override
50+
public void next(String output) {
51+
try {
52+
53+
super.next(output);
54+
} finally {
55+
56+
latch.countDown();
57+
}
58+
}
59+
};
60+
61+
command.run("", context);
62+
63+
boolean completed = latch.await(2, TimeUnit.SECONDS);
64+
assertTrue("Command should complete within 2 seconds", completed);
65+
66+
int delay = shell.getDelay();
67+
68+
assertTrue("Delay should be less than or equal to DEFAULT_DELAY",
69+
delay <= SuffixStream.DEFAULT_DELAY);
70+
assertTrue("Delay should be positive",
71+
delay > 0);
72+
73+
}
74+
}

0 commit comments

Comments
 (0)