import 'package:moxxmpp/moxxmpp.dart'; import 'package:test/test.dart'; import '../helpers/xmpp.dart'; void main() { test('Test having multiple disco requests for the same JID', () async { final fakeSocket = StubTCPSocket( play: [ StringExpectation( "", ''' PLAIN ''', ), StringExpectation( "AHBvbHlub21kaXZpc2lvbgBhYWFh", '' ), StringExpectation( "", ''' ''', ), StanzaExpectation( '', 'polynomdivision@test.server/MU29eEZn', ignoreId: true, ), StringExpectation( "chat", '', ), StanzaExpectation( "", '', ignoreId: true, adjustId: false, ), ], ); final XmppConnection conn = XmppConnection( TestingReconnectionPolicy(), AlwaysConnectedConnectivityManager(), fakeSocket, ); conn.setConnectionSettings(ConnectionSettings( jid: JID.fromString('polynomdivision@test.server'), password: 'aaaa', useDirectTLS: true, allowPlainAuth: true, ),); conn.registerManagers([ PresenceManager(), RosterManager(TestingRosterStateManager(null, [])), DiscoManager([]), PingManager(), EntityCapabilitiesManager('http://moxxmpp.example'), ]); conn.registerFeatureNegotiators( [ SaslPlainNegotiator(), SaslScramNegotiator(10, '', '', ScramHashType.sha512), ResourceBindingNegotiator(), ] ); final disco = conn.getManagerById(discoManager)!; await conn.connect(); await Future.delayed(const Duration(seconds: 3)); final jid = JID.fromString('romeo@montague.lit/orchard'); final result1 = disco.discoInfoQuery(jid.toString()); final result2 = disco.discoInfoQuery(jid.toString()); await Future.delayed(const Duration(seconds: 1)); expect( disco.getRunningInfoQueries(DiscoCacheKey(jid.toString(), null)).length, 1, ); fakeSocket.injectRawXml(""); await Future.delayed(const Duration(seconds: 2)); expect(fakeSocket.getState(), 6); expect(await result1, await result2); expect(disco.hasInfoQueriesRunning(), false); }); }