-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #96 from MacDeveloper1/bug/connect-url
Make connectUrl lazy and once initialized
- Loading branch information
Showing
3 changed files
with
60 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
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.addAll({config.connectUrl: config.connectUrl}); | ||
if (connectUrls.length == 1) { | ||
// On 1st connect we expect that the current stored values are equal | ||
expect(connectUrls.entries.first.key, | ||
equals(connectUrls.entries.first.value)); | ||
} else if (connectUrls.length == 2) { | ||
// On 2nd connect we expect that the current stored values are equal | ||
expect(connectUrls.entries.last.key, | ||
equals(connectUrls.entries.last.value)); | ||
// But they are different from the values saved on 1st connect | ||
expect(connectUrls.entries.first.key, | ||
isNot(equals(connectUrls.entries.last.key))); | ||
expect(connectUrls.entries.first.value, | ||
isNot(equals(connectUrls.entries.last.value))); | ||
} | ||
Timer(config.reconnectDelay, connect); | ||
} | ||
} | ||
|
||
connect(); | ||
|
||
// Wait until exit | ||
await Future.delayed(Duration(seconds: 3)); | ||
}); | ||
}); | ||
} |