Skip to content

Commit

Permalink
[sinttest] Refactoring XEP-0045 test for default roles
Browse files Browse the repository at this point in the history
Order of events in the test is made more predictable by explicitly waiting for all users to have joined the room, prior to checking their role.
  • Loading branch information
guusdk committed Apr 10, 2024
1 parent 78814d2 commit 582e2e9
Showing 1 changed file with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

import java.util.Set;
import java.util.concurrent.TimeoutException;

import org.jivesoftware.smack.SmackException;
Expand Down Expand Up @@ -794,23 +795,27 @@ public void mucTestDefaultRoleForAffiliationInMembersOnlyRoom() throws Exception

createMembersOnlyMuc(mucAsSeenByOne, nicknameOne);

final SimpleResultSyncPoint adminResultSyncPoint = new SimpleResultSyncPoint();
final SimpleResultSyncPoint allOccupantsDetectedSyncPoint = new SimpleResultSyncPoint();
final Set<EntityFullJid> expectedOccupants = Set.of(jidOne, jidTwo, jidThree);
mucAsSeenByOne.addParticipantStatusListener(new ParticipantStatusListener() {
@Override
public void adminGranted(EntityFullJid participant) {
adminResultSyncPoint.signal();
public void joined(EntityFullJid participant) {
if (mucAsSeenByOne.getOccupants().containsAll(expectedOccupants)) {
allOccupantsDetectedSyncPoint.signal();
}
}
});

try {
mucAsSeenByOne.grantMembership(conTwo.getUser().asBareJid());
mucAsSeenByOne.grantMembership(conThree.getUser().asBareJid());
mucAsSeenByOne.grantAdmin(conTwo.getUser().asBareJid());

mucAsSeenByTwo.join(nicknameTwo);
mucAsSeenByThree.join(nicknameThree);
mucAsSeenByOne.grantAdmin(conTwo.getUser().asBareJid());
adminResultSyncPoint.waitForResult(timeout);
assertEquals(mucAsSeenByOne.getOccupantsCount(), 3, "Unexpected occupant count in room " + mucAddress);

allOccupantsDetectedSyncPoint.waitForResult(timeout);

assertEquals(MUCRole.moderator, mucAsSeenByOne.getOccupant(jidOne).getRole(), "Unexpected role for occupant " + jidOne + " in room " + mucAddress);
assertEquals(MUCRole.moderator, mucAsSeenByOne.getOccupant(jidTwo).getRole(), "Unexpected role for occupant " + jidTwo + " in room " + mucAddress);
assertEquals(MUCRole.participant, mucAsSeenByOne.getOccupant(jidThree).getRole(), "Unexpected role for occupant " + jidThree + " in room " + mucAddress);
Expand Down

0 comments on commit 582e2e9

Please sign in to comment.