Skip to content

Migrate expression_compiler_service_test.dart to null-safety #1693

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dwds/lib/src/services/expression_compiler_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class _Compiler {
Future<Map<String, Object>> _send(Map<String, Object> request) async {
_sendPort.send(request);
return await _responseQueue.hasNext
? await _responseQueue.next as Map<String, Object>
? Map<String, Object>.from(await _responseQueue.next)
: {
'succeeded': false,
'errors': ['compilation service response stream closed'],
Expand Down
34 changes: 19 additions & 15 deletions dwds/test/expression_compiler_service_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// @dart = 2.9

@TestOn('vm')
import 'dart:async';
import 'dart:convert';
Expand All @@ -19,21 +17,27 @@ import 'package:test/test.dart';

import 'fixtures/logging.dart';

ExpressionCompilerService get service => _service!;
late ExpressionCompilerService? _service;

HttpServer get server => _server!;
late HttpServer? _server;

StreamController<String> get output => _output!;
late StreamController<String>? _output;

void main() async {
group('expression compiler service with fake asset server', () {
final logger = Logger('ExpressionCompilerServiceTest');
ExpressionCompilerService service;
HttpServer server;
StreamController<String> output;
Directory outputDir;
late Directory outputDir;

Future<void> stop() async {
await service?.stop();
await server?.close();
await output?.close();
service = null;
server = null;
output = null;
await _service?.stop();
await _server?.close();
await _output?.close();
_service = null;
_server = null;
_output = null;
}

setUp(() async {
Expand All @@ -47,21 +51,21 @@ void main() async {
final dartdevc = p.join(binDir, 'snapshots', 'dartdevc.dart.snapshot');

// redirect logs for testing
output = StreamController<String>.broadcast();
_output = StreamController<String>.broadcast();
output.stream.listen(printOnFailure);

configureLogWriter(
customLogWriter: (level, message, {error, loggerName, stackTrace}) =>
output.add('[$level] $loggerName: $message'));

// start asset server
server = await startHttpServer('localhost');
_server = await startHttpServer('localhost');
final port = server.port;

// start expression compilation service
Response assetHandler(request) =>
Response(200, body: File.fromUri(kernel).readAsBytesSync());
service = ExpressionCompilerService('localhost', port, verbose: false);
_service = ExpressionCompilerService('localhost', port, verbose: false);

await service.initialize(moduleFormat: 'amd');

Expand Down