Skip to content

Commit

Permalink
Refactored channel resume tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sacOO7 committed Feb 6, 2024
1 parent 68a0944 commit 8e7b272
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public void onChannelStateChanged(ChannelStateChange stateChange) {
for (final ChannelStateListener member : getMembers())
try {
member.onChannelStateChanged(stateChange);
} catch(Throwable t) {}
} catch(Throwable ignored) {}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
Expand Down Expand Up @@ -388,7 +389,7 @@ public void onConnectionStateChanged(ConnectionStateChange state) {
/* wait for cm thread to exit */
try {
Thread.sleep(2000L);
} catch(InterruptedException e) {}
} catch(InterruptedException ignored) {}

assertEquals("Verify closed state is reached", ConnectionState.closed, ably.connection.state);
Thread.State cmThreadState = threadContainer[0].getState();
Expand Down Expand Up @@ -462,7 +463,7 @@ public void run() {

connectionWaiter.waitFor(ConnectionState.connected);
assertEquals("Verify connected state is reached", ConnectionState.connected, ably.connection.state);
assertTrue("Not expecting token auth", ably.auth.getAuthMethod() == AuthMethod.basic);
assertSame("Not expecting token auth", ably.auth.getAuthMethod(), AuthMethod.basic);

ably.close();
connectionWaiter.waitFor(ConnectionState.closed);
Expand All @@ -471,7 +472,7 @@ public void run() {
/* wait for cm thread to exit */
try {
Thread.sleep(2000L);
} catch(InterruptedException e) {}
} catch(InterruptedException ignored) {}

Thread.State cmThreadState = threadContainer[0].getState();
assertEquals("Verify cm thread has exited", cmThreadState, Thread.State.TERMINATED);
Expand Down Expand Up @@ -510,7 +511,7 @@ public void run() {
/* wait for cm thread to exit */
try {
Thread.sleep(2000L);
} catch(InterruptedException e) {}
} catch(InterruptedException ignored) {}

Thread.State cmThreadState = threadContainer[0].getState();
assertEquals("Verify cm thread has exited", cmThreadState, Thread.State.TERMINATED);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public void auth_client_match_tokendetails_null_clientId() {
assertEquals("Verify connected state is reached", ConnectionState.connected, ablyRealtime.connection.state);

/* check expected clientId */
assertEquals("Auth#clientId is expected to be null", null, ablyRealtime.auth.clientId);
assertNull("Auth#clientId is expected to be null", ablyRealtime.auth.clientId);

ablyRealtime.close();
} catch (AblyException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@

public class RealtimeResumeTest extends ParameterizedTest {

private static final String TAG = RealtimeResumeTest.class.getName();

@Rule
public Timeout testTimeout = Timeout.seconds(60);

Expand Down Expand Up @@ -1014,7 +1012,6 @@ public void resume_rewind_1 ()

String testName = "resume_rewind_1";
try {

ClientOptions common_opts = createOptions(testVars.keys[0].keyStr);
sender = new AblyRealtime(common_opts);
receiver1 = new AblyRealtime(common_opts);
Expand All @@ -1036,21 +1033,22 @@ public void onRawMessageRecv(ProtocolMessage message) {}
};
receiver2 = new AblyRealtime(receiver2_opts);

Channel recever1_channel = receiver1.channels.get("[?rewind=1]" + testName);
Channel recever2_channel = receiver2.channels.get("[?rewind=1]" + testName);
Channel sender_channel = sender.channels.get(testName);
Channel receiver1_channel = receiver1.channels.get("[?rewind=1]" + testName);

Channel receiver2_channel = receiver2.channels.get("[?rewind=1]" + testName);

Channel sender_channel = sender.channels.get(testName);
sender_channel.attach();
(new ChannelWaiter(sender_channel)).waitFor(ChannelState.attached);
sender_channel.publish("0", testMessage);

/* subscribe 1*/
MessageWaiter messageWaiter_1 = new MessageWaiter(recever1_channel);
MessageWaiter messageWaiter_1 = new MessageWaiter(receiver1_channel);
messageWaiter_1.waitFor(1);
assertEquals("Verify rewound message", testMessage, messageWaiter_1.receivedMessages.get(0).data);

/* subscribe 2*/
MessageWaiter messageWaiter_2 = new MessageWaiter(recever2_channel);
MessageWaiter messageWaiter_2 = new MessageWaiter(receiver2_channel);
messageWaiter_2.waitFor(1, 7000);
assertEquals("Verify no message received on attach_rewind", 0, messageWaiter_2.receivedMessages.size());

Expand Down

0 comments on commit 8e7b272

Please sign in to comment.