Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ public static void startJetty() throws Exception {
}
int port = connector.getLocalPort();
serverUri = new URI(String.format("http://%s:%d/", host, port));

// Add shutdown hook for unit test restart before whole class tests finished, check the forkEvery in build.gradlew
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
try {
stopJetty();
} catch (Exception e) {
System.err.println("Shutdown hook cleanup failed: " + e.getMessage());
}
}));
}

@AfterClass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ public static void init() throws IOException {
Args.setParam(new String[]{"--output-directory", temporaryFolder.newFolder().toString(),
"--p2p-disable", "true"}, Constant.TEST_CONF);
context = new TronApplicationContext(DefaultConfig.class);

// Add shutdown hook for unit test restart before whole class tests finished, check the forkEvery in build.gradlew
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
try {
destroy();
} catch (Exception e) {
logger.error("Shutdown hook cleanup failed", e);
}
}));
}

@Test
Expand Down
9 changes: 9 additions & 0 deletions framework/src/test/java/org/tron/core/net/BaseNet.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,15 @@ public static void init() throws Exception {
do {
Thread.sleep(3000); //coverage consumerInvToSpread,consumerInvToFetch in AdvService.init
} while (++tryTimes < 100 && tronNetDelegate == null);

// Add shutdown hook for unit test restart before whole class tests finished, check the forkEvery in build.gradlew
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
try {
destroy();
} catch (Exception e) {
System.err.println("Shutdown hook cleanup failed: " + e.getMessage());
}
}));
}

@AfterClass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,15 @@ public static void init() throws Exception {
TronNetService tronNetService = context.getBean(TronNetService.class);
Parameter.p2pConfig = new P2pConfig();
ReflectUtils.setFieldValue(tronNetService, "p2pConfig", Parameter.p2pConfig);

// Add shutdown hook for unit test restart before whole class tests finished, check the forkEvery in build.gradlew
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
try {
destroy();
} catch (Exception e) {
System.err.println("Shutdown hook cleanup failed: " + e.getMessage());
}
}));
}

@AfterClass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ public static void init() throws IOException {
service = context.getBean(AdvService.class);
p2pEventHandler = context.getBean(P2pEventHandlerImpl.class);
ctx = (ApplicationContext) ReflectUtils.getFieldObject(p2pEventHandler, "ctx");

// Add shutdown hook for unit test restart before whole class tests finished, check the forkEvery in build.gradlew
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
try {
after();
} catch (Exception e) {
System.err.println("Shutdown hook cleanup failed: " + e.getMessage()); }
}));
}

@AfterClass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,15 @@ public static void init() throws Exception {
TronNetService tronNetService = context.getBean(TronNetService.class);
Parameter.p2pConfig = new P2pConfig();
ReflectUtils.setFieldValue(tronNetService, "p2pConfig", Parameter.p2pConfig);

// Add shutdown hook for unit test restart before whole class tests finished, check the forkEvery in build.gradlew
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
try {
destroy();
} catch (Exception e) {
System.err.println("Shutdown hook cleanup failed: " + e.getMessage());
}
}));
}

@AfterClass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,15 @@ public static void init() throws IOException {
manager.getDynamicPropertiesStore().saveAllowShieldedTRC20Transaction(1);
Application appTest = ApplicationFactory.create(context);
appTest.startup();

// Add shutdown hook for unit test restart before whole class tests finished, check the forkEvery in build.gradlew
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
try {
destroy();
} catch (Exception e) {
System.err.println("Shutdown hook cleanup failed: " + e.getMessage());
}
}));
}

@AfterClass
Expand Down
12 changes: 12 additions & 0 deletions framework/src/test/java/org/tron/core/services/WalletApiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,18 @@ public static void init() throws IOException {
context = new TronApplicationContext(DefaultConfig.class);
appT = ApplicationFactory.create(context);
appT.startup();

// Add shutdown hook for unit test restart before whole class tests finished, check the forkEvery in build.gradlew
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
try {
if (context != null) {
Args.clearParam();
context.destroy();
}
} catch (Exception e) {
System.err.println("Shutdown hook cleanup failed: " + e.getMessage());
}
}));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,15 @@ public static void init() throws IOException {
chainBaseManager = context.getBean(ChainBaseManager.class);
Application appTest = ApplicationFactory.create(context);
appTest.startup();

// Add shutdown hook for unit test restart before whole class tests finished, check the forkEvery in build.gradlew
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
try {
destroy();
} catch (Exception e) {
System.err.println("Shutdown hook cleanup failed: " + e.getMessage());
}
}));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,15 @@ public static void init() throws IOException {

Application appTest = ApplicationFactory.create(context);
appTest.startup();

// Add shutdown hook for unit test restart before whole class tests finished, check the forkEvery in build.gradlew
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
try {
destroy();
} catch (Exception e) {
System.err.println("Shutdown hook cleanup failed: " + e.getMessage());
}
}));
}

/**
Expand Down