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

Side by Side Diff: mojo/dart/http_load_test/bin/tester.dart

Issue 1545483003: Dart: Reorganize files (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Fix build file Created 5 years 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
« no previous file with comments | « mojo/dart/http_load_test/BUILD.gn ('k') | mojo/dart/http_load_test/lib/main.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 library http_load_test;
6
7 import 'dart:async';
8 import 'dart:convert';
9 import 'dart:io';
10
11 class Launcher {
12 /// Launch [executable] with [arguments]. Returns a [String] containing
13 /// the standard output from the launched executable.
14 static Future<String> launch(String executable,
15 List<String> arguments) async {
16 var process = await Process.start(executable, arguments);
17
18 // Completer completes once the child process exits.
19 var completer = new Completer();
20 String output = '';
21 process.stdout.transform(UTF8.decoder)
22 .transform(new LineSplitter()).listen((line) {
23 output = '$output\n$line';
24 print(line);
25 });
26 process.stderr.transform(UTF8.decoder)
27 .transform(new LineSplitter()).listen((line) {
28 output = '$output\n$line';
29 print(line);
30 });
31 process.exitCode.then((ec) {
32 output = '$output\nEXIT_CODE=$ec\n';
33 completer.complete(output);
34 });
35 return completer.future;
36 }
37 }
38
39 main(List<String> args) async {
40 var mojo_shell_executable = args[0];
41 var directory = args[1];
42
43 HttpServer server = await HttpServer.bind('127.0.0.1', 0);
44
45 server.listen((HttpRequest request) async {
46 final String path = request.uri.toFilePath();
47 final File file = new File('${directory}/${path}');
48 if (await file.exists()) {
49 try {
50 await file.openRead().pipe(request.response);
51 } catch (e) {
52 print(e);
53 }
54 } else {
55 request.response.statusCode = HttpStatus.NOT_FOUND;
56 request.response.close();
57 }
58 });
59
60 var launchUrl = 'http://127.0.0.1:${server.port}/lib/main.dart';
61 var output = await Launcher.launch(mojo_shell_executable, [launchUrl]);
62
63 server.close();
64
65 if (output.contains("ERROR")) {
66 throw "test failed.";
67 }
68 if (!output.contains("\nEXIT_CODE=0\n")) {
69 throw "Test failed.";
70 }
71 if (!output.contains("\nPASS")) {
72 throw "Test failed.";
73 }
74 }
OLDNEW
« no previous file with comments | « mojo/dart/http_load_test/BUILD.gn ('k') | mojo/dart/http_load_test/lib/main.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698