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

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

Issue 2767533002: Revert "Fix observatory tests broken by running dartfmt." (Closed)
Patch Set: 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 = 43 process2 = await io.Process.start(io.Platform.executable,
44 await io.Process.start(io.Platform.executable, args..add('foobar')); 44 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 '''
48 import "dart:io"; 49 import "dart:io";
49 50
50 void main() async { 51 void main() async {
51 await stdin.drain(); 52 await stdin.drain();
52 } 53 }
53 '''); 54 ''');
54 process3 = await io.Process.start(io.Platform.executable, [codeFilePath]); 55 process3 = await io.Process.start(io.Platform.executable,
56 [codeFilePath]);
55 } catch (e) { 57 } catch (e) {
56 closeDown(); 58 closeDown();
57 throw e; 59 throw e;
58 } 60 }
59 61
60 var result = JSON.encode({ 62 var result =
61 'type': 'foobar', 63 JSON.encode({'type': 'foobar',
62 'pids': [process1.pid, process2.pid, process3.pid] 64 'pids' : [process1.pid, process2.pid, process3.pid]});
63 });
64 return new Future.value(new ServiceExtensionResponse.result(result)); 65 return new Future.value(new ServiceExtensionResponse.result(result));
65 } 66 }
66 67
67 Future<ServiceExtensionResponse> closeStdin(ignored_a, ignored_b) async { 68 Future<ServiceExtensionResponse> closeStdin(ignored_a, ignored_b) async {
68 process3.stdin.close(); 69 process3.stdin.close();
69 var result = JSON.encode({'type': 'foobar'}); 70 var result = JSON.encode({'type' : 'foobar'});
70 var returnValue = 71 var returnValue =
71 new Future.value(new ServiceExtensionResponse.result(result)); 72 new Future.value(new ServiceExtensionResponse.result(result));
72 return process3.exitCode.then((int exit) => returnValue); 73 return process3.exitCode.then((int exit) => returnValue);
73 } 74 }
74 75
75 registerExtension('ext.dart.io.cleanup', cleanup); 76 registerExtension('ext.dart.io.cleanup', cleanup);
76 registerExtension('ext.dart.io.setup', setup); 77 registerExtension('ext.dart.io.setup', setup);
77 registerExtension('ext.dart.io.closeStdin', closeStdin); 78 registerExtension('ext.dart.io.closeStdin', closeStdin);
79
78 } 80 }
79 81
80 var processTests = [ 82 var processTests = [
81 // Initial. 83 // Initial.
82 (Isolate isolate) async { 84 (Isolate isolate) async {
83 var setup = await isolate.invokeRpcNoUpgrade('ext.dart.io.setup', {}); 85 var setup = await isolate.invokeRpcNoUpgrade('ext.dart.io.setup', {});
84 try { 86 try {
85 var all = 87 var all =
86 await isolate.invokeRpcNoUpgrade('ext.dart.io.getProcesses', {}); 88 await isolate.invokeRpcNoUpgrade('ext.dart.io.getProcesses', {});
87 expect(all['type'], equals('_startedprocesses')); 89 expect(all['type'], equals('_startedprocesses'));
88 90
89 expect(all['data'].length, equals(3)); 91 expect(all['data'].length, equals(3));
90 92
91 var first = await isolate.invokeRpcNoUpgrade( 93 var first = await isolate.invokeRpcNoUpgrade(
92 'ext.dart.io.getProcessById', {'id': all['data'][0]['id']}); 94 'ext.dart.io.getProcessById', { 'id' : all['data'][0]['id'] });
93 expect(first['name'], io.Platform.executable); 95 expect(first['name'], io.Platform.executable);
94 expect(first['pid'], equals(setup['pids'][0])); 96 expect(first['pid'], equals(setup['pids'][0]));
95 expect(first['arguments'].contains('foobar'), isFalse); 97 expect(first['arguments'].contains('foobar'), isFalse);
96 expect(first['startedAt'], greaterThan(0)); 98 expect(first['startedAt'], greaterThan(0));
97 99
98 var second = await isolate.invokeRpcNoUpgrade( 100 var second = await isolate.invokeRpcNoUpgrade(
99 'ext.dart.io.getProcessById', {'id': all['data'][1]['id']}); 101 'ext.dart.io.getProcessById', { 'id' : all['data'][1]['id'] });
100 expect(second['name'], io.Platform.executable); 102 expect(second['name'], io.Platform.executable);
101 expect(second['pid'], equals(setup['pids'][1])); 103 expect(second['pid'], equals(setup['pids'][1]));
102 expect(second['arguments'].contains('foobar'), isTrue); 104 expect(second['arguments'].contains('foobar'), isTrue);
103 expect(second['pid'] != first['pid'], isTrue); 105 expect(second['pid'] != first['pid'], isTrue);
104 expect(second['startedAt'], greaterThan(0)); 106 expect(second['startedAt'], greaterThan(0));
105 expect(second['startedAt'], greaterThanOrEqualTo(first['startedAt'])); 107 expect(second['startedAt'], greaterThanOrEqualTo(first['startedAt']));
106 108
107 var third = await isolate.invokeRpcNoUpgrade( 109 var third = await isolate.invokeRpcNoUpgrade(
108 'ext.dart.io.getProcessById', {'id': all['data'][2]['id']}); 110 'ext.dart.io.getProcessById', { 'id' : all['data'][2]['id'] });
109 expect(third['name'], io.Platform.executable); 111 expect(third['name'], io.Platform.executable);
110 expect(third['pid'], equals(setup['pids'][2])); 112 expect(third['pid'], equals(setup['pids'][2]));
111 expect(third['pid'] != first['pid'], isTrue); 113 expect(third['pid'] != first['pid'], isTrue);
112 expect(third['pid'] != second['pid'], isTrue); 114 expect(third['pid'] != second['pid'], isTrue);
113 expect(third['startedAt'], greaterThanOrEqualTo(second['startedAt'])); 115 expect(third['startedAt'], greaterThanOrEqualTo(second['startedAt']));
114 116
115 await isolate.invokeRpcNoUpgrade('ext.dart.io.closeStdin', {}); 117 await isolate.invokeRpcNoUpgrade('ext.dart.io.closeStdin', {});
116 all = await isolate.invokeRpcNoUpgrade('ext.dart.io.getProcesses', {}); 118 all = await isolate.invokeRpcNoUpgrade('ext.dart.io.getProcesses', {});
117 expect(all['type'], equals('_startedprocesses')); 119 expect(all['type'], equals('_startedprocesses'));
118 expect(all['data'].length, equals(2)); 120 expect(all['data'].length, equals(2));
119 } finally { 121 } finally {
120 await isolate.invokeRpcNoUpgrade('ext.dart.io.cleanup', {}); 122 await isolate.invokeRpcNoUpgrade('ext.dart.io.cleanup', {});
121 } 123 }
122 }, 124 },
123 ]; 125 ];
124 126
125 main(args) async => 127 main(args) async => runIsolateTests(args, processTests,
126 runIsolateTests(args, processTests, testeeBefore: setupProcesses); 128 testeeBefore:setupProcesses);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698