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

Side by Side Diff: runtime/observatory/tests/service/process_service_test.dart

Issue 2751423005: Run dartfmt on all files under runtime. (Closed)
Patch Set: Run dartfmt on all files under runtime. Created 3 years, 9 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
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS 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 import 'dart:async'; 5 import 'dart:async';
6 import 'dart:convert'; 6 import 'dart:convert';
7 import 'dart:developer'; 7 import 'dart:developer';
8 import 'dart:io' as io; 8 import 'dart:io' as io;
9 import 'package:observatory/service_io.dart'; 9 import 'package:observatory/service_io.dart';
10 import 'package:unittest/unittest.dart'; 10 import 'package:unittest/unittest.dart';
(...skipping 15 matching lines...) Expand all
26 process2.kill(); 26 process2.kill();
27 } 27 }
28 if (process3 != null) { 28 if (process3 != null) {
29 process3.kill(); 29 process3.kill();
30 } 30 }
31 dir.deleteSync(recursive: true); 31 dir.deleteSync(recursive: true);
32 } 32 }
33 33
34 Future<ServiceExtensionResponse> cleanup(ignored_a, ignored_b) { 34 Future<ServiceExtensionResponse> cleanup(ignored_a, ignored_b) {
35 closeDown(); 35 closeDown();
36 var result = JSON.encode({'type' : 'foobar'}); 36 var result = JSON.encode({'type': 'foobar'});
37 return new Future.value(new ServiceExtensionResponse.result(result)); 37 return new Future.value(new ServiceExtensionResponse.result(result));
38 } 38 }
39 39
40 Future<ServiceExtensionResponse> setup(ignored_a, ignored_b) async { 40 Future<ServiceExtensionResponse> setup(ignored_a, ignored_b) async {
41 try { 41 try {
42 process1 = await io.Process.start(io.Platform.executable, args); 42 process1 = await io.Process.start(io.Platform.executable, args);
43 process2 = await io.Process.start(io.Platform.executable, 43 process2 =
44 args..add('foobar')); 44 await io.Process.start(io.Platform.executable, args..add('foobar'));
45 var codeFilePath = dir.path + io.Platform.pathSeparator + "other_file"; 45 var codeFilePath = dir.path + io.Platform.pathSeparator + "other_file";
46 var codeFile = new io.File(codeFilePath); 46 var codeFile = new io.File(codeFilePath);
47 await codeFile.writeAsString( 47 await codeFile.writeAsString('''
48 '''
49 import "dart:io"; 48 import "dart:io";
50 49
51 void main() async { 50 void main() async {
52 await stdin.drain(); 51 await stdin.drain();
53 } 52 }
54 '''); 53 ''');
55 process3 = await io.Process.start(io.Platform.executable, 54 process3 = await io.Process.start(io.Platform.executable, [codeFilePath]);
56 [codeFilePath]);
57 } catch (e) { 55 } catch (e) {
58 closeDown(); 56 closeDown();
59 throw e; 57 throw e;
60 } 58 }
61 59
62 var result = 60 var result = JSON.encode({
63 JSON.encode({'type': 'foobar', 61 'type': 'foobar',
64 'pids' : [process1.pid, process2.pid, process3.pid]}); 62 'pids': [process1.pid, process2.pid, process3.pid]
63 });
65 return new Future.value(new ServiceExtensionResponse.result(result)); 64 return new Future.value(new ServiceExtensionResponse.result(result));
66 } 65 }
67 66
68 Future<ServiceExtensionResponse> closeStdin(ignored_a, ignored_b) async { 67 Future<ServiceExtensionResponse> closeStdin(ignored_a, ignored_b) async {
69 process3.stdin.close(); 68 process3.stdin.close();
70 var result = JSON.encode({'type' : 'foobar'}); 69 var result = JSON.encode({'type': 'foobar'});
71 var returnValue = 70 var returnValue =
72 new Future.value(new ServiceExtensionResponse.result(result)); 71 new Future.value(new ServiceExtensionResponse.result(result));
73 return process3.exitCode.then((int exit) => returnValue); 72 return process3.exitCode.then((int exit) => returnValue);
74 } 73 }
75 74
76 registerExtension('ext.dart.io.cleanup', cleanup); 75 registerExtension('ext.dart.io.cleanup', cleanup);
77 registerExtension('ext.dart.io.setup', setup); 76 registerExtension('ext.dart.io.setup', setup);
78 registerExtension('ext.dart.io.closeStdin', closeStdin); 77 registerExtension('ext.dart.io.closeStdin', closeStdin);
79
80 } 78 }
81 79
82 var processTests = [ 80 var processTests = [
83 // Initial. 81 // Initial.
84 (Isolate isolate) async { 82 (Isolate isolate) async {
85 var setup = await isolate.invokeRpcNoUpgrade('ext.dart.io.setup', {}); 83 var setup = await isolate.invokeRpcNoUpgrade('ext.dart.io.setup', {});
86 try { 84 try {
87 var all = 85 var all =
88 await isolate.invokeRpcNoUpgrade('ext.dart.io.getProcesses', {}); 86 await isolate.invokeRpcNoUpgrade('ext.dart.io.getProcesses', {});
89 expect(all['type'], equals('_startedprocesses')); 87 expect(all['type'], equals('_startedprocesses'));
90 88
91 expect(all['data'].length, equals(3)); 89 expect(all['data'].length, equals(3));
92 90
93 var first = await isolate.invokeRpcNoUpgrade( 91 var first = await isolate.invokeRpcNoUpgrade(
94 'ext.dart.io.getProcessById', { 'id' : all['data'][0]['id'] }); 92 'ext.dart.io.getProcessById', {'id': all['data'][0]['id']});
95 expect(first['name'], io.Platform.executable); 93 expect(first['name'], io.Platform.executable);
96 expect(first['pid'], equals(setup['pids'][0])); 94 expect(first['pid'], equals(setup['pids'][0]));
97 expect(first['arguments'].contains('foobar'), isFalse); 95 expect(first['arguments'].contains('foobar'), isFalse);
98 expect(first['startedAt'], greaterThan(0)); 96 expect(first['startedAt'], greaterThan(0));
99 97
100 var second = await isolate.invokeRpcNoUpgrade( 98 var second = await isolate.invokeRpcNoUpgrade(
101 'ext.dart.io.getProcessById', { 'id' : all['data'][1]['id'] }); 99 'ext.dart.io.getProcessById', {'id': all['data'][1]['id']});
102 expect(second['name'], io.Platform.executable); 100 expect(second['name'], io.Platform.executable);
103 expect(second['pid'], equals(setup['pids'][1])); 101 expect(second['pid'], equals(setup['pids'][1]));
104 expect(second['arguments'].contains('foobar'), isTrue); 102 expect(second['arguments'].contains('foobar'), isTrue);
105 expect(second['pid'] != first['pid'], isTrue); 103 expect(second['pid'] != first['pid'], isTrue);
106 expect(second['startedAt'], greaterThan(0)); 104 expect(second['startedAt'], greaterThan(0));
107 expect(second['startedAt'], greaterThanOrEqualTo(first['startedAt'])); 105 expect(second['startedAt'], greaterThanOrEqualTo(first['startedAt']));
108 106
109 var third = await isolate.invokeRpcNoUpgrade( 107 var third = await isolate.invokeRpcNoUpgrade(
110 'ext.dart.io.getProcessById', { 'id' : all['data'][2]['id'] }); 108 'ext.dart.io.getProcessById', {'id': all['data'][2]['id']});
111 expect(third['name'], io.Platform.executable); 109 expect(third['name'], io.Platform.executable);
112 expect(third['pid'], equals(setup['pids'][2])); 110 expect(third['pid'], equals(setup['pids'][2]));
113 expect(third['pid'] != first['pid'], isTrue); 111 expect(third['pid'] != first['pid'], isTrue);
114 expect(third['pid'] != second['pid'], isTrue); 112 expect(third['pid'] != second['pid'], isTrue);
115 expect(third['startedAt'], greaterThanOrEqualTo(second['startedAt'])); 113 expect(third['startedAt'], greaterThanOrEqualTo(second['startedAt']));
116 114
117 await isolate.invokeRpcNoUpgrade('ext.dart.io.closeStdin', {}); 115 await isolate.invokeRpcNoUpgrade('ext.dart.io.closeStdin', {});
118 all = await isolate.invokeRpcNoUpgrade('ext.dart.io.getProcesses', {}); 116 all = await isolate.invokeRpcNoUpgrade('ext.dart.io.getProcesses', {});
119 expect(all['type'], equals('_startedprocesses')); 117 expect(all['type'], equals('_startedprocesses'));
120 expect(all['data'].length, equals(2)); 118 expect(all['data'].length, equals(2));
121 } finally { 119 } finally {
122 await isolate.invokeRpcNoUpgrade('ext.dart.io.cleanup', {}); 120 await isolate.invokeRpcNoUpgrade('ext.dart.io.cleanup', {});
123 } 121 }
124 }, 122 },
125 ]; 123 ];
126 124
127 main(args) async => runIsolateTests(args, processTests, 125 main(args) async =>
128 testeeBefore:setupProcesses); 126 runIsolateTests(args, processTests, testeeBefore: setupProcesses);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698