mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-22 12:02:05 +01:00
Prevent race condition in ecaps test (#206)
Properly synchronize EntityCapsTest.testPreventDiscoInfo()
This commit is contained in:
parent
e38f80b3cb
commit
ec95bd4422
1 changed files with 20 additions and 1 deletions
|
@ -46,6 +46,7 @@ import org.jivesoftware.smackx.disco.packet.DiscoverInfo;
|
||||||
import org.igniterealtime.smack.inttest.AbstractSmackIntegrationTest;
|
import org.igniterealtime.smack.inttest.AbstractSmackIntegrationTest;
|
||||||
import org.igniterealtime.smack.inttest.SmackIntegrationTest;
|
import org.igniterealtime.smack.inttest.SmackIntegrationTest;
|
||||||
import org.igniterealtime.smack.inttest.SmackIntegrationTestEnvironment;
|
import org.igniterealtime.smack.inttest.SmackIntegrationTestEnvironment;
|
||||||
|
import org.igniterealtime.smack.inttest.util.SimpleResultSyncPoint;
|
||||||
import org.junit.AfterClass;
|
import org.junit.AfterClass;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
|
|
||||||
|
@ -131,7 +132,7 @@ public class EntityCapsTest extends AbstractSmackIntegrationTest {
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@SmackIntegrationTest
|
@SmackIntegrationTest
|
||||||
public void testPreventDiscoInfo() throws XMPPException, NoResponseException, NotConnectedException, InterruptedException {
|
public void testPreventDiscoInfo() throws Exception {
|
||||||
final String dummyFeature = getNewDummyFeature();
|
final String dummyFeature = getNewDummyFeature();
|
||||||
conOne.addPacketSendingListener(new StanzaListener() {
|
conOne.addPacketSendingListener(new StanzaListener() {
|
||||||
|
|
||||||
|
@ -142,9 +143,27 @@ public class EntityCapsTest extends AbstractSmackIntegrationTest {
|
||||||
|
|
||||||
}, new AndFilter(new StanzaTypeFilter(DiscoverInfo.class), IQTypeFilter.GET));
|
}, 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
|
// add a bogus feature so that con1 ver won't match con0's
|
||||||
sdmTwo.addFeature(dummyFeature);
|
sdmTwo.addFeature(dummyFeature);
|
||||||
|
|
||||||
|
try {
|
||||||
|
// wait for the dummy feature to get sent via presence
|
||||||
|
presenceReceivedSyncPoint.waitForResult(timeout);
|
||||||
|
} finally {
|
||||||
|
conOne.removeAsyncStanzaListener(presenceListener);
|
||||||
|
}
|
||||||
|
|
||||||
dropCapsCache();
|
dropCapsCache();
|
||||||
// discover that
|
// discover that
|
||||||
DiscoverInfo info = sdmOne.discoverInfo(conTwo.getUser());
|
DiscoverInfo info = sdmOne.discoverInfo(conTwo.getUser());
|
||||||
|
|
Loading…
Reference in a new issue