Skip to content
Open
Changes from 5 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
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +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.

import 'dart:async';
import 'dart:io';

import 'package:cupertino_http/cupertino_http.dart';
Expand Down Expand Up @@ -207,18 +208,23 @@ void testURLSessionTaskCommon(
group('task states', () {
late HttpServer server;
late URLSessionTask task;
late Completer<void> requestCompleter;

setUp(() async {
requestCompleter = Completer<void>();
server = (await HttpServer.bind('localhost', 0))
..listen((request) async {
await request.drain<void>();
request.response.headers.set('Content-Type', 'text/plain');
request.response.write('Hello World');
await requestCompleter.future;
await request.response.close();
});
final session = URLSession.sharedSession();
task = f(session, Uri.parse('http://localhost:${server.port}'));
});
tearDown(() {
if (!requestCompleter.isCompleted) requestCompleter.complete();
task.cancel();
server.close();
});
Expand Down Expand Up @@ -254,6 +260,7 @@ void testURLSessionTaskCommon(

test('completed', () async {
task.resume();
requestCompleter.complete();
while (task.state !=
NSURLSessionTaskState.NSURLSessionTaskStateCompleted) {
// Let the event loop run.
Expand Down
Loading