diff --git a/.github/workflows/test-package.yml b/.github/workflows/test-package.yml index 1ded117..89c7e63 100644 --- a/.github/workflows/test-package.yml +++ b/.github/workflows/test-package.yml @@ -47,7 +47,7 @@ jobs: matrix: # Add macos-latest and/or windows-latest if relevant for this package. os: [ubuntu-latest] - sdk: [3.0.0, dev] + sdk: [3.2, dev] steps: - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 - uses: dart-lang/setup-dart@ca7e6fee45ffbd82b555a7ebfc236d2c86439f5b diff --git a/CHANGELOG.md b/CHANGELOG.md index 0c25cce..9674672 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 2.3.1-wip + +- Require Dart 3.2 + ## 2.3.0 - Only send updates on frames and pings being received when there are listeners, as to not fill up memory. diff --git a/analysis_options.yaml b/analysis_options.yaml index 8b5373d..9f9fe93 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -1,15 +1,9 @@ -include: package:lints/recommended.yaml +# https://dart.dev/tools/analysis#the-analysis-options-file +include: package:dart_flutter_team_lints/analysis_options.yaml analyzer: language: strict-casts: true errors: - unused_element: error - unused_import: error - unused_local_variable: error - dead_code: error - -linter: - rules: # Disabled as there are several dozen violations. - constant_identifier_names: false + constant_identifier_names: ignore diff --git a/lib/multiprotocol_server.dart b/lib/multiprotocol_server.dart index 0b1aeeb..54fe6c0 100644 --- a/lib/multiprotocol_server.dart +++ b/lib/multiprotocol_server.dart @@ -45,7 +45,7 @@ class MultiProtocolHttpServer { /// /// See also [startServing]. static Future bind( - address, int port, SecurityContext context, + Object? address, int port, SecurityContext context, {http2.ServerSettings? settings}) async { context.setAlpnProtocols(['h2', 'h2-14', 'http/1.1'], true); var secureServer = await SecureServerSocket.bind(address, port, context); diff --git a/lib/src/async_utils/async_utils.dart b/lib/src/async_utils/async_utils.dart index 6148328..22a73e9 100644 --- a/lib/src/async_utils/async_utils.dart +++ b/lib/src/async_utils/async_utils.dart @@ -60,15 +60,9 @@ class BufferedSink { bufferIndicator.markBuffered(); _controller - ..onListen = () { - bufferIndicator.markUnBuffered(); - } - ..onPause = () { - bufferIndicator.markBuffered(); - } - ..onResume = () { - bufferIndicator.markUnBuffered(); - } + ..onListen = bufferIndicator.markUnBuffered + ..onPause = bufferIndicator.markBuffered + ..onResume = bufferIndicator.markUnBuffered ..onCancel = () { // TODO: We may want to propagate cancel events as errors. // Currently `_doneFuture` will just complete normally if the sink diff --git a/lib/src/connection.dart b/lib/src/connection.dart index 35a851b..4e52e57 100644 --- a/lib/src/connection.dart +++ b/lib/src/connection.dart @@ -188,7 +188,7 @@ abstract class Connection { var settings = _decodeSettings(settingsObject); // Do the initial settings handshake (possibly with pushes disabled). - _settingsHandler.changeSettings(settings).catchError((error) { + _settingsHandler.changeSettings(settings).catchError((Object error) { // TODO: The [error] can contain sensitive information we now expose via // a [Goaway] frame. We should somehow ensure we're only sending useful // but non-sensitive information. @@ -271,15 +271,15 @@ abstract class Connection { } /// Pings the remote peer (can e.g. be used for measuring latency). - Future ping() { + Future ping() { return _pingHandler.ping().catchError((e, s) { - return Future.error( + return Future.error( TransportException('The connection has been terminated.')); }, test: (e) => e is TerminatedException); } /// Finishes this connection. - Future finish() { + Future finish() { _finishing(active: true); // TODO: There is probably more we need to wait for. @@ -288,7 +288,7 @@ abstract class Connection { } /// Terminates this connection forcefully. - Future terminate([int? errorCode]) { + Future terminate([int? errorCode]) { return _terminate(errorCode ?? ErrorCode.NO_ERROR); } @@ -441,16 +441,15 @@ abstract class Connection { _settingsHandler.terminate(exception); return Future.wait([cancelFuture, closeFuture]) - .catchError((_) => const []); + .catchError((_) => const []); } - return Future.value(); + return Future.value(); } } class ClientConnection extends Connection implements ClientTransportConnection { - ClientConnection._(Stream> incoming, StreamSink> outgoing, - Settings settings) - : super(incoming, outgoing, settings, isClientConnection: true); + ClientConnection._(super.incoming, super.outgoing, super.settings) + : super(isClientConnection: true); factory ClientConnection(Stream> incoming, StreamSink> outgoing, ClientSettings clientSettings) { @@ -489,9 +488,8 @@ class ClientConnection extends Connection implements ClientTransportConnection { } class ServerConnection extends Connection implements ServerTransportConnection { - ServerConnection._(Stream> incoming, StreamSink> outgoing, - Settings settings) - : super(incoming, outgoing, settings, isClientConnection: false); + ServerConnection._(super.incoming, super.outgoing, super.settings) + : super(isClientConnection: false); factory ServerConnection(Stream> incoming, StreamSink> outgoing, ServerSettings serverSettings) { diff --git a/lib/src/connection_preface.dart b/lib/src/connection_preface.dart index c2bf652..2f0b98c 100644 --- a/lib/src/connection_preface.dart +++ b/lib/src/connection_preface.dart @@ -96,15 +96,14 @@ Stream> readConnectionPreface(Stream> incoming) { } result.onListen = () { - subscription = incoming.listen(onData, - onError: (Object e, StackTrace s) => result.addError(e, s), - onDone: () { - if (!connectionPrefaceRead) { - terminate('EOS before connection preface could be read.'); - } else { - result.close(); - } - }); + subscription = + incoming.listen(onData, onError: result.addError, onDone: () { + if (!connectionPrefaceRead) { + terminate('EOS before connection preface could be read.'); + } else { + result.close(); + } + }); result ..onPause = subscription.pause ..onResume = subscription.resume diff --git a/lib/src/error_handler.dart b/lib/src/error_handler.dart index f7eed21..a8e1920 100644 --- a/lib/src/error_handler.dart +++ b/lib/src/error_handler.dart @@ -11,7 +11,7 @@ mixin TerminatableMixin { bool _terminated = false; /// Terminates this stream message queue. Further operations on it will fail. - void terminate([error]) { + void terminate([Object? error]) { if (!wasTerminated) { _terminated = true; onTerminated(error); @@ -60,7 +60,7 @@ mixin CancellableMixin { /// Used by classes which may be closed. mixin ClosableMixin { bool _closing = false; - final Completer _completer = Completer(); + final Completer _completer = Completer(); Future get done => _completer.future; @@ -91,13 +91,13 @@ mixin ClosableMixin { return f(); } - void closeWithValue([value]) { + void closeWithValue([Object? value]) { if (!wasClosed) { _completer.complete(value); } } - void closeWithError(error) { + void closeWithError(Object? error) { if (!wasClosed) { _completer.complete(error); } diff --git a/lib/src/flowcontrol/connection_queues.dart b/lib/src/flowcontrol/connection_queues.dart index 7382884..f1a499a 100644 --- a/lib/src/flowcontrol/connection_queues.dart +++ b/lib/src/flowcontrol/connection_queues.dart @@ -10,11 +10,9 @@ import 'dart:async'; import 'dart:collection'; import '../../transport.dart'; - import '../byte_utils.dart'; import '../error_handler.dart'; import '../frames/frames.dart'; - import 'queue_messages.dart'; import 'stream_queues.dart'; import 'window_handler.dart'; @@ -66,7 +64,7 @@ class ConnectionMessageQueueOut extends Object } @override - void onTerminated(error) { + void onTerminated(Object? error) { _messages.clear(); closeWithError(error); } @@ -182,7 +180,7 @@ class ConnectionMessageQueueIn extends Object final IncomingWindowHandler _windowUpdateHandler; /// Catches any protocol errors and acts upon them. - final Function _catchProtocolErrors; + final void Function(void Function()) _catchProtocolErrors; /// A mapping from stream-id to the corresponding stream-specific /// [StreamMessageQueueIn]. @@ -200,7 +198,7 @@ class ConnectionMessageQueueIn extends Object this._windowUpdateHandler, this._catchProtocolErrors); @override - void onTerminated(error) { + void onTerminated(Object? error) { // NOTE: The higher level will be shutdown first, so all streams // should have been removed at this point. assert(_stream2messageQueue.isEmpty); diff --git a/lib/src/flowcontrol/stream_queues.dart b/lib/src/flowcontrol/stream_queues.dart index ff9711c..de7950a 100644 --- a/lib/src/flowcontrol/stream_queues.dart +++ b/lib/src/flowcontrol/stream_queues.dart @@ -84,7 +84,7 @@ class StreamMessageQueueOut extends Object } @override - void onTerminated(error) { + void onTerminated(Object? error) { _messages.clear(); closeWithError(error); } @@ -183,11 +183,7 @@ class StreamMessageQueueIn extends Object _tryUpdateBufferIndicator(); } } - ..onPause = () { - _tryUpdateBufferIndicator(); - // TODO: Would we ever want to decrease the window size in this - // situation? - } + ..onPause = _tryUpdateBufferIndicator ..onResume = () { if (!wasClosed && !wasTerminated) { _tryDispatch(); diff --git a/lib/src/flowcontrol/window_handler.dart b/lib/src/flowcontrol/window_handler.dart index 6f9a5a6..27d0321 100644 --- a/lib/src/flowcontrol/window_handler.dart +++ b/lib/src/flowcontrol/window_handler.dart @@ -58,12 +58,12 @@ abstract class AbstractOutgoingWindowHandler { /// Handles the connection window for outgoing data frames. class OutgoingConnectionWindowHandler extends AbstractOutgoingWindowHandler { - OutgoingConnectionWindowHandler(Window window) : super(window); + OutgoingConnectionWindowHandler(super.window); } /// Handles the window for outgoing messages to the peer. class OutgoingStreamWindowHandler extends AbstractOutgoingWindowHandler { - OutgoingStreamWindowHandler(Window window) : super(window); + OutgoingStreamWindowHandler(super.window); /// Update the peer window by adding [difference] to it. /// diff --git a/lib/src/frames/frame_reader.dart b/lib/src/frames/frame_reader.dart index 2d93f01..7b69261 100644 --- a/lib/src/frames/frame_reader.dart +++ b/lib/src/frames/frame_reader.dart @@ -2,7 +2,7 @@ // 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. -part of http2.src.frames; +part of 'frames.dart'; /// Used for converting a `Stream>` to a `Stream`. class FrameReader { diff --git a/lib/src/frames/frame_types.dart b/lib/src/frames/frame_types.dart index abab588..33c9e4a 100644 --- a/lib/src/frames/frame_types.dart +++ b/lib/src/frames/frame_types.dart @@ -2,7 +2,7 @@ // 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. -part of http2.src.frames; +part of 'frames.dart'; const int FRAME_HEADER_SIZE = 9; @@ -67,7 +67,7 @@ class DataFrame extends Frame { final List bytes; - DataFrame(FrameHeader header, this.padLength, this.bytes) : super(header); + DataFrame(super.header, this.padLength, this.bytes); bool get hasEndStreamFlag => _isFlagSet(header.flags, FLAG_END_STREAM); bool get hasPaddedFlag => _isFlagSet(header.flags, FLAG_PADDED); @@ -99,9 +99,14 @@ class HeadersFrame extends Frame { final int? weight; final List headerBlockFragment; - HeadersFrame(FrameHeader header, this.padLength, this.exclusiveDependency, - this.streamDependency, this.weight, this.headerBlockFragment) - : super(header); + HeadersFrame( + super.header, + this.padLength, + this.exclusiveDependency, + this.streamDependency, + this.weight, + this.headerBlockFragment, + ); /// This will be set from the outside after decoding. late List
decodedHeaders; @@ -148,9 +153,12 @@ class PriorityFrame extends Frame { final int streamDependency; final int weight; - PriorityFrame(FrameHeader header, this.exclusiveDependency, - this.streamDependency, this.weight) - : super(header); + PriorityFrame( + super.header, + this.exclusiveDependency, + this.streamDependency, + this.weight, + ); @override Map toJson() => super.toJson() @@ -166,7 +174,7 @@ class RstStreamFrame extends Frame { final int errorCode; - RstStreamFrame(FrameHeader header, this.errorCode) : super(header); + RstStreamFrame(super.header, this.errorCode); @override Map toJson() => super.toJson() @@ -199,7 +207,7 @@ class SettingsFrame extends Frame { final List settings; - SettingsFrame(FrameHeader header, this.settings) : super(header); + SettingsFrame(super.header, this.settings); bool get hasAckFlag => _isFlagSet(header.flags, FLAG_ACK); @@ -225,9 +233,12 @@ class PushPromiseFrame extends Frame { /// This will be set from the outside after decoding. late List
decodedHeaders; - PushPromiseFrame(FrameHeader header, this.padLength, this.promisedStreamId, - this.headerBlockFragment) - : super(header); + PushPromiseFrame( + super.header, + this.padLength, + this.promisedStreamId, + this.headerBlockFragment, + ); bool get hasEndHeadersFlag => _isFlagSet(header.flags, FLAG_END_HEADERS); bool get hasPaddedFlag => _isFlagSet(header.flags, FLAG_PADDED); @@ -267,7 +278,7 @@ class PingFrame extends Frame { final int opaqueData; - PingFrame(FrameHeader header, this.opaqueData) : super(header); + PingFrame(super.header, this.opaqueData); bool get hasAckFlag => _isFlagSet(header.flags, FLAG_ACK); @@ -283,9 +294,7 @@ class GoawayFrame extends Frame { final int errorCode; final List debugData; - GoawayFrame( - FrameHeader header, this.lastStreamId, this.errorCode, this.debugData) - : super(header); + GoawayFrame(super.header, this.lastStreamId, this.errorCode, this.debugData); @override Map toJson() => super.toJson() @@ -301,8 +310,7 @@ class WindowUpdateFrame extends Frame { final int windowSizeIncrement; - WindowUpdateFrame(FrameHeader header, this.windowSizeIncrement) - : super(header); + WindowUpdateFrame(super.header, this.windowSizeIncrement); @override Map toJson() => super.toJson() @@ -316,8 +324,7 @@ class ContinuationFrame extends Frame { final List headerBlockFragment; - ContinuationFrame(FrameHeader header, this.headerBlockFragment) - : super(header); + ContinuationFrame(super.header, this.headerBlockFragment); bool get hasEndHeadersFlag => _isFlagSet(header.flags, FLAG_END_HEADERS); @@ -331,7 +338,7 @@ class ContinuationFrame extends Frame { class UnknownFrame extends Frame { final List data; - UnknownFrame(FrameHeader header, this.data) : super(header); + UnknownFrame(super.header, this.data); @override Map toJson() => super.toJson() diff --git a/lib/src/frames/frame_utils.dart b/lib/src/frames/frame_utils.dart index 73a3173..11c30a5 100644 --- a/lib/src/frames/frame_utils.dart +++ b/lib/src/frames/frame_utils.dart @@ -2,6 +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. -part of http2.src.frames; +part of 'frames.dart'; bool _isFlagSet(int value, int flag) => value & flag == flag; diff --git a/lib/src/frames/frame_writer.dart b/lib/src/frames/frame_writer.dart index 211aa54..50caad7 100644 --- a/lib/src/frames/frame_writer.dart +++ b/lib/src/frames/frame_writer.dart @@ -2,7 +2,7 @@ // 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. -part of http2.src.frames; +part of 'frames.dart'; // TODO: No support for writing padded information. // TODO: No support for stream priorities. diff --git a/lib/src/hpack/hpack.dart b/lib/src/hpack/hpack.dart index f34e043..ab5d9c8 100644 --- a/lib/src/hpack/hpack.dart +++ b/lib/src/hpack/hpack.dart @@ -11,7 +11,6 @@ import 'dart:convert' show ascii; import 'dart:typed_data'; import '../byte_utils.dart'; - import 'huffman.dart'; import 'huffman_table.dart'; @@ -157,6 +156,7 @@ class HPackDecoder { } } return headers; + // ignore: avoid_catching_errors } on RangeError catch (e) { throw HPackDecodingException('$e'); } on HuffmanDecodingException catch (e) { diff --git a/lib/src/ping/ping_handler.dart b/lib/src/ping/ping_handler.dart index 49bd6cc..f9be1f9 100644 --- a/lib/src/ping/ping_handler.dart +++ b/lib/src/ping/ping_handler.dart @@ -61,7 +61,7 @@ class PingHandler extends Object with TerminatableMixin { Future ping() { return ensureNotTerminatedAsync(() { - var c = Completer(); + var c = Completer(); var id = _nextId++; _remainingPings[id] = c; _frameWriter.writePingFrame(id); diff --git a/lib/src/settings/settings.dart b/lib/src/settings/settings.dart index 948658d..291c668 100644 --- a/lib/src/settings/settings.dart +++ b/lib/src/settings/settings.dart @@ -163,7 +163,7 @@ class SettingsHandler extends Object with TerminatableMixin { return ensureNotTerminatedAsync(() { // TODO: Have a timeout: When ACK doesn't get back in a reasonable time // frame we should quit with ErrorCode.SETTINGS_TIMEOUT. - var completer = Completer(); + var completer = Completer(); _toBeAcknowledgedSettings.add(changes); _toBeAcknowledgedCompleters.add(completer); _frameWriter.writeSettingsFrame(changes); diff --git a/lib/src/streams/stream_handler.dart b/lib/src/streams/stream_handler.dart index 4018d3a..92a228d 100644 --- a/lib/src/streams/stream_handler.dart +++ b/lib/src/streams/stream_handler.dart @@ -283,7 +283,7 @@ class StreamHandler extends Object with TerminatableMixin, ClosableMixin { 'not in "idle" state.'); } - var sameDirection = (nextStreamId + remoteStreamId) % 2 == 0; + var sameDirection = (nextStreamId + remoteStreamId).isEven; assert(!sameDirection); lastRemoteStreamId = remoteStreamId; @@ -343,7 +343,7 @@ class StreamHandler extends Object with TerminatableMixin, ClosableMixin { // NOTE: We are not interested whether the streams were normally finished // or abnormally terminated. Therefore we use 'catchError((_) {})'! var streamDone = [streamQueueIn.done, streamQueueOut.done]; - Future.wait(streamDone).catchError((_) => const []).whenComplete(() { + Future.wait(streamDone).catchError((_) => const []).whenComplete(() { _cleanupClosedStream(stream); }); diff --git a/lib/src/sync_errors.dart b/lib/src/sync_errors.dart index 2423e6a..3d11616 100644 --- a/lib/src/sync_errors.dart +++ b/lib/src/sync_errors.dart @@ -45,8 +45,7 @@ class StreamException implements Exception { } class StreamClosedException extends StreamException { - StreamClosedException(int streamId, [String message = '']) - : super(streamId, message); + StreamClosedException(super.streamId, [super.message = '']); @override String toString() => 'StreamClosedException(stream id: $streamId): $_message'; diff --git a/lib/transport.dart b/lib/transport.dart index af37cf6..87a10f6 100644 --- a/lib/transport.dart +++ b/lib/transport.dart @@ -8,8 +8,8 @@ import 'dart:io'; import 'src/connection.dart'; import 'src/hpack/hpack.dart' show Header; -export 'src/hpack/hpack.dart' show Header; export 'src/frames/frames.dart' show ErrorCode; +export 'src/hpack/hpack.dart' show Header; typedef ActiveStateHandler = void Function(bool isActive); @@ -28,10 +28,7 @@ abstract class Settings { /// Settings for a [TransportConnection] a server can make. class ServerSettings extends Settings { - const ServerSettings({int? concurrentStreamLimit, int? streamWindowSize}) - : super( - concurrentStreamLimit: concurrentStreamLimit, - streamWindowSize: streamWindowSize); + const ServerSettings({super.concurrentStreamLimit, super.streamWindowSize}); } /// Settings for a [TransportConnection] a client can make. @@ -40,12 +37,9 @@ class ClientSettings extends Settings { final bool allowServerPushes; const ClientSettings( - {int? concurrentStreamLimit, - int? streamWindowSize, - this.allowServerPushes = false}) - : super( - concurrentStreamLimit: concurrentStreamLimit, - streamWindowSize: streamWindowSize); + {super.concurrentStreamLimit, + super.streamWindowSize, + this.allowServerPushes = false}); } /// Represents a HTTP/2 connection. @@ -194,8 +188,7 @@ abstract class StreamMessage { class DataStreamMessage extends StreamMessage { final List bytes; - DataStreamMessage(this.bytes, {bool? endStream}) - : super(endStream: endStream); + DataStreamMessage(this.bytes, {super.endStream}); @override String toString() => 'DataStreamMessage(${bytes.length} bytes)'; @@ -205,8 +198,7 @@ class DataStreamMessage extends StreamMessage { class HeadersStreamMessage extends StreamMessage { final List
headers; - HeadersStreamMessage(this.headers, {bool? endStream}) - : super(endStream: endStream); + HeadersStreamMessage(this.headers, {super.endStream}); @override String toString() => 'HeadersStreamMessage(${headers.length} headers)'; diff --git a/manual_test/out_of_stream_ids_test.dart b/manual_test/out_of_stream_ids_test.dart index d653793..acfbbd9 100644 --- a/manual_test/out_of_stream_ids_test.dart +++ b/manual_test/out_of_stream_ids_test.dart @@ -11,6 +11,8 @@ /// /// without this patch this test will run for a _long_ time. /// --------------------------------------------------------------------------- +library; + import 'dart:async'; import 'package:http2/src/streams/stream_handler.dart'; @@ -46,7 +48,7 @@ void main() { expect(() => client.makeRequest(headers), throwsA(const TypeMatcher())); - await Future.delayed(const Duration(seconds: 1)); + await Future.delayed(const Duration(seconds: 1)); await client.finish(); } diff --git a/pubspec.yaml b/pubspec.yaml index d8d21c8..72528e2 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,13 +1,13 @@ name: http2 -version: 2.3.0 +version: 2.3.1-wip description: A HTTP/2 implementation in Dart. repository: https://github.com/dart-lang/http2 environment: - sdk: '>=3.0.0 <4.0.0' + sdk: ^3.2.0 dev_dependencies: build_runner: ^2.3.0 - lints: ^2.0.0 + dart_flutter_team_lints: ^2.0.0 mockito: ^5.3.2 test: ^1.21.4 diff --git a/test/client_test.dart b/test/client_test.dart index cf66a9e..726707f 100644 --- a/test/client_test.dart +++ b/test/client_test.dart @@ -24,7 +24,7 @@ void main() { FrameWriter serverWriter, StreamIterator serverReader, Future Function() nextFrame) async { - var settingsDone = Completer(); + var settingsDone = Completer(); Future serverFun() async { serverWriter.writeSettingsFrame([]); @@ -67,7 +67,7 @@ void main() { FrameWriter serverWriter, StreamIterator serverReader, Future Function() nextFrame) async { - final settingsDone = Completer(); + final settingsDone = Completer(); Future serverFun() async { serverWriter.writeSettingsFrame([]); @@ -89,7 +89,7 @@ void main() { Future clientFun() async { await settingsDone.future; await client.onInitialPeerSettingsReceived - .timeout(Duration(milliseconds: 20)); // Should complete + .timeout(const Duration(milliseconds: 20)); // Should complete expect(client.isOpen, true); @@ -109,7 +109,7 @@ void main() { FrameWriter serverWriter, StreamIterator serverReader, Future Function() nextFrame) async { - final goawayReceived = Completer(); + final goawayReceived = Completer(); Future serverFun() async { serverWriter.writePingFrame(42); expect(await nextFrame(), isA()); @@ -123,7 +123,7 @@ void main() { expect( client.onInitialPeerSettingsReceived - .timeout(Duration(seconds: 1)), + .timeout(const Duration(seconds: 1)), throwsA(isA())); // We wait until the server received the error (it's actually later @@ -153,7 +153,7 @@ void main() { FrameWriter serverWriter, StreamIterator serverReader, Future Function() nextFrame) async { - var goawayReceived = Completer(); + var goawayReceived = Completer(); Future serverFun() async { serverWriter.writePingFrame(42); expect(await nextFrame(), isA()); @@ -220,7 +220,7 @@ void main() { FrameWriter serverWriter, StreamIterator serverReader, Future Function() nextFrame) async { - var handshakeCompleter = Completer(); + var handshakeCompleter = Completer(); Future serverFun() async { serverWriter.writeSettingsFrame([]); @@ -281,7 +281,7 @@ void main() { FrameWriter serverWriter, StreamIterator serverReader, Future Function() nextFrame) async { - var handshakeCompleter = Completer(); + var handshakeCompleter = Completer(); Future serverFun() async { serverWriter.writeSettingsFrame([]); @@ -373,9 +373,9 @@ void main() { FrameWriter serverWriter, StreamIterator serverReader, Future Function() nextFrame) async { - var handshakeCompleter = Completer(); - var cancelDone = Completer(); - var endDone = Completer(); + var handshakeCompleter = Completer(); + var cancelDone = Completer(); + var endDone = Completer(); Future serverFun() async { serverWriter.writeSettingsFrame([]); @@ -463,10 +463,10 @@ void main() { FrameWriter serverWriter, StreamIterator serverReader, Future Function() nextFrame) async { - var handshakeCompleter = Completer(); - var cancelDone = Completer(); - var endDone = Completer(); - var clientDone = Completer(); + var handshakeCompleter = Completer(); + var cancelDone = Completer(); + var endDone = Completer(); + var clientDone = Completer(); Future serverFun() async { serverWriter.writeSettingsFrame([]); @@ -550,7 +550,7 @@ void main() { FrameWriter serverWriter, StreamIterator serverReader, Future Function() nextFrame) async { - var handshakeCompleter = Completer(); + var handshakeCompleter = Completer(); Future serverFun() async { serverWriter.writeSettingsFrame([]); @@ -610,7 +610,7 @@ void main() { FrameWriter serverWriter, StreamIterator serverReader, Future Function() nextFrame) async { - var handshakeCompleter = Completer(); + var handshakeCompleter = Completer(); Future serverFun() async { serverWriter.writeSettingsFrame([]); @@ -661,7 +661,7 @@ void main() { FrameWriter serverWriter, StreamIterator serverReader, Future Function() nextFrame) async { - var handshakeCompleter = Completer(); + var handshakeCompleter = Completer(); Future serverFun() async { serverWriter.writeSettingsFrame([]); @@ -702,7 +702,7 @@ void main() { expectAsync1((StreamMessage msg) {}, count: 0), onError: expectAsync1((Object error) {})); sub.pause(); - await Future.delayed(const Duration(milliseconds: 40)); + await Future.delayed(const Duration(milliseconds: 40)); sub.resume(); await client.finish(); @@ -717,8 +717,8 @@ void main() { FrameWriter serverWriter, StreamIterator serverReader, Future Function() nextFrame) async { - var settingsDone = Completer(); - var headersDone = Completer(); + var settingsDone = Completer(); + var headersDone = Completer(); Future serverFun() async { var decoder = HPackDecoder(); @@ -781,7 +781,7 @@ void main() { FrameWriter serverWriter, StreamIterator serverReader, Future Function() nextFrame) async { - var settingsDone = Completer(); + var settingsDone = Completer(); Future serverFun() async { var decoder = HPackDecoder(); diff --git a/test/multiprotocol_server_test.dart b/test/multiprotocol_server_test.dart index 997f0da..736e7da 100644 --- a/test/multiprotocol_server_test.dart +++ b/test/multiprotocol_server_test.dart @@ -74,7 +74,7 @@ Future makeHttp11Request( Future handleHttp11Request(HttpRequest request, int i) async { expect(request.uri.path, '/abc$i'); - await request.drain(); + await request.drain(); request.response.write('answer$i'); await request.response.close(); } diff --git a/test/src/hpack/hpack_test.dart b/test/src/hpack/hpack_test.dart index 4d3bf53..aadf6cb 100644 --- a/test/src/hpack/hpack_test.dart +++ b/test/src/hpack/hpack_test.dart @@ -609,8 +609,8 @@ void main() { test('update-dynamic-table-size-too-high', () { var context = HPackContext(); // Sets dynamic table to 4096 - expect( - context.decoder.decode(TestHelper.newInteger(0x20, 5, 4096)), []); + expect(context.decoder.decode(TestHelper.newInteger(0x20, 5, 4096)), + []); }); test('dynamic table entry', () { @@ -809,7 +809,7 @@ class _HeaderMatcher extends Matcher { Description describe(Description description) => description.add('Header'); @override - bool matches(item, Map matchState) { + bool matches(Object? item, Map matchState) { return item is Header && _compareLists(item.name, header.name) && _compareLists(item.value, header.value); diff --git a/test/src/ping/ping_handler_test.dart b/test/src/ping/ping_handler_test.dart index ef5250d..df02420 100644 --- a/test/src/ping/ping_handler_test.dart +++ b/test/src/ping/ping_handler_test.dart @@ -98,8 +98,7 @@ void main() { final pings = []; final writer = FrameWriterMock(); - final pingStream = StreamController() - ..stream.listen((event) => pings.add(event)); + final pingStream = StreamController()..stream.listen(pings.add); PingHandler(writer, pingStream) ..processPingFrame(PingFrame( @@ -119,7 +118,7 @@ void main() { } PingHandler instantiateHandler(FrameWriterMock writer) { - StreamController controller = StreamController(); + var controller = StreamController(); return PingHandler(writer, controller); } diff --git a/test/src/streams/simple_flow_test.dart b/test/src/streams/simple_flow_test.dart index 7a29468..25226d1 100644 --- a/test/src/streams/simple_flow_test.dart +++ b/test/src/streams/simple_flow_test.dart @@ -30,7 +30,7 @@ void main() { }); } - var serverReceivedAllBytes = Completer(); + var serverReceivedAllBytes = Completer(); void Function(StreamMessage) messageTestFun(String type) { var expectHeader = true; @@ -83,7 +83,7 @@ void main() { sStream.incomingMessages .listen(messageTestFun('server'), onDone: expectAsync0(() {})); sStream.sendHeaders(expectedHeaders, endStream: true); - expect(await serverReceivedAllBytes.future, completes); + await serverReceivedAllBytes.future; })); TransportStream cStream = client.makeRequest(expectedHeaders); diff --git a/test/src/streams/simple_push_test.dart b/test/src/streams/simple_push_test.dart index e91f95b..d12dbb5 100644 --- a/test/src/streams/simple_push_test.dart +++ b/test/src/streams/simple_push_test.dart @@ -34,7 +34,7 @@ void main() { }); } - var serverReceivedAllBytes = Completer(); + var serverReceivedAllBytes = Completer(); Future readData(StreamIterator iterator) async { var all = []; @@ -66,7 +66,7 @@ void main() { unawaited(sStream.incomingMessages.drain()); sStream.sendHeaders(expectedHeaders, endStream: true); - expect(await serverReceivedAllBytes.future, completes); + await serverReceivedAllBytes.future; })); var cStream = client.makeRequest(expectedHeaders, endStream: true); @@ -84,7 +84,7 @@ void main() { var msg = await readData(iterator); expect(msg, 'pushing "hello world" :)'); })); - }, settings: ClientSettings(allowServerPushes: true)); + }, settings: const ClientSettings(allowServerPushes: true)); }); }); } diff --git a/test/src/streams/streams_test.dart b/test/src/streams/streams_test.dart index 18109fc..6bfa49c 100644 --- a/test/src/streams/streams_test.dart +++ b/test/src/streams/streams_test.dart @@ -67,7 +67,7 @@ void main() { server.incomingStreams .listen(expectAsync1((TransportStream sStream) async { var isFirst = true; - var receivedChunks = []; + var receivedChunks = >[]; sStream.incomingMessages.listen( expectAsync1((StreamMessage msg) { if (isFirst) { diff --git a/test/transport_test.dart b/test/transport_test.dart index e227ed2..96c2c03 100644 --- a/test/transport_test.dart +++ b/test/transport_test.dart @@ -67,8 +67,8 @@ void main() { // The default is unlimited, which is why we have to wait for the server // setting to arrive on the client. // At the moment, delaying by 2 microtask cycles is enough. - await Future.value(); - await Future.value(); + await Future.value(); + await Future.value(); final streams = []; for (var i = 0; i < concurrentStreamLimit; ++i) { @@ -93,7 +93,7 @@ void main() { await Future.wait([clientFun(), serverFun()]); }, serverSettings: - ServerSettings(concurrentStreamLimit: concurrentStreamLimit)); + const ServerSettings(concurrentStreamLimit: concurrentStreamLimit)); transportTest('disabled-push', (ClientTransportConnection client, ServerTransportConnection server) async { @@ -188,7 +188,7 @@ void main() { await client.terminate(); await serverFuture; }, - clientSettings: ClientSettings( + clientSettings: const ClientSettings( concurrentStreamLimit: kDefaultStreamLimit, allowServerPushes: true)); @@ -216,7 +216,7 @@ void main() { transportTest('client-terminates-stream', (ClientTransportConnection client, ServerTransportConnection server) async { - var readyForError = Completer(); + var readyForError = Completer(); Future serverFun() async { await for (ServerTransportStream stream in server.incomingStreams) { @@ -268,7 +268,7 @@ void main() { transportTest('client-terminates-stream-after-half-close', (ClientTransportConnection client, ServerTransportConnection server) async { - var readyForError = Completer(); + var readyForError = Completer(); Future serverFun() async { await for (ServerTransportStream stream in server.incomingStreams) { @@ -304,7 +304,7 @@ void main() { transportTest('server-terminates-stream-after-half-close', (ClientTransportConnection client, ServerTransportConnection server) async { - var readyForError = Completer(); + var readyForError = Completer(); Future serverFun() async { await for (ServerTransportStream stream in server.incomingStreams) { @@ -375,19 +375,19 @@ void main() { // This extra await is needed to allow the idle handler to run before // verifying the idleCount, because the stream cleanup runs // asynchronously after the stream is closed. - await Future.value(); + await Future.value(); expect(activeCount, 1); expect(idleCount, 1); var stream = client.makeRequest([]); await stream.outgoingMessages.close(); await stream.incomingMessages.toList(); - await Future.value(); + await Future.value(); stream = client.makeRequest([]); await stream.outgoingMessages.close(); await stream.incomingMessages.toList(); - await Future.value(); + await Future.value(); await client.finish(); expect(activeCount, 3); @@ -410,7 +410,7 @@ void main() { lessThan(kChunkSize * kNumberOfMessages)); var serverSentBytes = 0; - var flowcontrolWindowFull = Completer(); + var flowcontrolWindowFull = Completer(); Future serverFun() async { await for (ServerTransportStream stream in server.incomingStreams) { @@ -438,9 +438,7 @@ void main() { } controller - ..onListen = () { - addData(); - } + ..onListen = addData ..onPause = expectAsync0(() { // Assert that we're now at the place (since the granularity // of adding is [kChunkSize], it could be that we added @@ -450,9 +448,7 @@ void main() { lessThan(expectedStreamFlowcontrolWindow)); flowcontrolWindowFull.complete(); }) - ..onResume = () { - addData(); - } + ..onResume = addData ..onCancel = () {}; await stream.outgoingMessages.addStream(controller.stream); @@ -506,7 +502,7 @@ void main() { (ClientTransportConnection client, ServerTransportConnection server) async { await testWindowSize(client, server, 8096); - }, clientSettings: ClientSettings(streamWindowSize: 8096)); + }, clientSettings: const ClientSettings(streamWindowSize: 8096)); }); }); }