Skip to content
This repository has been archived by the owner on Oct 17, 2024. It is now read-only.

Commit

Permalink
tiny bit more cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
kevmoo committed Feb 13, 2024
1 parent 26690d3 commit f5a08a3
Show file tree
Hide file tree
Showing 19 changed files with 112 additions and 109 deletions.
2 changes: 1 addition & 1 deletion test/async_cache_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ void main() {
Future<String> throwingCall() async => throw Exception();
await expectLater(cache.fetch(throwingCall), throwsA(isException));
// To let the timer invalidate the cache
await Future.delayed(const Duration(milliseconds: 5));
await Future<void>.delayed(const Duration(milliseconds: 5));

Future<String> call() async => 'Completed';
expect(await cache.fetch(call), 'Completed', reason: 'Cache invalidates');
Expand Down
34 changes: 18 additions & 16 deletions test/cancelable_operation_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ void main() {
});

test('is not complete until the result is available', () async {
var backingWork = Completer();
var backingWork = Completer<void>();
var operation = CancelableOperation.fromFuture(backingWork.future);
expect(operation.isCompleted, isFalse);
backingWork.complete();
Expand All @@ -132,17 +132,19 @@ void main() {

test('successfully then with a future', () {
completer.complete(1);
expect(() => completer.complete(Completer().future), throwsStateError);
expect(() => completer.complete(Completer<void>().future),
throwsStateError);
});

test('with a future then successfully', () {
completer.complete(Completer().future);
completer.complete(Completer<void>().future);
expect(() => completer.complete(1), throwsStateError);
});

test('with a future twice', () {
completer.complete(Completer().future);
expect(() => completer.complete(Completer().future), throwsStateError);
completer.complete(Completer<void>().future);
expect(() => completer.complete(Completer<void>().future),
throwsStateError);
});
});

Expand Down Expand Up @@ -185,7 +187,7 @@ void main() {

group('when canceled', () {
test('causes the future never to fire', () async {
var completer = CancelableCompleter();
var completer = CancelableCompleter<void>();
completer.operation.value.whenComplete(expectAsync0(() {}, count: 0));
completer.operation.cancel();

Expand Down Expand Up @@ -242,7 +244,7 @@ void main() {
'does call onCancel if the completer has completed to an unfired '
'Future', () {
var completer = CancelableCompleter(onCancel: expectAsync0(() {}));
completer.complete(Completer().future);
completer.complete(Completer<void>().future);
expect(completer.operation.cancel(), completes);
});

Expand All @@ -257,15 +259,15 @@ void main() {
});

test('can be completed once after being canceled', () async {
var completer = CancelableCompleter();
var completer = CancelableCompleter<int>();
completer.operation.value.whenComplete(expectAsync0(() {}, count: 0));
await completer.operation.cancel();
completer.complete(1);
expect(() => completer.complete(1), throwsStateError);
});

test('fires valueOrCancellation with the given value', () {
var completer = CancelableCompleter();
var completer = CancelableCompleter<int>();
expect(completer.operation.valueOrCancellation(1), completion(equals(1)));
completer.operation.cancel();
});
Expand All @@ -279,7 +281,7 @@ void main() {
});

test('valueOrCancellation waits on the onCancel future', () async {
var innerCompleter = Completer();
var innerCompleter = Completer<void>();
var completer =
CancelableCompleter(onCancel: () => innerCompleter.future);

Expand Down Expand Up @@ -389,13 +391,13 @@ void main() {

group('asStream()', () {
test('emits a value and then closes', () {
var completer = CancelableCompleter();
var completer = CancelableCompleter<int>();
expect(completer.operation.asStream().toList(), completion(equals([1])));
completer.complete(1);
});

test('emits an error and then closes', () {
var completer = CancelableCompleter();
var completer = CancelableCompleter<void>();
var queue = StreamQueue(completer.operation.asStream());
expect(queue.next, throwsA('error'));
expect(queue.hasNext, completion(isFalse));
Expand Down Expand Up @@ -425,7 +427,7 @@ void main() {
onError = expectAsync2((e, s) => 'Fake', count: 0, id: 'onError');
onCancel = expectAsync0(() => 'Fake', count: 0, id: 'onCancel');
propagateCancel = false;
originalCompleter = CancelableCompleter();
originalCompleter = CancelableCompleter<int>();
});

CancelableOperation<String> runThen() {
Expand Down Expand Up @@ -574,8 +576,8 @@ void main() {
test('waits for chained cancellation', () async {
var completer = CancelableCompleter<void>();
var chainedOperation = completer.operation
.then((_) => Future.delayed(const Duration(milliseconds: 1)))
.then((_) => Future.delayed(const Duration(milliseconds: 1)));
.then((_) => Future<void>.delayed(const Duration(milliseconds: 1)))
.then((_) => Future<void>.delayed(const Duration(milliseconds: 1)));

await completer.operation.cancel();
expect(completer.operation.isCanceled, true);
Expand Down Expand Up @@ -655,7 +657,7 @@ void main() {
onError = null;
onCancel = null;
propagateCancel = false;
originalCompleter = CancelableCompleter();
originalCompleter = CancelableCompleter<int>();
});

CancelableOperation<String> runThenOperation() {
Expand Down
4 changes: 2 additions & 2 deletions test/chunked_stream_reader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ void main() {
final r = ChunkedStreamReader(() async* {
yield [1, 2, 3];
// This will hang forever, so we will call cancel()
await Completer().future;
await Completer<void>().future;
yield [4]; // this should never be reachable
fail('unreachable!');
}());
Expand All @@ -362,7 +362,7 @@ void main() {
final r = ChunkedStreamReader(() async* {
yield [1, 2, 3];
// This will hang forever, so we will call cancel()
await Completer().future;
await Completer<void>().future;
yield [4]; // this should never be reachable
fail('unreachable!');
}());
Expand Down
30 changes: 15 additions & 15 deletions test/future_group_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ void main() {
});

test('completes once all contained futures complete', () async {
var completer1 = Completer();
var completer2 = Completer();
var completer3 = Completer();
var completer1 = Completer<void>();
var completer2 = Completer<void>();
var completer3 = Completer<void>();

futureGroup.add(completer1.future);
futureGroup.add(completer2.future);
Expand All @@ -93,9 +93,9 @@ void main() {
});

test('completes to the values of the futures in order of addition', () {
var completer1 = Completer();
var completer2 = Completer();
var completer3 = Completer();
var completer1 = Completer<int>();
var completer2 = Completer<int>();
var completer3 = Completer<int>();

futureGroup.add(completer1.future);
futureGroup.add(completer2.future);
Expand All @@ -112,9 +112,9 @@ void main() {

test("completes to the first error to be emitted, even if it's not closed",
() {
var completer1 = Completer();
var completer2 = Completer();
var completer3 = Completer();
var completer1 = Completer<void>();
var completer2 = Completer<void>();
var completer3 = Completer<void>();

futureGroup.add(completer1.future);
futureGroup.add(completer2.future);
Expand All @@ -130,9 +130,9 @@ void main() {
var idle = false;
futureGroup.onIdle.listen((_) => idle = true);

var completer1 = Completer();
var completer2 = Completer();
var completer3 = Completer();
var completer1 = Completer<void>();
var completer2 = Completer<void>();
var completer3 = Completer<void>();

futureGroup.add(completer1.future);
futureGroup.add(completer2.future);
Expand Down Expand Up @@ -162,7 +162,7 @@ void main() {
var idle = false;
futureGroup.onIdle.listen((_) => idle = true);

var completer = Completer();
var completer = Completer<void>();
futureGroup.add(completer.future);

completer.complete();
Expand All @@ -171,7 +171,7 @@ void main() {
expect(futureGroup.isIdle, isTrue);

idle = false;
completer = Completer();
completer = Completer<void>();
futureGroup.add(completer.future);

await flushMicrotasks();
Expand Down Expand Up @@ -206,7 +206,7 @@ void main() {
futureFired = true;
}));

var completer = Completer();
var completer = Completer<void>();
futureGroup.add(completer.future);
futureGroup.close();

Expand Down
4 changes: 2 additions & 2 deletions test/null_stream_sink_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ void main() {
});

test('a custom future may be passed to done', () async {
var completer = Completer();
var completer = Completer<void>();
var sink = NullStreamSink(done: completer.future);

var doneFired = false;
Expand Down Expand Up @@ -68,7 +68,7 @@ void main() {
});

test('returns the cancel future', () async {
var completer = Completer();
var completer = Completer<void>();
var sink = NullStreamSink();
var controller = StreamController(onCancel: () => completer.future);

Expand Down
10 changes: 5 additions & 5 deletions test/reject_errors_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import 'package:test/test.dart';
void main() {
late StreamController controller;
setUp(() {
controller = StreamController();
controller = StreamController<void>();
});

test('passes through data events', () {
Expand Down Expand Up @@ -89,7 +89,7 @@ void main() {

group('when the inner sink\'s done future completes', () {
test('done completes', () async {
var completer = Completer();
var completer = Completer<void>();
var transformed = NullStreamSink(done: completer.future).rejectErrors();

var doneCompleted = false;
Expand All @@ -103,7 +103,7 @@ void main() {
});

test('an outstanding addStream() completes', () async {
var completer = Completer();
var completer = Completer<void>();
var transformed = NullStreamSink(done: completer.future).rejectErrors();

var addStreamCompleted = false;
Expand All @@ -119,7 +119,7 @@ void main() {
});

test('an outstanding addStream()\'s subscription is cancelled', () async {
var completer = Completer();
var completer = Completer<void>();
var transformed = NullStreamSink(done: completer.future).rejectErrors();

var addStreamCancelled = false;
Expand All @@ -134,7 +134,7 @@ void main() {
});

test('forwards an outstanding addStream()\'s cancellation error', () async {
var completer = Completer();
var completer = Completer<void>();
var transformed = NullStreamSink(done: completer.future).rejectErrors();

expect(
Expand Down
2 changes: 1 addition & 1 deletion test/result/result_future_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ void main() {
late Completer completer;
late ResultFuture future;
setUp(() {
completer = Completer();
completer = Completer<void>();
future = ResultFuture(completer.future);
});

Expand Down
9 changes: 5 additions & 4 deletions test/sink_base_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ void main() {
});

test('all invocations of close() return the same future', () async {
var completer = Completer();
var completer = Completer<void>();
var sink = _StreamSink(onClose: expectAsync0(() => completer.future));

var close1Completed = false;
Expand All @@ -106,7 +106,7 @@ void main() {

test('done returns a future that completes once close() completes',
() async {
var completer = Completer();
var completer = Completer<void>();
var sink = _StreamSink(onClose: expectAsync0(() => completer.future));

var doneCompleted = false;
Expand Down Expand Up @@ -297,7 +297,7 @@ void main() {

group('flush()', () {
test('returns a future that completes when onFlush() is done', () async {
var completer = Completer();
var completer = Completer<void>();
var sink = _IOSink(onFlush: expectAsync0(() => completer.future));

var flushDone = false;
Expand All @@ -324,7 +324,8 @@ void main() {
});

test('locks the sink as though a stream was being added', () {
var sink = _IOSink(onFlush: expectAsync0(() => Completer().future));
var sink =
_IOSink(onFlush: expectAsync0(() => Completer<void>().future));
sink.flush();
expect(() => sink.add([0]), throwsStateError);
expect(() => sink.addError('oh no'), throwsStateError);
Expand Down
Loading

0 comments on commit f5a08a3

Please sign in to comment.