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

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

Issue 1331033003: Add tracking of open processes to the new io resource tracking. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: address comments Created 5 years, 3 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
« no previous file with comments | « runtime/bin/process_patch.dart ('k') | sdk/lib/io/io_resource_info.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 (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
3 // BSD-style license that can be found in the LICENSE file.
4
5 import 'dart:async';
6 import 'dart:convert';
7 import 'dart:developer';
8 import 'dart:io' as io;
9 import 'package:observatory/service_io.dart';
10 import 'package:unittest/unittest.dart';
11 import 'test_helper.dart';
12
13 Future setupProcesses() async {
14 var dir = await io.Directory.systemTemp.createTemp('file_service');
15
16 var args = ['--pause_isolates_on_start', io.Platform.script.toFilePath()];
17 var process1;
18 var process2;
19 var process3;
20
21 void closeDown() {
22 if (process1 != null) {
23 process1.kill();
24 }
25 if (process2 != null) {
26 process2.kill();
27 }
28 if (process3 != null) {
29 process3.kill();
30 }
31 dir.deleteSync(recursive: true);
32 }
33
34 Future<ServiceExtensionResponse> cleanup(ignored_a, ignored_b) {
35 closeDown();
36 var result = JSON.encode({'type' : 'foobar'});
37 return new Future.value(new ServiceExtensionResponse.result(result));
38 }
39
40 Future<ServiceExtensionResponse> setup(ignored_a, ignored_b) async {
41 try {
42 process1 = await io.Process.start(io.Platform.executable, args);
43 process2 = await io.Process.start(io.Platform.executable,
44 args..add('foobar'));
45 var codeFilePath = dir.path + io.Platform.pathSeparator + "other_file";
46 var codeFile = new io.File(codeFilePath);
47 await codeFile.writeAsString(
48 '''
49 import "dart:io";
50
51 void main() async {
52 await stdin.drain();
53 }
54 ''');
55 process3 = await io.Process.start(io.Platform.executable,
56 [codeFilePath]);
57 } catch (e) {
58 closeDown();
59 throw e;
60 }
61
62 var result =
63 JSON.encode({'type': 'foobar',
64 'pids' : [process1.pid, process2.pid, process3.pid]});
65 return new Future.value(new ServiceExtensionResponse.result(result));
66 }
67
68 Future<ServiceExtensionResponse> closeStdin(ignored_a, ignored_b) async {
69 process3.stdin.close();
70 var result = JSON.encode({'type' : 'foobar'});
71 var returnValue =
72 new Future.value(new ServiceExtensionResponse.result(result));
73 return process3.exitCode.then((int exit) => returnValue);
74 }
75
76 registerExtension('__cleanup', cleanup);
77 registerExtension('__setup', setup);
78 registerExtension('__closeStdin', closeStdin);
79
80 }
81
82 var processTests = [
83 // Initial.
84 (Isolate isolate) async {
85 var setup = await isolate.invokeRpcNoUpgrade('__setup', {});
86 try {
87 var all = await isolate.invokeRpcNoUpgrade('__getProcesses', {});
88 expect(all['type'], equals('_startedprocesses'));
89
90 expect(all['data'].length, equals(3));
91
92 var first = await isolate.invokeRpcNoUpgrade(
93 '__getProcessById', { 'id' : all['data'][0]['id'] });
94 expect(first['name'], io.Platform.executable);
95 expect(first['pid'], equals(setup['pids'][0]));
96 expect(first['arguments'].contains('foobar'), isFalse);
97
98 var second = await isolate.invokeRpcNoUpgrade(
99 '__getProcessById', { 'id' : all['data'][1]['id'] });
100 expect(second['name'], io.Platform.executable);
101 expect(second['pid'], equals(setup['pids'][1]));
102 expect(second['arguments'].contains('foobar'), isTrue);
103 expect(second['pid'] != first['pid'], isTrue);
104
105 var third = await isolate.invokeRpcNoUpgrade(
106 '__getProcessById', { 'id' : all['data'][2]['id'] });
107 expect(third['name'], io.Platform.executable);
108 expect(third['pid'], equals(setup['pids'][2]));
109 expect(third['pid'] != first['pid'], isTrue);
110 expect(third['pid'] != second['pid'], isTrue);
111
112 await isolate.invokeRpcNoUpgrade('__closeStdin', {});
113 all = await isolate.invokeRpcNoUpgrade('__getProcesses', {});
114 expect(all['type'], equals('_startedprocesses'));
115 expect(all['data'].length, equals(2));
116 } finally {
117 await isolate.invokeRpcNoUpgrade('__cleanup', {});
118 }
119 },
120 ];
121
122 main(args) async => runIsolateTests(args, processTests,
123 testeeBefore:setupProcesses);
OLDNEW
« no previous file with comments | « runtime/bin/process_patch.dart ('k') | sdk/lib/io/io_resource_info.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698