Тесты работают - запускаются из специальной кнопки - возле билд.

Не совсем всё по стандарту но и это очень хорошо и удобно!
This commit is contained in:
AidarKC 2025-12-29 15:03:42 +03:00
parent 7fdc890a85
commit 43a26007d6
9 changed files with 79 additions and 8 deletions

View File

@ -100,3 +100,22 @@ shadowJar {
)
}
}
tasks.named('test') {
enabled = false
}
tasks.register('itCleanRun', JavaExec) {
group = "build"
description = "Clean data → kill 7070 → start WS → run all IT tests"
classpath = sourceSets.test.runtimeClasspath
mainClass = "test.it.IT_RunAllCleanStartWsMain"
// пробрасываем системные флаги (по желанию)
systemProperty "it.debug", System.getProperty("it.debug", "true")
systemProperty "it.login", System.getProperty("it.login", "anya24")
dependsOn testClasses
}

View File

@ -2,7 +2,6 @@ package test.it;
import org.junit.platform.suite.api.SelectClasses;
import org.junit.platform.suite.api.Suite;
import test.it.ws.*;
/**
* Сьют, который запускает IT тесты строго в заданном порядке.

View File

@ -1,11 +1,11 @@
package test.it.ws;
package test.it;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import test.it.utils.ItRunContext;
import test.it.utils.JsonBuilders;
import test.it.utils.TestConfig;
import test.it.utils.TestLog;
import test.it.addBlockUtils.AddBlockFlow;
import java.time.Duration;

View File

@ -0,0 +1,55 @@
package test.it;
import server.ws.WsServer;
public class IT_RunAllCleanStartWsMain {
public static void main(String[] args) {
// 1) Гасим всё на 7070 (если ничего нет не падаем)
runBash("kill -9 $(lsof -t -i:7070) 2>/dev/null || true");
// 2) Чистим data/
IT_CleanAllDate.main(new String[0]);
// 3) Стартуем WS сервер в отдельном потоке (daemon, чтобы JVM могла завершиться)
Thread wsThread = new Thread(() -> {
try {
WsServer.main(new String[0]); // внутри join() -> поток будет висеть
} catch (Throwable t) {
t.printStackTrace(System.out);
}
}, "wsServer-thread");
wsThread.setDaemon(true);
wsThread.start();
// 4) Ждём, чтобы успел стартануть
sleepMs(1000);
// 5) Запускаем все IT тесты (без System.exit внутри)
int failed = IT_RunAllMain.runAll();
// 6) Завершаем процесс с кодом ошибок
System.exit(failed);
}
private static void runBash(String cmd) {
try {
Process p = new ProcessBuilder("bash", "-lc", cmd)
.inheritIO()
.start();
int code = p.waitFor();
// тут не ругаемся: команда может быть "пустой" (ничего не слушает порт)
// а мы уже добавили "|| true"
} catch (Exception e) {
System.out.println("WARN: bash command failed: " + e);
}
}
private static void sleepMs(long ms) {
try {
Thread.sleep(ms);
} catch (InterruptedException ignored) {
Thread.currentThread().interrupt();
}
}
}

View File

@ -2,7 +2,6 @@ package test.it;
import test.it.utils.ItRunContext;
import test.it.utils.TestLog;
import test.it.ws.IT_03_AddBlock_NoAuth;
/**
* Ручной запуск всех IT тестов БЕЗ JUnit / Suite.

View File

@ -1,4 +1,4 @@
package test.it.ws;
package test.it.addBlockUtils;
import blockchain.BchBlockEntry;
import blockchain.BchCryptoVerifier;

View File

@ -1,4 +1,4 @@
package test.it.ws;
package test.it.addBlockUtils;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;

View File

@ -1,4 +1,4 @@
package test.it.ws;
package test.it.addBlockUtils;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;