[io/socket] Test of being able to read big chunks from a socket

Follow-up to https://dart-review.googlesource.com/c/sdk/+/369243 where
without that CL (i.e. after
https://dart-review.googlesource.com/c/sdk/+/369141 but before the fix)
the test will hang. With the CL the test finishes as it should.

Change-Id: I7b37be1c515a3666a8040d1790b55ff99b68a1be
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/369463
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
This commit is contained in:
Jens Johansen 2024-06-03 12:56:19 +00:00 committed by Commit Queue
parent 552240b0a6
commit 1c3d4dbe42

View file

@ -0,0 +1,43 @@
// Copyright (c) 2024, 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.
import "dart:io";
import "dart:typed_data";
import "package:async_helper/async_helper.dart";
import "package:expect/expect.dart";
Future<void> main() async {
asyncStart();
Uint8List data = new Uint8List(100 * 1024 * 1024);
final HttpServer server = await HttpServer.bind('127.0.0.1', 0);
print("Listening on 127.0.0.1:${server.port}");
server.listen((HttpRequest request) {
print("Handling request...");
final HttpResponse response = request.response;
response.add(data);
response.close();
});
HttpClient client = new HttpClient();
HttpClientRequest clientResult =
await client.get('127.0.0.1', server.port, 'foo');
HttpClientResponse response = await clientResult.close();
print("Client result closed");
int totalLength = 0;
await for (List<int> data in response) {
totalLength += data.length;
print("Got chunk of size ${data.length}. "
"Total received is now $totalLength.");
}
print("Client done.");
Expect.equals(data.length, totalLength);
client.close();
await server.close();
asyncEnd();
}