Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions qDup-core/src/main/java/io/hyperfoil/tools/qdup/cmd/impl/Sh.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

import java.util.*;

import static io.hyperfoil.tools.qdup.stream.SuffixStream.DEFAULT_DELAY;

public class Sh extends Cmd {

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

@Override
public void postRun(String output,Context context){

//turn off stream logging if enabled
if(context.getCoordinator().getGlobals().getSetting(Globals.STREAM_LOGGING,false)){
context.getShell().removeLineObserver("stream");
Expand All @@ -133,10 +136,27 @@ public void postRun(String output,Context context){
context.getShell().isPromptShell(getPreviousPrompt()) &&
context.getShell().getHost().isShell())
{

long start = System.currentTimeMillis();

// Combined exit code capture + pwd + exit code restore in a single shSync
// to reduce per-command overhead from 3 round-trips to 1
String combined = context.getShell().shSync("export __qdup_ec=$?; echo \"${__qdup_ec}:::$(pwd)\"; (exit $__qdup_ec)");

long round_trip_time = System.currentTimeMillis() - start;

round_trip_time = round_trip_time - context.getShell().getDelay();


if(round_trip_time > DEFAULT_DELAY){
round_trip_time = DEFAULT_DELAY;
}

if(round_trip_time > 0){
context.getShell().setDelay((int) round_trip_time);
}


String response = "";
String pwd = "";
boolean parsed = false;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package io.hyperfoil.tools.qdup.cmd.impl;


import com.oracle.truffle.api.library.GenerateLibrary;
import io.hyperfoil.tools.qdup.*;
import io.hyperfoil.tools.qdup.cmd.*;
import io.hyperfoil.tools.qdup.config.RunConfig;
import io.hyperfoil.tools.qdup.config.RunConfigBuilder;
import io.hyperfoil.tools.qdup.config.yaml.Parser;

import io.hyperfoil.tools.qdup.shell.AbstractShell;
import io.hyperfoil.tools.qdup.shell.SshShell;
import io.hyperfoil.tools.qdup.stream.SuffixStream;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

import static org.junit.Assert.*;
import org.junit.Test;

public class ShTest extends SshTestBase {

@Test
public void testExecutorDelay() throws InterruptedException {

AbstractShell shell = getSession();

Sh command = new Sh("echo Hello World");

RunConfigBuilder builder = getBuilder();
RunConfig runConfig = builder.buildConfig(Parser.getInstance());
Run run = new Run(
"/tmp/",
runConfig,
new Dispatcher()
);

CountDownLatch latch = new CountDownLatch(1);

ScriptContext context = new ScriptContext(
shell,
new State(""),
run,
new Profiles().get("ScriptContextTest"),
command,
false
)
{
@Override
public void next(String output) {
try {

super.next(output);
} finally {

latch.countDown();
}
}
};

command.run("", context);

boolean completed = latch.await(2, TimeUnit.SECONDS);
assertTrue("Command should complete within 2 seconds", completed);

int delay = shell.getDelay();

assertTrue("Delay should be less than or equal to DEFAULT_DELAY",
delay <= SuffixStream.DEFAULT_DELAY);
assertTrue("Delay should be positive",
delay > 0);

}
}
Loading