blob: 37c77777671d3f6ce8061203fdc289d290d24917 [file] [log] [blame]
// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
// 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
/// @assertion void addError(
/// error, [
/// StackTrace stackTrace
/// ])
/// Passes the error to the target consumer as an error event.
///
/// This function must not be called when a stream is currently being added using
/// addStream.
///
/// This operation is non-blocking. See flush or done for how to get any errors
/// generated by this call.
/// @description Checks that this method passes the error to the target consumer
/// as an error event
/// @author sgrekhov@unipro.ru
import "dart:io";
import "../../../Utils/expect.dart";
var localhost = InternetAddress.loopbackIPv4.address;
test(String method) async {
asyncStart();
HttpServer server = await HttpServer.bind(localhost, 0);
server.listen((HttpRequest request) {
Expect.fail("Error expected");
});
server.handleError((e) {
Expect.fail("Error on the client end expected");
});
HttpClient client = new HttpClient();
client.open(method, localhost, server.port, "")
.then((HttpClientRequest request) {
request.addError("Error");
return request.close();
}).then((HttpClientResponse response) {
Expect.fail("Error expected");
}, onError: (e) {
Expect.equals("Error", e);
server.close();
asyncEnd();
});
}
main() {
test("get");
test("head");
test("delete");
test("put");
test("post");
test("patch");
}