1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-12-22 12:37:58 +01:00

Prevent race condition in ecaps test (#206)

Properly synchronize EntityCapsTest.testPreventDiscoInfo()
This commit is contained in:
Paul Schaub 2018-02-20 15:52:04 +01:00 committed by Florian Schmaus
parent e38f80b3cb
commit ec95bd4422

View file

@ -46,6 +46,7 @@ import org.jivesoftware.smackx.disco.packet.DiscoverInfo;
import org.igniterealtime.smack.inttest.AbstractSmackIntegrationTest;
import org.igniterealtime.smack.inttest.SmackIntegrationTest;
import org.igniterealtime.smack.inttest.SmackIntegrationTestEnvironment;
import org.igniterealtime.smack.inttest.util.SimpleResultSyncPoint;
import org.junit.AfterClass;
import org.junit.BeforeClass;
@ -131,7 +132,7 @@ public class EntityCapsTest extends AbstractSmackIntegrationTest {
*
*/
@SmackIntegrationTest
public void testPreventDiscoInfo() throws XMPPException, NoResponseException, NotConnectedException, InterruptedException {
public void testPreventDiscoInfo() throws Exception {
final String dummyFeature = getNewDummyFeature();
conOne.addPacketSendingListener(new StanzaListener() {
@ -142,9 +143,27 @@ public class EntityCapsTest extends AbstractSmackIntegrationTest {
}, new AndFilter(new StanzaTypeFilter(DiscoverInfo.class), IQTypeFilter.GET));
final SimpleResultSyncPoint presenceReceivedSyncPoint = new SimpleResultSyncPoint();
final StanzaListener presenceListener = new StanzaListener() {
@Override
public void processStanza(Stanza packet) {
presenceReceivedSyncPoint.signal();
}
};
// Add a stanzaListener to listen for incoming presence
conOne.addAsyncStanzaListener(presenceListener, PresenceTypeFilter.AVAILABLE);
// add a bogus feature so that con1 ver won't match con0's
sdmTwo.addFeature(dummyFeature);
try {
// wait for the dummy feature to get sent via presence
presenceReceivedSyncPoint.waitForResult(timeout);
} finally {
conOne.removeAsyncStanzaListener(presenceListener);
}
dropCapsCache();
// discover that
DiscoverInfo info = sdmOne.discoverInfo(conTwo.getUser());