уничтожение процесса тестирования.
This commit is contained in:
@@ -1,22 +1,6 @@
|
||||
package Common.Constants;
|
||||
import java.util.regex.Pattern;
|
||||
public class Constants {
|
||||
public static final int Nan = -1;
|
||||
public static char toStrike = (char) 822;
|
||||
public static final Pattern VALID_EMAIL_ADDRESS_REGEX =
|
||||
Pattern.compile("^[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,6}$", Pattern.CASE_INSENSITIVE);
|
||||
public static char[] forbidden_file_name_characters = new char[]{
|
||||
'#', '%', '&', '{', '}',
|
||||
'<', '>', '*', '?', '!',
|
||||
'$', '\'', '\"', '@', '+',
|
||||
'`', '|', '=', '#', ':', '/', '\\',
|
||||
'~', '^'
|
||||
};
|
||||
public static char[] regular_metasymbols = new char[]{
|
||||
'<', '>', '(', ')', '[', ']', '{', '}', '^', '-', '=', '$', '!', '|', '?', '*', '+', '.'
|
||||
};
|
||||
//все запретные символы через пробел.
|
||||
public static String all_forbidden_characters_string = "";
|
||||
//https://losst.ru/komandy-terminala-linux
|
||||
public static String[] linux_system_commands = new String[]{
|
||||
//<editor-fold desc="все линуксовые команды. их МНОГО">
|
||||
@@ -355,4 +339,21 @@ public class Constants {
|
||||
"zypper"
|
||||
//</editor-fold>
|
||||
};
|
||||
public static final int Nan = -1;
|
||||
public static char toStrike = (char) 822;
|
||||
public static final Pattern VALID_EMAIL_ADDRESS_REGEX =
|
||||
Pattern.compile("^[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,6}$", Pattern.CASE_INSENSITIVE);
|
||||
public static char[] forbidden_file_name_characters = new char[]{
|
||||
'#', '%', '&', '{', '}',
|
||||
'<', '>', '*', '?', '!',
|
||||
'$', '\'', '\"', '@', '+',
|
||||
'`', '|', '=', '#', ':', '/', '\\',
|
||||
'~', '^'
|
||||
};
|
||||
public static char[] regular_metasymbols = new char[]{
|
||||
'<', '>', '(', ')', '[', ']', '{', '}', '^', '-', '=', '$', '!', '|', '?', '*', '+', '.'
|
||||
};
|
||||
//все запретные символы через пробел.
|
||||
public static String all_forbidden_characters_string = "";
|
||||
public static String aborted = "ABORTED";
|
||||
}
|
||||
|
||||
@@ -345,6 +345,7 @@ public class Global {
|
||||
System.exit(0);
|
||||
}
|
||||
public static void ScenarioMode() throws Exception {
|
||||
isWindows = System.getProperty("os.name").startsWith("Windows");
|
||||
Log = new Loggable() {
|
||||
@Override
|
||||
public String getLogHomePath() {
|
||||
|
||||
@@ -6,7 +6,6 @@ import java.io.File;
|
||||
import java.util.concurrent.Callable;
|
||||
public class InterruptThread extends Thread{
|
||||
//------------
|
||||
public static final String Eliminated = "Eliminated";
|
||||
public InterruptThread(int sleep_ms, Callable action){
|
||||
super(() -> {
|
||||
File interruptFile = new File(db_project_info.interrupt);
|
||||
@@ -14,7 +13,7 @@ public class InterruptThread extends Thread{
|
||||
while (true) {
|
||||
Thread.sleep(sleep_ms);
|
||||
if (interruptFile.exists()) {
|
||||
FileUtils.writeStringToFile(new File(Eliminated + " by INTERRUPT file"), "");
|
||||
FileUtils.writeStringToFile(new File("ABORTED"), "");
|
||||
FileUtils.forceDelete(interruptFile);
|
||||
action.call();
|
||||
}
|
||||
|
||||
@@ -4,8 +4,10 @@ import com.google.gson.annotations.Expose;
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
public class SapforScenario_json {
|
||||
@Expose
|
||||
public String sapfor_drv = ""; //файл с сапфором. Имя уникально для сценария.
|
||||
@Expose
|
||||
public List<String> tests = new Vector<>();
|
||||
@Expose
|
||||
public List<SapforPackage_json> packages= new Vector<>();
|
||||
public List<SapforPackage_json> packages = new Vector<>();
|
||||
}
|
||||
|
||||
@@ -9,16 +9,17 @@ import SapforTestingSystem.ThreadsPlanner.ThreadsPlanner;
|
||||
import java.io.File;
|
||||
import java.nio.file.Paths;
|
||||
public class SapforTestingPlanner extends ThreadsPlanner {
|
||||
SapforScenario_json scenario_json = null;
|
||||
public SapforTestingPlanner() throws Exception {
|
||||
super(Global.properties.threadsTimeout, Global.properties.threadsNum);
|
||||
SapforScenario_json scenario_json = (SapforScenario_json) Utils.jsonFromFile(new File(Global.Home, "scenario.txt"), SapforScenario_json.class);
|
||||
scenario_json = (SapforScenario_json) Utils.jsonFromFile(new File(Global.Home, "scenario.txt"), SapforScenario_json.class);
|
||||
//формирование списка задач.
|
||||
for (SapforPackage_json sapforPackage_json : scenario_json.packages) {
|
||||
for (String testName : scenario_json.tests) {
|
||||
addThread(() -> {
|
||||
try {
|
||||
new SapforTest(
|
||||
new File(Global.Home, "SAPFOR_F.exe"),
|
||||
new File(Global.Home, scenario_json.sapfor_drv),
|
||||
Paths.get(Global.Home, sapforPackage_json.id, testName).toFile(),
|
||||
sapforPackage_json.flags,
|
||||
sapforPackage_json.codes).Do();
|
||||
@@ -28,5 +29,17 @@ public class SapforTestingPlanner extends ThreadsPlanner {
|
||||
});
|
||||
}
|
||||
}
|
||||
interruptThread.start();
|
||||
}
|
||||
@Override
|
||||
public void Interrupt() throws Exception {
|
||||
System.out.println("killing "+scenario_json.sapfor_drv+"...");
|
||||
String kill_command = Global.isWindows? ("taskkill /FI \"IMAGENAME eq " + scenario_json.sapfor_drv+ "\" /F /T"):
|
||||
("killall -SIGKILL " + scenario_json.sapfor_drv);
|
||||
Process killer = Runtime.getRuntime().exec(kill_command);
|
||||
killer.waitFor();
|
||||
System.out.println("done!");
|
||||
//todo для надежности сделать еще один kill с внешнего процесса.
|
||||
// может быть гонка, что нить успеет запустить процесс уже после интеррупта.
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,12 @@ import java.util.LinkedHashMap;
|
||||
import java.util.Vector;
|
||||
public abstract class ThreadsPlanner {
|
||||
//-->
|
||||
Thread interruptThread = new InterruptThread(5000, () -> {
|
||||
protected Thread interruptThread = new InterruptThread(5000, () -> {
|
||||
try {
|
||||
Interrupt();
|
||||
} catch (Exception exception) {
|
||||
Global.Log.PrintException(exception);
|
||||
}
|
||||
System.exit(0);
|
||||
return null;
|
||||
});
|
||||
@@ -42,6 +47,8 @@ public abstract class ThreadsPlanner {
|
||||
Global.Log.Print("Planner finished");
|
||||
finalize();
|
||||
}
|
||||
public void Interrupt() throws Exception {
|
||||
}
|
||||
protected void checkActiveThreads() throws Exception {
|
||||
Vector<Integer> toExclude = new Vector<>();
|
||||
//--
|
||||
|
||||
@@ -216,7 +216,7 @@ public class StartSapforTests extends Pass_2021<SapforScenario> {
|
||||
Utils.CheckAndCleanDirectory(scenarioWorkspace);
|
||||
target.workspace = scenarioWorkspace.getAbsolutePath();
|
||||
target.testsNames = String.join(";", testsNames_lower);
|
||||
sapfor = new File(target.workspace, "SAPFOR_F.exe"); //развилка на линукс
|
||||
sapfor = new File(target.workspace, Utils.getDateName("SAPFOR_F") + (Global.isWindows ? ".exe" : "")); //развилка на линукс
|
||||
ShowMessage2("Копирование SAPFOR");
|
||||
FileUtils.copyFile(Current.getSapfor().getFile(), sapfor);
|
||||
ShowMessage2("Копирование визуализатора");
|
||||
@@ -232,6 +232,7 @@ public class StartSapforTests extends Pass_2021<SapforScenario> {
|
||||
//----
|
||||
File scenarioFile = new File(target.workspace, "scenario.txt");
|
||||
SapforScenario_json scenario_json = new SapforScenario_json();
|
||||
scenario_json.sapfor_drv = sapfor.getName();
|
||||
scenario_json.tests.addAll(allTests.keySet());
|
||||
//----
|
||||
Global.db.Update(target);
|
||||
|
||||
Reference in New Issue
Block a user