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

Fix presence / ignored presence tests #989

Merged
merged 7 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/integration-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: 'recursive'

- run: ./gradlew :java:testRestSuite

Expand All @@ -24,6 +26,8 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: 'recursive'

- run: ./gradlew :java:testRealtimeSuite

Expand Down
3 changes: 1 addition & 2 deletions lib/src/main/java/io/ably/lib/realtime/ChannelBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -369,8 +369,7 @@ private static void callCompletionListenerSuccess(CompletionListener listener) {

@Deprecated
public void sync() throws AblyException {
Log.w(TAG, "sync() method is deprecated since protocol 1.2, current protocol " +
Defaults.ABLY_PROTOCOL_VERSION);
Log.w(TAG, "sync() method is intended only for internal testing purpose as per RTP19");
}

private static void callCompletionListenerError(CompletionListener listener, ErrorInfo err) {
Expand Down
51 changes: 8 additions & 43 deletions lib/src/main/java/io/ably/lib/realtime/Presence.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;

/**
* Enables the presence set to be entered and subscribed to, and the historic presence set to be retrieved for a channel.
Expand Down Expand Up @@ -903,11 +902,6 @@ private void failQueuedMessages(ErrorInfo reason) {
************************************/

void onAttached(boolean hasPresence) {
/* Interrupt get() call => by unblocking presence.waitForSync()*/
synchronized (presence) {
ttypic marked this conversation as resolved.
Show resolved Hide resolved
presence.notifyAll();
}

presence.startSync();
if (!hasPresence) { // RTP19a
endSync();
Expand All @@ -919,8 +913,8 @@ void onAttached(boolean hasPresence) {
/**
* Spec: RTP17g
*/
synchronized void enterInternalMembers() {
for (final PresenceMessage item: internalPresence.values()) {
void enterInternalMembers() {
ttypic marked this conversation as resolved.
Show resolved Hide resolved
for (final PresenceMessage item: internalPresence.members.values()) {
try {
enterClientWithId(item.id, item.clientId, item.data, new CompletionListener() {
@Override
Expand Down Expand Up @@ -1026,7 +1020,7 @@ synchronized Collection<PresenceMessage> get(Param[] params) throws AblyExceptio
for (Param param: params) {
switch (param.key) {
case GET_WAITFORSYNC:
waitForSync = Boolean.valueOf(param.value);
waitForSync = Boolean.parseBoolean(param.value);
break;
case GET_CLIENTID:
clientId = param.value;
Expand All @@ -1041,8 +1035,7 @@ synchronized Collection<PresenceMessage> get(Param[] params) throws AblyExceptio
if (waitForSync)
waitForSync();

for (Map.Entry<String, PresenceMessage> entry: members.entrySet()) {
PresenceMessage member = entry.getValue();
for (PresenceMessage member: members.values()) {
if ((clientId == null || member.clientId.equals(clientId)) &&
(connectionId == null || member.connectionId.equals(connectionId)))
result.add(member);
Expand Down Expand Up @@ -1106,10 +1099,10 @@ synchronized boolean hasNewerItem(String key, PresenceMessage item) {
return false;

try {
long messageSerial = Long.valueOf(itemComponents[1]);
long messageIndex = Long.valueOf(itemComponents[2]);
long existingMessageSerial = Long.valueOf(existingItemComponents[1]);
long existingMessageIndex = Long.valueOf(existingItemComponents[2]);
long messageSerial = Long.parseLong(itemComponents[1]);
long messageIndex = Long.parseLong(itemComponents[2]);
long existingMessageSerial = Long.parseLong(existingItemComponents[1]);
long existingMessageIndex = Long.parseLong(existingItemComponents[2]);

return existingMessageSerial > messageSerial ||
(existingMessageSerial == messageSerial && existingMessageIndex >= messageIndex);
Expand All @@ -1119,34 +1112,6 @@ synchronized boolean hasNewerItem(String key, PresenceMessage item) {
}
}

/**
* Get all members based on the current state (even if sync is in progress)
* @return
*/
synchronized Collection<PresenceMessage> values() {
try { return values(false); } catch (InterruptedException|AblyException e) { return null; }
}

/**
* Get all members, optionally waiting if a sync is in progress.
* @param wait
* @return
* @throws InterruptedException
*/
synchronized Collection<PresenceMessage> values(boolean wait) throws AblyException, InterruptedException {
Set<PresenceMessage> result = new HashSet<PresenceMessage>();
if(wait)
waitForSync();
result.addAll(members.values());
for(Iterator<PresenceMessage> it = result.iterator(); it.hasNext();) {
PresenceMessage entry = it.next();
if(entry.action == PresenceMessage.Action.absent) {
it.remove();
}
}
return result;
}

/**
* Remove a member.
* @param item
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ public void setUpBefore() throws Exception {
/**
* Attach to channel, enter presence channel and await entered event
*/
@Ignore("FIXME: fix exception")
@Test
public void enter_simple() {
AblyRealtime clientAbly1 = null;
Expand Down Expand Up @@ -190,7 +189,6 @@ public void enter_simple() {
/**
* Enter presence channel without prior attach and await entered event
*/
@Ignore("FIXME: fix exception")
@Test
public void enter_before_attach() {
AblyRealtime clientAbly1 = null;
Expand Down Expand Up @@ -239,7 +237,6 @@ public void enter_before_attach() {
/**
* Enter presence channel without prior connect and await entered event
*/
@Ignore("FIXME: fix exception")
@Test
public void enter_before_connect() {
AblyRealtime clientAbly1 = null;
Expand Down Expand Up @@ -285,7 +282,6 @@ public void enter_before_connect() {
* Enter, then leave, presence channel and await leave event
* Verify that the item is removed from the presence map (RTP2e)
*/
@Ignore("FIXME: fix exception")
@Test
public void enter_leave_simple() {
AblyRealtime clientAbly1 = null;
Expand Down Expand Up @@ -345,7 +341,6 @@ public void enter_leave_simple() {
/**
* Enter, then enter again, expecting update event
*/
@Ignore("FIXME: fix exception")
@Test
public void enter_enter_simple() {
AblyRealtime clientAbly1 = null;
Expand Down Expand Up @@ -414,7 +409,6 @@ public void enter_enter_simple() {
/**
* Enter, then update, expecting update event
*/
@Ignore("FIXME: fix exception")
@Test
public void enter_update_simple() {
AblyRealtime clientAbly1 = null;
Expand Down Expand Up @@ -552,7 +546,6 @@ public void enter_update_null() {
/**
* Update without having first entered, expecting enter event
*/
@Ignore("FIXME: fix exception")
@Test
public void update_noenter() {
AblyRealtime clientAbly1 = null;
Expand Down Expand Up @@ -611,7 +604,6 @@ public void update_noenter() {
* Enter, then leave (with no data) and await leave event,
* expecting enter data to be in leave event
*/
@Ignore("FIXME: fix exception")
@Test
public void enter_leave_nodata() {
AblyRealtime clientAbly1 = null;
Expand Down Expand Up @@ -667,7 +659,6 @@ public void enter_leave_nodata() {
/**
* Attach to channel, enter presence channel and get presence using realtime get()
*/
@Ignore("FIXME: fix exception")
@Test
public void realtime_get_simple() {
AblyRealtime clientAbly1 = null;
Expand Down Expand Up @@ -722,7 +713,6 @@ public void realtime_get_simple() {
/**
* Attach to channel, enter+leave presence channel and get presence with realtime get()
*/
@Ignore("FIXME: fix exception")
@Test
public void realtime_get_leave() {
AblyRealtime clientAbly1 = null;
Expand Down Expand Up @@ -781,7 +771,6 @@ public void realtime_get_leave() {
* Attach to channel, enter presence channel, then initiate second
* connection, seeing existing member in message subsequent to second attach response
*/
@Ignore("FIXME: fix exception")
@Test
public void attach_enter_simple() {
AblyRealtime clientAbly1 = null;
Expand Down Expand Up @@ -858,7 +847,6 @@ public void attach_enter_simple() {
*
* Test RTP4
*/
@Ignore("FIXME: fix exception")
@Test
public void attach_enter_multiple() {
AblyRealtime clientAbly1 = null;
Expand Down Expand Up @@ -943,7 +931,6 @@ public void attach_enter_multiple() {
/**
* Attach and enter channel on two connections, seeing
* both members in presence returned by realtime get() */
@Ignore("FIXME: fix exception")
@Test
public void realtime_enter_multiple() {
AblyRealtime clientAbly1 = null;
Expand Down Expand Up @@ -1014,7 +1001,6 @@ public void realtime_enter_multiple() {
/**
* Attach to channel, enter presence channel and get presence using rest get()
*/
@Ignore("FIXME: fix exception")
@Test
public void rest_get_simple() {
AblyRealtime clientAbly1 = null;
Expand Down Expand Up @@ -1067,7 +1053,6 @@ public void rest_get_simple() {
/**
* Attach to channel, enter+leave presence channel and get presence with rest get()
*/
@Ignore("FIXME: fix exception")
@Test
public void rest_get_leave() {
AblyRealtime clientAbly1 = null;
Expand Down Expand Up @@ -1125,7 +1110,6 @@ public void rest_get_leave() {
/**
* Attach and enter channel on two connections, seeing
* both members in presence returned by rest get() */
@Ignore("FIXME: fix exception")
@Test
public void rest_enter_multiple() {
AblyRealtime clientAbly1 = null;
Expand Down Expand Up @@ -1191,7 +1175,6 @@ public void rest_enter_multiple() {
/**
* Attach and enter channel multiple times on a single connection,
* retrieving members using paginated rest get() */
@Ignore("FIXME: fix exception")
@Test
public void rest_paginated_get() {
AblyRealtime clientAbly1 = null;
Expand Down Expand Up @@ -1277,7 +1260,6 @@ public void rest_paginated_get() {
/**
* Attach to channel, enter presence channel, disconnect and await leave event
*/
@Ignore("FIXME: fix exception")
@Test
public void disconnect_leave() {
AblyRealtime clientAbly1 = null;
Expand Down Expand Up @@ -1419,7 +1401,6 @@ public Presence.PresenceListener setMessageStack(List<PresenceMessage> messageSt
*
* @throws AblyException
*/
@Ignore("FIXME: flaky test")
@Test
public void realtime_presence_unsubscribe_single() throws AblyException {
/* Ably instance that will emit presence events */
Expand Down Expand Up @@ -1499,7 +1480,6 @@ public Presence.PresenceListener setMessageStack(List<PresenceMessage> messageSt
*
* @throws AblyException
*/
@Ignore("FIXME: flaky test")
@Test
public void realtime_presence_subscribe_all() throws AblyException {
/* Ably instance that will emit presence events */
Expand Down Expand Up @@ -1575,7 +1555,6 @@ public Presence.PresenceListener setMessageStack(List<PresenceMessage> messageSt
*
* @throws AblyException
*/
@Ignore("FIXME: fix exception")
@Test
public void realtime_presence_subscribe_multiple() throws AblyException {
/* Ably instance that will emit presence events */
Expand Down Expand Up @@ -1824,7 +1803,6 @@ public Presence.PresenceListener setMessageStack(List<PresenceMessage> messageSt
*
* @throws AblyException
*/
@Ignore("FIXME: flaky test")
@Test
public void realtime_presence_attach_implicit_subscribe_fail() throws AblyException {
AblyRealtime ably = null;
Expand Down Expand Up @@ -2142,7 +2120,6 @@ public void realtime_presence_attach_implicit_leaveclient_fail() throws AblyExce
*
* @throws AblyException
*/
@Ignore("FIXME: fix exception")
@Test
public void realtime_presence_get_throws_when_channel_failed() throws AblyException {
AblyRealtime ably = null;
Expand Down Expand Up @@ -2467,7 +2444,6 @@ public void onPresenceMessage(PresenceMessage message) {
*
* Tests RTP3
*/
@Ignore("FIXME: fix exception")
@Test
public void reattach_resume_broken_sync() {
AblyRealtime clientAbly1 = null;
Expand Down Expand Up @@ -2850,7 +2826,6 @@ public void onChannelStateChanged(ChannelStateChange stateChange) {
*
* Not functional yet
*/
@Ignore("FIXME: fix exception")
@Test
public void presence_without_subscribe_capability() throws AblyException {
String channelName = "presence_without_subscribe" + testParams.name;
Expand Down Expand Up @@ -2914,7 +2889,6 @@ public void onError(ErrorInfo reason) {
*
* Tests RTP13
*/
@Ignore("FIXME: fix exception")
@Test
public void sync_complete() {
AblyRealtime ably1 = null, ably2 = null;
Expand Down Expand Up @@ -2994,7 +2968,6 @@ public void presence_enter_without_permission() throws AblyException {
/**
* Enter wrong client (mismatching one set in the token), check exception
*/
@Ignore("FIXME: fix exception")
@Test
public void presence_enter_mismatched_clientid() throws AblyException {
String channelName = "presence_enter_mismatched_clientid" + testParams.name;
Expand Down Expand Up @@ -3236,7 +3209,6 @@ public boolean matches(ProtocolMessage message) {
* Verify presence data is received and encoded/decoded correctly
* Tests RTP8e, RTP6a
*/
@Ignore("FIXME: flaky test")
@Test
public void presence_encoding() throws AblyException, InterruptedException {
AblyRealtime ably1 = null, ably2 = null;
Expand Down Expand Up @@ -3307,7 +3279,6 @@ public void onPresenceMessage(PresenceMessage message) {
* Test Presence.get() filtering and syncToWait flag
* Tests RTP11b, RTP11c, RTP11d
*/
@Ignore("FIXME: fix exception")
@Test
public void presence_get() throws AblyException, InterruptedException {
AblyRealtime ably1 = null, ably2 = null;
Expand All @@ -3316,15 +3287,15 @@ public void presence_get() throws AblyException, InterruptedException {
final String channelName = "presence_get" + testParams.name;
ClientOptions opts = createOptions(testVars.keys[0].keyStr);
ably1 = new AblyRealtime(opts);
opts.autoConnect = false;
ably2 = new AblyRealtime(opts);

Channel channel1 = ably1.channels.get(channelName);
CompletionWaiter completionWaiter = new CompletionWaiter();
channel1.presence.enterClient("1", null, completionWaiter);
channel1.presence.enterClient("2", null, completionWaiter);
completionWaiter.waitFor(2);

opts.autoConnect = false;
ably2 = new AblyRealtime(opts);
Channel channel2 = ably2.channels.get(channelName);
PresenceWaiter waiter2 = new PresenceWaiter(channel2);

Expand Down Expand Up @@ -3403,7 +3374,6 @@ public void checkMembersWithChannelPresence(Channel testChannel) throws AblyExce
assertEquals("Members count with channel presence should be " + presenceMessages.length, presenceMessages.length, 1);
}

@Ignore
@Test
public void test_consistent_presence_for_members() {
AblyRealtime clientAbly1 = null;
Expand Down Expand Up @@ -3566,7 +3536,6 @@ public void message_from_encoded_json_object() throws AblyException {
* Refer Spec. TP4
* @throws AblyException
*/
@Ignore("FIXME: fix exception")
@Test
public void messages_from_encoded_json_array() throws AblyException {
JsonArray fixtures = null;
Expand Down