Skip to content

Commit 62a0da0

Browse files
author
Anna Gringauze
committed
Add tests
1 parent 5d5d209 commit 62a0da0

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed

dwds/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
- Return empty library from `ChromeProxyService.getObject` for
44
libraries present in medatata but not lodaded at runtime.
55
- Log failures to load kernel during expression evaluation.
6+
- Limit simultaneous connections to asset server to prevent broken sockets.
67

78
## 11.1.1
89

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
// @dart = 2.9
6+
7+
import 'dart:io';
8+
9+
import 'package:http/http.dart' as http;
10+
import 'package:http/io_client.dart';
11+
import 'package:shelf/shelf.dart';
12+
import 'package:shelf_proxy/shelf_proxy.dart';
13+
import 'package:test/test.dart';
14+
15+
import '../fixtures/context.dart';
16+
import '../fixtures/utilities.dart';
17+
18+
void main() {
19+
group('Asset handler', () {
20+
final context = TestContext();
21+
Handler assetHandler;
22+
http.Client client;
23+
24+
setUpAll(() async {
25+
await context.setUp(enableExpressionEvaluation: true);
26+
27+
client = IOClient(HttpClient()
28+
..maxConnectionsPerHost = 200
29+
..idleTimeout = const Duration(seconds: 30)
30+
..connectionTimeout = const Duration(seconds: 30));
31+
32+
var assetServerPort = daemonPort(context.workingDirectory);
33+
var pathToServe = context.pathToServe;
34+
35+
assetHandler = proxyHandler(
36+
'http://localhost:$assetServerPort/$pathToServe/',
37+
client: client);
38+
});
39+
40+
tearDownAll(() {
41+
client.close();
42+
});
43+
44+
Future<void> readAsString(String path) async {
45+
var request = Request('GET', Uri.parse('http://foo:0000/$path'));
46+
var response = await assetHandler(request);
47+
var result = await response.readAsString();
48+
expect(result, isNotNull, reason: 'Failed to read $path');
49+
}
50+
51+
Future<void> readAsBytes(String path) async {
52+
var request = Request('GET', Uri.parse('http://foo:0000/$path'));
53+
var response = await assetHandler(request);
54+
var result = response.read().toList();
55+
expect(result, isNotNull, reason: 'Failed to read $path');
56+
}
57+
58+
test('can read dill files', () async {
59+
var path = 'hello_world/main.unsound.ddc.full.dill';
60+
await readAsBytes(path);
61+
});
62+
63+
test('can read large number of resources simultaneously', () async {
64+
final n = 1000;
65+
var futures = [
66+
for (var i = 0; i < n; i++)
67+
readAsString('hello_world/main.unsound.ddc.js.map'),
68+
for (var i = 0; i < n; i++)
69+
readAsString('hello_world/main.unsound.ddc.js'),
70+
for (var i = 0; i < n; i++)
71+
readAsBytes('hello_world/main.unsound.ddc.full.dill'),
72+
];
73+
74+
await expectLater(Future.wait(futures), completes);
75+
});
76+
});
77+
}

0 commit comments

Comments
 (0)