platform/packages/websocket/test/service/io_test.dart

65 lines
1.7 KiB
Dart
Raw Normal View History

2016-12-23 20:57:46 +00:00
import 'dart:io';
2021-05-15 07:19:35 +00:00
import 'package:angel3_container/mirrors.dart';
import 'package:angel3_framework/angel3_framework.dart' as srv;
import 'package:angel3_framework/http.dart' as srv;
import 'package:angel3_websocket/io.dart' as ws;
import 'package:angel3_websocket/server.dart' as srv;
2017-09-24 04:37:58 +00:00
import 'package:logging/logging.dart';
2016-12-23 20:57:46 +00:00
import 'package:test/test.dart';
import 'common.dart';
2021-02-21 02:47:23 +00:00
void main() {
2021-04-26 00:47:32 +00:00
srv.Angel? app;
late srv.AngelHttp http;
ws.WebSockets? client;
2016-12-23 20:57:46 +00:00
srv.AngelWebSocket websockets;
2021-04-26 00:47:32 +00:00
HttpServer? server;
String? url;
2016-12-23 20:57:46 +00:00
setUp(() async {
2021-02-21 02:47:23 +00:00
app = srv.Angel(reflector: MirrorsReflector())
..use('/api/todos', TodoService());
2021-04-26 00:47:32 +00:00
http = srv.AngelHttp(app!, useZone: false);
2016-12-23 20:57:46 +00:00
2021-02-21 02:47:23 +00:00
websockets = srv.AngelWebSocket(app)
2016-12-23 20:57:46 +00:00
..onData.listen((data) {
print('Received by server: $data');
});
2021-04-26 00:47:32 +00:00
await app!.configure(websockets.configureServer);
app!.all('/ws', websockets.handleRequest);
app!.logger = Logger('angel_auth')..onRecord.listen(print);
2018-07-10 16:54:55 +00:00
server = await http.startServer();
2021-04-26 00:47:32 +00:00
url = 'ws://${server!.address.address}:${server!.port}/ws';
2016-12-23 20:57:46 +00:00
2021-02-21 02:47:23 +00:00
client = ws.WebSockets(url);
2021-04-26 00:47:32 +00:00
await client!.connect();
2016-12-23 20:57:46 +00:00
client
2021-04-26 00:47:32 +00:00
?..onData.listen((data) {
2016-12-23 20:57:46 +00:00
print('Received by client: $data');
})
..onError.listen((error) {
// Auto-fail tests on errors ;)
stderr.writeln(error);
error.errors.forEach(stderr.writeln);
throw error;
});
});
tearDown(() async {
2021-04-26 00:47:32 +00:00
await client!.close();
await http.server!.close(force: true);
2021-02-21 02:47:23 +00:00
2016-12-23 20:57:46 +00:00
app = null;
client = null;
server = null;
url = null;
2021-02-21 02:47:23 +00:00
//exit(0);
2016-12-23 20:57:46 +00:00
});
group('service.io', () {
2021-04-26 00:47:32 +00:00
test('index', () => testIndex(client!));
2016-12-23 20:57:46 +00:00
});
}