Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(400)

Side by Side Diff: pkg/barback/test/too_many_open_files_test.dart

Issue 27242002: Use file pool to handle running out of file descriptors. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Revise to work with readAsString() too. (Thanks Kevin!) Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2013, 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 library barback.test.too_many_open_files_test;
6
7 import 'dart:async';
8 import 'dart:io';
9
10 import 'package:barback/barback.dart';
11 import 'package:path/path.dart' as pathos;
12 import 'package:unittest/unittest.dart';
13
14 import 'utils.dart';
15
16 main() {
17 initConfig();
18
19 runOnManyFiles(Future assetHandler(Asset asset)) {
nweiz 2013/10/16 00:16:01 It feels like this should be defined at the top le
Bob Nystrom 2013/10/16 00:51:46 Done.
20 // Make a text file in a temp directory.
21 var tempDir = Directory.systemTemp.createTempSync("barback").path;
22 var filePath = pathos.join(tempDir, "out.txt");
23
24 // Make sure it's large enough to not be read in a single chunk.
25 var contents = new StringBuffer();
26 for (var i = 0; i < 1024; i++) {
27 contents.write(
28 "this is a sixty four character long string that describes itself");
29 }
30
31 new File(filePath).writeAsStringSync(contents.toString());
32
33 var id = new AssetId("myapp", "out.txt");
34
35 // Create a large number of assets, larger than the file descriptor limit
36 // of most machines and start reading from all of them.
37 var futures = [];
38 for (var i = 0; i < 1000; i++) {
39 var asset = new Asset.fromPath(id, filePath);
40 futures.add(assetHandler(asset));
41 }
42
43 expect(Future.wait(futures).whenComplete(() {
44 new Directory(tempDir).delete(recursive: true);
45 }), completes);
46 }
47
48 test("handles many simultaneous asset read() calls", () {
49 runOnManyFiles((asset) {
50 var completer = new Completer();
51 var stream = asset.read();
52
53 stream.listen((data) {
54 // Do nothing.
55 }, onError: (error) {
56 completer.completeError(error);
57 }, onDone: () {
58 if (!completer.isCompleted) completer.complete();
59 });
nweiz 2013/10/16 00:16:01 It would be cleaner just to return asset.read().to
Bob Nystrom 2013/10/16 00:51:46 Indeed! Done.
60
61 return completer.future;
62 });
63 });
64
65 test("handles many simultaneous asset readToString() calls", () {
66 runOnManyFiles((asset) => asset.readAsString());
67 });
68 }
OLDNEW
« pkg/barback/lib/src/file_pool.dart ('K') | « pkg/barback/lib/src/file_pool.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698