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

Side by Side Diff: sdk/lib/_internal/pub/test/serve/utils.dart

Issue 21147002: Install before starting the server if the lockfile is out of date. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Rebase. Created 7 years, 4 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
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS d.file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS d.file
2 // for details. All rights reserved. Use of this source code is governed by a 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library pub_tests; 5 library pub_tests;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:io'; 8 import 'dart:io';
9 9
10 import 'package:http/http.dart' as http; 10 import 'package:http/http.dart' as http;
11 import 'package:scheduled_test/scheduled_process.dart'; 11 import 'package:scheduled_test/scheduled_process.dart';
12 import 'package:scheduled_test/scheduled_test.dart'; 12 import 'package:scheduled_test/scheduled_test.dart';
13 13
14 import '../descriptor.dart' as d; 14 import '../descriptor.dart' as d;
15 import '../test_pub.dart'; 15 import '../test_pub.dart';
16 16
17 /// The pub process running "pub serve". 17 /// The pub process running "pub serve".
18 ScheduledProcess _pubServer; 18 ScheduledProcess _pubServer;
19 19
20 /// The ephemeral port assigned to the running server. 20 /// The ephemeral port assigned to the running server.
21 int _port; 21 int _port;
22 22
23 /// Schedules starting the "pub serve" process. 23 /// Schedules starting the "pub serve" process.
24 void startPubServe() { 24 ///
25 /// If [shouldInstallFirst] is `true`, then validates that pub install is run
nweiz 2013/07/30 19:34:36 Nit: remove "then"
Bob Nystrom 2013/07/30 21:35:32 Done.
26 /// first.
27 void startPubServe({bool shouldInstallFirst: false}) {
25 // Use port 0 to get an ephemeral port. 28 // Use port 0 to get an ephemeral port.
26 _pubServer = startPub(args: ["serve", "--port=0"]); 29 _pubServer = startPub(args: ["serve", "--port=0"]);
27 30
28 expect(_pubServer.nextLine().then((line) { 31 if (shouldInstallFirst) {
29 var match = new RegExp(r"localhost:(\d+)").firstMatch(line); 32 schedule(() {
30 assert(match != null); 33 return _pubServer.nextLine().then((line1) {
31 _port = int.parse(match[1]); 34 expect(line1, startsWith("Dependencies have changed"));
32 }), completes); 35 return _pubServer.nextLine();
36 }).then((line2) {
37 expect(line2, startsWith("Resolving dependencies..."));
38 return _pubServer.nextLine();
39 }).then((line3) {
40 expect(line3, equals("Dependencies installed!"));
41 return _pubServer.nextLine();
42 }).then((line4) {
43 _parsePort(line4);
44 });
45 });
nweiz 2013/07/30 19:34:36 Since [nextLine] is scheduled internally, you can
Bob Nystrom 2013/07/30 21:35:32 Done.
46
47 return;
48 }
49
50 expect(_pubServer.nextLine().then(_parsePort), completes);
51 }
52
53 /// Parses the port number from the "Serving blah on localhost:1234" line
54 /// printed by pub serve.
55 void _parsePort(String line) {
56 var match = new RegExp(r"localhost:(\d+)").firstMatch(line);
57 assert(match != null);
58 _port = int.parse(match[1]);
33 } 59 }
34 60
35 void endPubServe() { 61 void endPubServe() {
36 _pubServer.kill(); 62 _pubServer.kill();
37 } 63 }
38 64
39 /// Schedules an HTTP request to the running pub server with [urlPath] and 65 /// Schedules an HTTP request to the running pub server with [urlPath] and
40 /// verifies that it responds with [expected]. 66 /// verifies that it responds with [expected].
41 void requestShouldSucceed(String urlPath, String expected) { 67 void requestShouldSucceed(String urlPath, String expected) {
42 schedule(() { 68 schedule(() {
43 return http.get("http://localhost:$_port/$urlPath").then((response) { 69 return http.get("http://localhost:$_port/$urlPath").then((response) {
44 expect(response.body, equals(expected)); 70 expect(response.body, equals(expected));
45 }); 71 });
46 }, "request $urlPath"); 72 }, "request $urlPath");
47 } 73 }
48 74
49 /// Schedules an HTTP request to the running pub server with [urlPath] and 75 /// Schedules an HTTP request to the running pub server with [urlPath] and
50 /// verifies that it responds with a 404. 76 /// verifies that it responds with a 404.
51 void requestShould404(String urlPath) { 77 void requestShould404(String urlPath) {
52 schedule(() { 78 schedule(() {
53 return http.get("http://localhost:$_port/$urlPath").then((response) { 79 return http.get("http://localhost:$_port/$urlPath").then((response) {
54 expect(response.statusCode, equals(404)); 80 expect(response.statusCode, equals(404));
55 }); 81 });
56 }, "request $urlPath"); 82 }, "request $urlPath");
57 } 83 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698