Skip to content

Commit

Permalink
Fix the instability of testTonyAMStartupTimeoutShouldFail (#656)
Browse files Browse the repository at this point in the history
Signed-off-by: zhangjunfan <junfan.zhang@outlook.com>
  • Loading branch information
zuston authored Mar 13, 2022
1 parent 85ec144 commit bde8203
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 37 deletions.
10 changes: 10 additions & 0 deletions tony-core/src/main/java/com/linkedin/tony/TonyClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@ public class TonyClient implements AutoCloseable {
// For access from CLI.
private Set<TaskInfo> taskInfos = new HashSet<>();

// Just for test cases
private boolean makeAppStateAlwaysAccepted = false;

/**
* Gets default hadoop application classpath from yarnConf.
*/
Expand Down Expand Up @@ -1070,6 +1073,10 @@ public boolean monitorApplication() throws YarnException, IOException, Interrupt
ApplicationReport report = yarnClient.getApplicationReport(appId);

YarnApplicationState appState = report.getYarnApplicationState();
// Just for test the config of `tony.am.startup-timeout`
if (makeAppStateAlwaysAccepted) {
appState = YarnApplicationState.ACCEPTED;
}

FinalApplicationStatus finalApplicationStatus = report.getFinalApplicationStatus();
initRpcClientAndLogAMUrl(report);
Expand Down Expand Up @@ -1476,4 +1483,7 @@ public static void main(String[] args) {
System.exit(exitCode);
}

public void makeAppStateAlwaysAccepted(boolean appStateAlwaysAccepted) {
this.makeAppStateAlwaysAccepted = appStateAlwaysAccepted;
}
}
39 changes: 2 additions & 37 deletions tony-core/src/test/java/com/linkedin/tony/TestTonyE2E.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

import java.util.HashSet;

import com.linkedin.tony.util.Utils;
import org.apache.commons.cli.ParseException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
Expand All @@ -34,10 +33,6 @@
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.stream.Stream;

import static com.linkedin.tony.TaskExecutor.MARK_LOST_CONNECTION_ENV_KEY;
import static com.linkedin.tony.TonyConfigurationKeys.TASK_HEARTBEAT_INTERVAL_MS;
Expand Down Expand Up @@ -614,15 +609,10 @@ public void testTonyAllocationTimeoutShouldFail() throws ParseException, IOExcep
Assert.assertEquals(exitCode, -1);
}

@Test(timeOut = 60000)
@Test
public void testTonyAMStartupTimeoutShouldFail() throws ParseException, IOException {
/* Creating 10 jobs submitting to Yarn to make cluster fulfill. */
ExecutorService executorService = Executors.newFixedThreadPool(10);
Stream.iterate(0, n -> n + 1)
.limit(10)
.forEach(x -> mockedTask(executorService));

TonyClient client = new TonyClient(conf);
client.makeAppStateAlwaysAccepted(true);
client.init(new String[]{
"--src_dir", "tony-core/src/test/resources/scripts",
"--executes", "python check_env_and_venv.py",
Expand All @@ -636,31 +626,6 @@ public void testTonyAMStartupTimeoutShouldFail() throws ParseException, IOExcept
});
int exitCode = client.start();
Assert.assertEquals(exitCode, -1);

Utils.shutdownThreadPool(executorService);
}

private Future<?> mockedTask(ExecutorService service) {
return service.submit(() -> {
TonyClient client = new TonyClient(conf);
try {
client.init(new String[]{
"--src_dir", "tony-core/src/test/resources/scripts",
"--hdfs_classpath", libPath,
"--shell_env", "ENV_CHECK=ENV_CHECK",
"--container_env", Constants.SKIP_HADOOP_PATH + "=true",
"--python_venv", "tony-core/src/test/resources/test.zip",
"--conf", "tony.ps.instances=1",
"--conf", "tony.worker.instances=4",
"--conf", "tony.ps.command=python sleep_30.py",
"--conf", "tony.worker.command=python check_env_and_venv.py"
});
client.start();
} catch (Exception e) {
e.printStackTrace();
}
return;
});
}

/**
Expand Down

0 comments on commit bde8203

Please sign in to comment.