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 the instability of testTonyAMStartupTimeoutShouldFail #656

Merged
merged 1 commit into from
Mar 13, 2022
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
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