Skip to content

Commit

Permalink
GEODE-7919-fix-flaky: add Awaitility to soak up latency (apache#4891)
Browse files Browse the repository at this point in the history
add Awaitility calls to soak up latency and shut down threads after tests
  • Loading branch information
Bill authored Apr 2, 2020
1 parent ba1916b commit ef6fdc1
Showing 1 changed file with 41 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/
package org.apache.geode.distributed.internal.membership.gms;

import static org.apache.geode.test.awaitility.GeodeAwaitility.await;
import static org.assertj.core.api.Assertions.assertThat;

import java.io.IOException;
Expand Down Expand Up @@ -69,6 +70,7 @@ public void before() throws IOException, MembershipConfigurationException {
@Test
public void oneMembershipCanStartWithALocator()
throws IOException, MemberStartupException {

final MembershipLocator<MemberIdentifier> locator = createLocator(0);
locator.start();

Expand All @@ -77,13 +79,18 @@ public void oneMembershipCanStartWithALocator()
start(membership);

assertThat(membership.getView().getMembers()).hasSize(1);

stop(membership);
stop(locator);
}

@Test
public void twoMembershipsCanStartWithOneLocator()
throws IOException, MemberStartupException {

final MembershipLocator<MemberIdentifier> locator = createLocator(0);
locator.start();

final int locatorPort = locator.getPort();

final Membership<MemberIdentifier> membership1 = createMembership(locator, locatorPort);
Expand All @@ -92,8 +99,14 @@ public void twoMembershipsCanStartWithOneLocator()
final Membership<MemberIdentifier> membership2 = createMembership(null, locatorPort);
start(membership2);

assertThat(membership1.getView().getMembers()).hasSize(2);
assertThat(membership2.getView().getMembers()).hasSize(2);
await().untilAsserted(
() -> assertThat(membership1.getView().getMembers()).hasSize(2));

await().untilAsserted(
() -> assertThat(membership2.getView().getMembers()).hasSize(2));

stop(membership1, membership2);
stop(locator);
}

@Test
Expand All @@ -102,21 +115,28 @@ public void twoLocatorsCanStartSequentially()

final MembershipLocator<MemberIdentifier> locator1 = createLocator(0);
locator1.start();

final int locatorPort1 = locator1.getPort();

Membership<MemberIdentifier> membership1 = createMembership(locator1, locatorPort1);
start(membership1);

final MembershipLocator<MemberIdentifier> locator2 = createLocator(0, locatorPort1);
locator2.start();

final int locatorPort2 = locator2.getPort();

Membership<MemberIdentifier> membership2 =
createMembership(locator2, locatorPort1, locatorPort2);
start(membership2);

assertThat(membership1.getView().getMembers()).hasSize(2);
assertThat(membership2.getView().getMembers()).hasSize(2);
await().untilAsserted(
() -> assertThat(membership1.getView().getMembers()).hasSize(2));
await().untilAsserted(
() -> assertThat(membership2.getView().getMembers()).hasSize(2));

stop(membership2, membership1);
stop(locator2, locator1);
}

@Test
Expand All @@ -125,24 +145,31 @@ public void secondMembershipCanJoinUsingTheSecondLocatorToStart()

final MembershipLocator<MemberIdentifier> locator1 = createLocator(0);
locator1.start();

final int locatorPort1 = locator1.getPort();

final Membership<MemberIdentifier> membership1 = createMembership(locator1, locatorPort1);
start(membership1);

final MembershipLocator<MemberIdentifier> locator2 = createLocator(0, locatorPort1);
locator2.start();

int locatorPort2 = locator2.getPort();

// Force the next membership to use locator2 by stopping locator1
locator1.stop();
stop(locator1);

Membership<MemberIdentifier> membership2 =
createMembership(locator2, locatorPort1, locatorPort2);
start(membership2);

assertThat(membership1.getView().getMembers()).hasSize(2);
assertThat(membership2.getView().getMembers()).hasSize(2);
await().untilAsserted(
() -> assertThat(membership1.getView().getMembers()).hasSize(2));
await().untilAsserted(
() -> assertThat(membership2.getView().getMembers()).hasSize(2));

stop(membership2, membership1);
stop(locator2, locator1);
}

private void start(final Membership<MemberIdentifier> membership)
Expand Down Expand Up @@ -218,4 +245,11 @@ private MembershipLocator<MemberIdentifier> createLocator(
.create();
}

private void stop(final Membership<MemberIdentifier>... memberships) {
Arrays.stream(memberships).forEach(membership -> membership.disconnect(false));
}

private void stop(final MembershipLocator<MemberIdentifier>... locators) {
Arrays.stream(locators).forEach(locator -> locator.stop());
}
}

0 comments on commit ef6fdc1

Please sign in to comment.