Fix instability due to race condition on stop. (#265)

This commit is contained in:
Artur Souza 2020-04-02 19:22:28 -07:00 committed by GitHub
parent 53adaa9ce8
commit 1ca2751828
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 29 additions and 43 deletions

View File

@ -49,16 +49,6 @@ public abstract class BaseIT {
return run;
}
protected static DaprRun restartDaprApp(DaprRun run) throws Exception {
DaprRun.Builder builder = DAPR_RUN_BUILDERS.get(run.getAppName());
run.stop();
DaprRun newRun = builder.build();
DAPR_RUNS.add(newRun);
newRun.start();
newRun.use();
return newRun;
}
@AfterClass
public static void cleanUp() throws Exception {
for (DaprRun app : DAPR_RUNS) {

View File

@ -63,7 +63,7 @@ public class Command {
// Waits for success to happen within 1 minute.
finished.tryAcquire(SUCCESS_WAIT_TIMEOUT_MINUTES, TimeUnit.MINUTES);
if (!success.get()) {
System.out.println("TEST WARNING: Could find success criteria for command: " + command);
throw new IllegalStateException("Could not find success criteria for command: " + command);
}
}
}

View File

@ -30,6 +30,8 @@ public class DaprRun {
private final Command startCommand;
private final Command listCommand;
private final Command stopCommand;
private DaprRun(String testName,
@ -41,6 +43,9 @@ public class DaprRun {
this.appName = String.format("%s_%s", testName, serviceClass.getSimpleName());
this.startCommand =
new Command(successMessage, buildDaprCommand(this.appName, serviceClass, ports));
this.listCommand = new Command(
this.appName,
"dapr list");
this.stopCommand = new Command(
"app stopped successfully",
"dapr stop --app-id " + this.appName);
@ -60,7 +65,17 @@ public class DaprRun {
this.started.set(true);
long timeLeft = this.maxWaitMilliseconds - (System.currentTimeMillis() - start);
callWithRetry(() -> {
System.out.println("Checking if Dapr is listening on HTTP port ...");
try {
this.listCommand.run();
} catch (Exception e) {
throw new RuntimeException(e);
}
}, timeLeft);
if (this.ports.getAppPort() != null) {
timeLeft = this.maxWaitMilliseconds - (System.currentTimeMillis() - start);
callWithRetry(() -> {
System.out.println("Checking if app is listening on port ...");
assertListeningOnPort(this.ports.getAppPort());
@ -89,11 +104,11 @@ public class DaprRun {
System.out.println("Stopping dapr application ...");
try {
this.stopCommand.run();
} catch (RuntimeException e) {
System.out.println("Could not stop app: " + this.appName);
}
System.out.println("Dapr application stopped.");
System.out.println("Dapr application stopped.");
} catch (RuntimeException e) {
System.out.println("Could not stop app " + this.appName + ": " + e.getMessage());
}
}
public void use() {

View File

@ -77,9 +77,9 @@ public class ActorTurnBasedConcurrencyIT extends BaseIT {
MyActorService.SUCCESS_MESSAGE,
MyActorService.class,
true,
10000);
60000);
Thread.sleep(2000);
Thread.sleep(3000);
String actorType="MyActorTest";
logger.debug("Creating proxy builder");

View File

@ -36,44 +36,25 @@ public class MethodInvokeIT extends BaseIT {
/**
* Run of a Dapr application.
*/
private static DaprRun daprRun = null;
/**
* Flag to determine if there is a context change based on parameters.
*/
private static Boolean wasGrpc;
private DaprRun daprRun = null;
@Parameter
public boolean useGrpc;
@BeforeClass
public static void initClass() throws Exception {
System.out.println("Working Directory = " + System.getProperty("user.dir"));
daprRun = startDaprApp(
MethodInvokeIT.class.getSimpleName(),
MethodInvokeService.SUCCESS_MESSAGE,
MethodInvokeService.class,
true,
60000);
}
@Before
public void init() throws Exception {
if (wasGrpc != null) {
if (wasGrpc.booleanValue() != this.useGrpc) {
// Context change.
daprRun = super.restartDaprApp(daprRun);
}
}
daprRun = startDaprApp(
MethodInvokeIT.class.getSimpleName(),
MethodInvokeService.SUCCESS_MESSAGE,
MethodInvokeService.class,
true,
60000);
if (this.useGrpc) {
daprRun.switchToGRPC();
} else {
daprRun.switchToHTTP();
}
wasGrpc = this.useGrpc;
}
@Test