fix(tests): Fix integration tests
This commit is contained in:
parent
85995d51e4
commit
f355f01fc8
@ -5,7 +5,7 @@ import 'package:test/test.dart';
|
||||
|
||||
Future<void> _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<void> _runTest(String domain) async {
|
||||
});
|
||||
|
||||
final connection = XmppConnection(
|
||||
ExponentialBackoffReconnectionPolicy(),
|
||||
TestingReconnectionPolicy(),
|
||||
AlwaysConnectedConnectivityManager(),
|
||||
socket,
|
||||
);
|
||||
connection.registerFeatureNegotiators([
|
||||
)..registerFeatureNegotiators([
|
||||
StartTlsNegotiator(),
|
||||
]);
|
||||
connection.registerManagers([
|
||||
DiscoManager(),
|
||||
RosterManager(),
|
||||
PingManager(),
|
||||
await connection.registerManagers([
|
||||
DiscoManager([]),
|
||||
RosterManager(TestingRosterStateManager('', [])),
|
||||
MessageManager(),
|
||||
PresenceManager('http://moxxmpp.example'),
|
||||
PresenceManager(),
|
||||
]);
|
||||
|
||||
connection.setConnectionSettings(
|
||||
@ -34,18 +33,22 @@ Future<void> _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<XmppError>(), 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}');
|
||||
});
|
||||
|
||||
|
@ -6,25 +6,27 @@ 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 {
|
||||
test(
|
||||
'Failing an awaited connection with TestingSleepReconnectionPolicy',
|
||||
() async {
|
||||
var errors = 0;
|
||||
final connection = XmppConnection(
|
||||
TestingSleepReconnectionPolicy(10),
|
||||
TCPSocketWrapper(false),
|
||||
);
|
||||
connection.registerFeatureNegotiators([
|
||||
AlwaysConnectedConnectivityManager(),
|
||||
TCPSocketWrapper(),
|
||||
)..registerFeatureNegotiators([
|
||||
StartTlsNegotiator(),
|
||||
]);
|
||||
connection.registerManagers([
|
||||
DiscoManager(),
|
||||
RosterManager(),
|
||||
PingManager(),
|
||||
await connection.registerManagers([
|
||||
DiscoManager([]),
|
||||
RosterManager(TestingRosterStateManager('', [])),
|
||||
MessageManager(),
|
||||
PresenceManager('http://moxxmpp.example'),
|
||||
PresenceManager(),
|
||||
]);
|
||||
connection.asBroadcastStream().listen((event) {
|
||||
if (event is ConnectionStateChangedEvent) {
|
||||
@ -39,35 +41,41 @@ void main() {
|
||||
jid: JID.fromString('testuser@no-sasl.badxmpp.eu'),
|
||||
password: 'abc123',
|
||||
useDirectTLS: true,
|
||||
allowPlainAuth: true,
|
||||
),
|
||||
);
|
||||
|
||||
final result = await connection.connectAwaitable();
|
||||
final result = await connection.connect(
|
||||
shouldReconnect: false,
|
||||
waitUntilLogin: true,
|
||||
enableReconnectOnSuccess: false,
|
||||
);
|
||||
log.info('Connection failed as expected');
|
||||
expect(result.success, false);
|
||||
expect(result.isType<XmppError>(), false);
|
||||
expect(errors, 1);
|
||||
|
||||
log.info('Waiting 20 seconds for unexpected reconnections');
|
||||
await Future.delayed(const Duration(seconds: 20));
|
||||
await Future<void>.delayed(const Duration(seconds: 20));
|
||||
expect(errors, 1);
|
||||
}, timeout: Timeout.factor(2));
|
||||
},
|
||||
timeout: const Timeout.factor(2),
|
||||
);
|
||||
|
||||
test('Failing an awaited connection with ExponentialBackoffReconnectionPolicy', () async {
|
||||
test(
|
||||
'Failing an awaited connection with ExponentialBackoffReconnectionPolicy',
|
||||
() async {
|
||||
var errors = 0;
|
||||
final connection = XmppConnection(
|
||||
ExponentialBackoffReconnectionPolicy(1),
|
||||
TCPSocketWrapper(false),
|
||||
);
|
||||
connection.registerFeatureNegotiators([
|
||||
TestingReconnectionPolicy(),
|
||||
AlwaysConnectedConnectivityManager(),
|
||||
TCPSocketWrapper(),
|
||||
)..registerFeatureNegotiators([
|
||||
StartTlsNegotiator(),
|
||||
]);
|
||||
connection.registerManagers([
|
||||
DiscoManager(),
|
||||
RosterManager(),
|
||||
PingManager(),
|
||||
await connection.registerManagers([
|
||||
DiscoManager([]),
|
||||
RosterManager(TestingRosterStateManager('', [])),
|
||||
MessageManager(),
|
||||
PresenceManager('http://moxxmpp.example'),
|
||||
PresenceManager(),
|
||||
]);
|
||||
connection.asBroadcastStream().listen((event) {
|
||||
if (event is ConnectionStateChangedEvent) {
|
||||
@ -82,17 +90,22 @@ void main() {
|
||||
jid: JID.fromString('testuser@no-sasl.badxmpp.eu'),
|
||||
password: 'abc123',
|
||||
useDirectTLS: true,
|
||||
allowPlainAuth: true,
|
||||
),
|
||||
);
|
||||
|
||||
final result = await connection.connectAwaitable();
|
||||
final result = await connection.connect(
|
||||
shouldReconnect: false,
|
||||
waitUntilLogin: true,
|
||||
enableReconnectOnSuccess: false,
|
||||
);
|
||||
log.info('Connection failed as expected');
|
||||
expect(result.success, false);
|
||||
expect(result.isType<XmppError>(), false);
|
||||
expect(errors, 1);
|
||||
|
||||
log.info('Waiting 20 seconds for unexpected reconnections');
|
||||
await Future.delayed(const Duration(seconds: 20));
|
||||
await Future<void>.delayed(const Duration(seconds: 20));
|
||||
expect(errors, 1);
|
||||
}, timeout: Timeout.factor(2));
|
||||
},
|
||||
timeout: const Timeout.factor(2),
|
||||
);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user