Skip to content

Commit

Permalink
Add StompConfig test
Browse files Browse the repository at this point in the history
  • Loading branch information
MacDeveloper1 committed Jan 31, 2024
1 parent 2cf8e8e commit d778aa9
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions test/stomp_config_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import 'dart:async';

import 'package:test/test.dart';
import 'package:web_socket_channel/web_socket_channel.dart';

import 'package:stomp_dart_client/stomp_config.dart';
import 'package:stomp_dart_client/src/_connect_api.dart'
if (dart.library.html) '../lib/src/_connect_html.dart'
if (dart.library.io) '../lib/src/_connect_io.dart' as platform;

void main() {
group('StompConfig', () {
test('Generate session URL once per connection', () async {
final config = StompConfig.sockJS(
url: 'http://localhost',
reconnectDelay: Duration(milliseconds: 500),
);

final connectUrls = <(String, String)>[];

void connect() async {
try {
await platform.connect(config..resetSession());
} on WebSocketChannelException catch (_) {
// Save subsequent calls of `connectUrl`.
connectUrls.add((config.connectUrl, config.connectUrl));
if (connectUrls.length == 1) {
// On 1st connect we expect that the current stored values are equal
expect(connectUrls.first.$1, equals(connectUrls.first.$2));
} else if (connectUrls.length == 2) {
// On 2nd connect we expect that the current stored values are equal
expect(connectUrls.last.$1, equals(connectUrls.last.$2));
// But they are different from the values saved on 1st connect
expect(connectUrls.first.$1, isNot(equals(connectUrls.last.$1)));
expect(connectUrls.first.$2, isNot(equals(connectUrls.last.$2)));
}
Timer(config.reconnectDelay, connect);
}
}

connect();

// Wait until exit
await Future.delayed(Duration(seconds: 3));
});
});
}

0 comments on commit d778aa9

Please sign in to comment.