From f355f01fc8b7a7824acc037d0b6a196f6244bacc Mon Sep 17 00:00:00 2001 From: "Alexander \"PapaTutuWawa" Date: Thu, 30 Mar 2023 16:15:44 +0200 Subject: [PATCH] fix(tests): Fix integration tests --- .../badxmpp_certificate_test.dart | 31 ++-- .../failure_reconnection_test.dart | 165 ++++++++++-------- .../integration_test/no_service_test.dart | 1 + 3 files changed, 107 insertions(+), 90 deletions(-) diff --git a/packages/moxxmpp_socket_tcp/integration_test/badxmpp_certificate_test.dart b/packages/moxxmpp_socket_tcp/integration_test/badxmpp_certificate_test.dart index 0417b7a..b93d554 100644 --- a/packages/moxxmpp_socket_tcp/integration_test/badxmpp_certificate_test.dart +++ b/packages/moxxmpp_socket_tcp/integration_test/badxmpp_certificate_test.dart @@ -5,7 +5,7 @@ import 'package:test/test.dart'; Future _runTest(String domain) async { var gotTLSException = false; - final socket = TCPSocketWrapper(false); + final socket = TCPSocketWrapper(); final log = Logger('TestLogger'); socket.getEventStream().listen((event) { if (event is XmppSocketTLSFailedEvent) { @@ -15,18 +15,17 @@ Future _runTest(String domain) async { }); final connection = XmppConnection( - ExponentialBackoffReconnectionPolicy(), + TestingReconnectionPolicy(), + AlwaysConnectedConnectivityManager(), socket, - ); - connection.registerFeatureNegotiators([ - StartTlsNegotiator(), - ]); - connection.registerManagers([ - DiscoManager(), - RosterManager(), - PingManager(), + )..registerFeatureNegotiators([ + StartTlsNegotiator(), + ]); + await connection.registerManagers([ + DiscoManager([]), + RosterManager(TestingRosterStateManager('', [])), MessageManager(), - PresenceManager('http://moxxmpp.example'), + PresenceManager(), ]); connection.setConnectionSettings( @@ -34,18 +33,22 @@ Future _runTest(String domain) async { jid: JID.fromString('testuser@$domain'), password: 'abc123', useDirectTLS: true, - allowPlainAuth: true, ), ); - final result = await connection.connectAwaitable(); - expect(result.success, false); + final result = await connection.connect( + shouldReconnect: false, + waitUntilLogin: true, + enableReconnectOnSuccess: false, + ); + expect(result.isType(), false); expect(gotTLSException, true); } void main() { Logger.root.level = Level.ALL; Logger.root.onRecord.listen((record) { + // ignore: avoid_print print('${record.level.name}: ${record.time}: ${record.message}'); }); diff --git a/packages/moxxmpp_socket_tcp/integration_test/failure_reconnection_test.dart b/packages/moxxmpp_socket_tcp/integration_test/failure_reconnection_test.dart index 7940b54..e701de1 100644 --- a/packages/moxxmpp_socket_tcp/integration_test/failure_reconnection_test.dart +++ b/packages/moxxmpp_socket_tcp/integration_test/failure_reconnection_test.dart @@ -6,93 +6,106 @@ import 'package:test/test.dart'; void main() { Logger.root.level = Level.ALL; Logger.root.onRecord.listen((record) { + // ignore: avoid_print print('${record.level.name}: ${record.time}: ${record.message}'); }); final log = Logger('FailureReconnectionTest'); - test('Failing an awaited connection with TestingSleepReconnectionPolicy', () async { - var errors = 0; - final connection = XmppConnection( - TestingSleepReconnectionPolicy(10), - TCPSocketWrapper(false), - ); - connection.registerFeatureNegotiators([ - StartTlsNegotiator(), - ]); - connection.registerManagers([ - DiscoManager(), - RosterManager(), - PingManager(), - MessageManager(), - PresenceManager('http://moxxmpp.example'), - ]); - connection.asBroadcastStream().listen((event) { - if (event is ConnectionStateChangedEvent) { - if (event.state == XmppConnectionState.error) { - errors++; + test( + 'Failing an awaited connection with TestingSleepReconnectionPolicy', + () async { + var errors = 0; + final connection = XmppConnection( + TestingSleepReconnectionPolicy(10), + AlwaysConnectedConnectivityManager(), + TCPSocketWrapper(), + )..registerFeatureNegotiators([ + StartTlsNegotiator(), + ]); + await connection.registerManagers([ + DiscoManager([]), + RosterManager(TestingRosterStateManager('', [])), + MessageManager(), + PresenceManager(), + ]); + connection.asBroadcastStream().listen((event) { + if (event is ConnectionStateChangedEvent) { + if (event.state == XmppConnectionState.error) { + errors++; + } } - } - }); + }); - connection.setConnectionSettings( - ConnectionSettings( - jid: JID.fromString('testuser@no-sasl.badxmpp.eu'), - password: 'abc123', - useDirectTLS: true, - allowPlainAuth: true, - ), - ); + connection.setConnectionSettings( + ConnectionSettings( + jid: JID.fromString('testuser@no-sasl.badxmpp.eu'), + password: 'abc123', + useDirectTLS: true, + ), + ); - final result = await connection.connectAwaitable(); - log.info('Connection failed as expected'); - expect(result.success, false); - expect(errors, 1); + final result = await connection.connect( + shouldReconnect: false, + waitUntilLogin: true, + enableReconnectOnSuccess: false, + ); + log.info('Connection failed as expected'); + expect(result.isType(), false); + expect(errors, 1); - log.info('Waiting 20 seconds for unexpected reconnections'); - await Future.delayed(const Duration(seconds: 20)); - expect(errors, 1); - }, timeout: Timeout.factor(2)); + log.info('Waiting 20 seconds for unexpected reconnections'); + await Future.delayed(const Duration(seconds: 20)); + expect(errors, 1); + }, + timeout: const Timeout.factor(2), + ); - test('Failing an awaited connection with ExponentialBackoffReconnectionPolicy', () async { - var errors = 0; - final connection = XmppConnection( - ExponentialBackoffReconnectionPolicy(1), - TCPSocketWrapper(false), - ); - connection.registerFeatureNegotiators([ - StartTlsNegotiator(), - ]); - connection.registerManagers([ - DiscoManager(), - RosterManager(), - PingManager(), - MessageManager(), - PresenceManager('http://moxxmpp.example'), - ]); - connection.asBroadcastStream().listen((event) { - if (event is ConnectionStateChangedEvent) { - if (event.state == XmppConnectionState.error) { - errors++; + test( + 'Failing an awaited connection with ExponentialBackoffReconnectionPolicy', + () async { + var errors = 0; + final connection = XmppConnection( + TestingReconnectionPolicy(), + AlwaysConnectedConnectivityManager(), + TCPSocketWrapper(), + )..registerFeatureNegotiators([ + StartTlsNegotiator(), + ]); + await connection.registerManagers([ + DiscoManager([]), + RosterManager(TestingRosterStateManager('', [])), + MessageManager(), + PresenceManager(), + ]); + connection.asBroadcastStream().listen((event) { + if (event is ConnectionStateChangedEvent) { + if (event.state == XmppConnectionState.error) { + errors++; + } } - } - }); + }); - connection.setConnectionSettings( - ConnectionSettings( - jid: JID.fromString('testuser@no-sasl.badxmpp.eu'), - password: 'abc123', - useDirectTLS: true, - allowPlainAuth: true, - ), - ); + connection.setConnectionSettings( + ConnectionSettings( + jid: JID.fromString('testuser@no-sasl.badxmpp.eu'), + password: 'abc123', + useDirectTLS: true, + ), + ); - final result = await connection.connectAwaitable(); - log.info('Connection failed as expected'); - expect(result.success, false); - expect(errors, 1); + final result = await connection.connect( + shouldReconnect: false, + waitUntilLogin: true, + enableReconnectOnSuccess: false, + ); + log.info('Connection failed as expected'); + expect(result.isType(), false); + expect(errors, 1); - log.info('Waiting 20 seconds for unexpected reconnections'); - await Future.delayed(const Duration(seconds: 20)); - expect(errors, 1); - }, timeout: Timeout.factor(2)); + log.info('Waiting 20 seconds for unexpected reconnections'); + await Future.delayed(const Duration(seconds: 20)); + expect(errors, 1); + }, + timeout: const Timeout.factor(2), + ); } diff --git a/packages/moxxmpp_socket_tcp/integration_test/no_service_test.dart b/packages/moxxmpp_socket_tcp/integration_test/no_service_test.dart index e69de29..8b13789 100644 --- a/packages/moxxmpp_socket_tcp/integration_test/no_service_test.dart +++ b/packages/moxxmpp_socket_tcp/integration_test/no_service_test.dart @@ -0,0 +1 @@ +