Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flakey tests #916

Closed
wants to merge 3 commits into from
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 @@ -21,7 +21,7 @@
import io.ably.lib.types.ClientOptions;

@RunWith(Parameterized.class)
public class ParameterizedTest {
abstract public class ParameterizedTest {
@Parameters(name = "{0}")
public static Iterable<Setup.TestParameters> data() {
return Arrays.asList(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -724,11 +724,35 @@ public void onChannelStateChanged(ChannelStateChange stateChange) {
}
});

/* Wait for both channels to reattach and verify state histories match the expected ones */
/*
Wait for both channels to reattach and verify state histories match the expected ones.
There's sometimes a delay between the channel becoming attached and the status appearing
in the array, so allow some waiting.
*/
attachedChannelWaiter.waitFor(ChannelState.attached);
suspendedChannelWaiter.waitFor(ChannelState.attached);
assertEquals("Attached channel histories do not match", attachedChannelHistory, expectedAttachedChannelHistory);
assertEquals("Suspended channel histories do not match", suspendedChannelHistory, expectedSuspendedChannelHistory);

long attachedHistoryTimeout = System.currentTimeMillis() + 5000;
while (!expectedAttachedChannelHistory.equals(attachedChannelHistory)) {
if (System.currentTimeMillis() > attachedHistoryTimeout) {
throw new AssertionError("Timed out wait for attached channel history");
}

try {
Thread.sleep(500);
} catch (InterruptedException ie) {}
}

long suspendedHistoryTimeout = System.currentTimeMillis() + 5000;
while (!expectedSuspendedChannelHistory.equals(suspendedChannelHistory)) {
if (System.currentTimeMillis() > suspendedHistoryTimeout) {
throw new AssertionError("Timed out wait for suspended channel history");
}

try {
Thread.sleep(500);
} catch (InterruptedException ie) {}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
Expand Down Expand Up @@ -1046,6 +1047,15 @@ public void attach_when_channel_in_detaching_state() throws AblyException {
/* create a channel and attach */
final String channelName = "attach_channel";
final Channel channel = ably.channels.get(channelName);

final List<String> channelHistory = new ArrayList<String>();
final List<String> expectedChannelHistory = Arrays.asList("attaching", "attached", "detaching", "detached", "attaching", "attached");
channel.on(new ChannelStateListener() {
@Override
public void onChannelStateChanged(ChannelStateChange stateChange) {
channelHistory.add(stateChange.current.name());
}
});
channel.attach();
new ChannelWaiter(channel).waitFor(ChannelState.attached);
assertEquals("Verify attached state reached", ChannelState.attached, channel.state);
Expand All @@ -1067,11 +1077,11 @@ public void attach_when_channel_in_detaching_state() throws AblyException {

detachCompletionWaiter.waitFor();
assertThat(detachCompletionWaiter.success, is(true));
assertThat(channel.state, is(ChannelState.detached));
//verify reattach - after detach
attachCompletionWaiter.waitFor();
assertThat(attachCompletionWaiter.success,is(true));
assertThat(channel.state, is(ChannelState.attached));

// Verify order of channel state transitions
assertEquals("Channel made expected state transitions", expectedChannelHistory, channelHistory);
} finally {
if(ably != null)
ably.close();
Expand Down