Skip to content

Commit

Permalink
GEODE-5212: fix timing issues in BeforeCompletionTest (#2565)
Browse files Browse the repository at this point in the history
Signed-off-by: Kirk Lund <klund@apache.org>
  • Loading branch information
sboorlagadda authored Oct 5, 2018
1 parent 9199a9e commit d185c4a
Showing 1 changed file with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;

import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -81,7 +81,7 @@ public void executeThrowsTransactionExceptionIfDoOpFailedWithRuntimeException()
public void doOpCallsDoBeforeCompletion() {
beforeCompletion.doOp(txState);

verify(txState, times(1)).doBeforeCompletion();
verify(txState).doBeforeCompletion();
}

@Test
Expand All @@ -106,17 +106,17 @@ public void executeThrowsIfCancelCriterionThrows() {
}

@Test
public void executeWaitsUntilDoOpFinish() throws Exception {
public void executeWaitsUntilDoOpFinish() {
Thread thread = new Thread(() -> beforeCompletion.execute(cancelCriterion));
thread.start();
// give the thread a chance to get past the "finished" check by waiting until
// checkCancelInProgress is called
Awaitility.await().atMost(60, TimeUnit.SECONDS)
.untilAsserted(() -> verify(cancelCriterion, times(1)).checkCancelInProgress(null));
Awaitility.await().atMost(5, TimeUnit.MINUTES)
.untilAsserted(() -> verify(cancelCriterion, atLeastOnce()).checkCancelInProgress(null));

beforeCompletion.doOp(txState);

Awaitility.await().atMost(60, TimeUnit.SECONDS).until(() -> !(thread.isAlive()));
Awaitility.await().atMost(5, TimeUnit.MINUTES).until(() -> !(thread.isAlive()));
}

}

0 comments on commit d185c4a

Please sign in to comment.