| OLD | NEW |
| 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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 } | 66 } |
| 67 | 67 |
| 68 Future<ServiceExtensionResponse> closeStdin(ignored_a, ignored_b) async { | 68 Future<ServiceExtensionResponse> closeStdin(ignored_a, ignored_b) async { |
| 69 process3.stdin.close(); | 69 process3.stdin.close(); |
| 70 var result = JSON.encode({'type' : 'foobar'}); | 70 var result = JSON.encode({'type' : 'foobar'}); |
| 71 var returnValue = | 71 var returnValue = |
| 72 new Future.value(new ServiceExtensionResponse.result(result)); | 72 new Future.value(new ServiceExtensionResponse.result(result)); |
| 73 return process3.exitCode.then((int exit) => returnValue); | 73 return process3.exitCode.then((int exit) => returnValue); |
| 74 } | 74 } |
| 75 | 75 |
| 76 registerExtension('__cleanup', cleanup); | 76 registerExtension('ext.dart.io.cleanup', cleanup); |
| 77 registerExtension('__setup', setup); | 77 registerExtension('ext.dart.io.setup', setup); |
| 78 registerExtension('__closeStdin', closeStdin); | 78 registerExtension('ext.dart.io.closeStdin', closeStdin); |
| 79 | 79 |
| 80 } | 80 } |
| 81 | 81 |
| 82 var processTests = [ | 82 var processTests = [ |
| 83 // Initial. | 83 // Initial. |
| 84 (Isolate isolate) async { | 84 (Isolate isolate) async { |
| 85 var setup = await isolate.invokeRpcNoUpgrade('__setup', {}); | 85 var setup = await isolate.invokeRpcNoUpgrade('ext.dart.io.setup', {}); |
| 86 try { | 86 try { |
| 87 var all = await isolate.invokeRpcNoUpgrade('__getProcesses', {}); | 87 var all = |
| 88 await isolate.invokeRpcNoUpgrade('ext.dart.io.getProcesses', {}); |
| 88 expect(all['type'], equals('_startedprocesses')); | 89 expect(all['type'], equals('_startedprocesses')); |
| 89 | 90 |
| 90 expect(all['data'].length, equals(3)); | 91 expect(all['data'].length, equals(3)); |
| 91 | 92 |
| 92 var first = await isolate.invokeRpcNoUpgrade( | 93 var first = await isolate.invokeRpcNoUpgrade( |
| 93 '__getProcessById', { 'id' : all['data'][0]['id'] }); | 94 'ext.dart.io.getProcessById', { 'id' : all['data'][0]['id'] }); |
| 94 expect(first['name'], io.Platform.executable); | 95 expect(first['name'], io.Platform.executable); |
| 95 expect(first['pid'], equals(setup['pids'][0])); | 96 expect(first['pid'], equals(setup['pids'][0])); |
| 96 expect(first['arguments'].contains('foobar'), isFalse); | 97 expect(first['arguments'].contains('foobar'), isFalse); |
| 97 expect(first['startedAt'], greaterThan(0)); | 98 expect(first['startedAt'], greaterThan(0)); |
| 98 | 99 |
| 99 var second = await isolate.invokeRpcNoUpgrade( | 100 var second = await isolate.invokeRpcNoUpgrade( |
| 100 '__getProcessById', { 'id' : all['data'][1]['id'] }); | 101 'ext.dart.io.getProcessById', { 'id' : all['data'][1]['id'] }); |
| 101 expect(second['name'], io.Platform.executable); | 102 expect(second['name'], io.Platform.executable); |
| 102 expect(second['pid'], equals(setup['pids'][1])); | 103 expect(second['pid'], equals(setup['pids'][1])); |
| 103 expect(second['arguments'].contains('foobar'), isTrue); | 104 expect(second['arguments'].contains('foobar'), isTrue); |
| 104 expect(second['pid'] != first['pid'], isTrue); | 105 expect(second['pid'] != first['pid'], isTrue); |
| 105 expect(second['startedAt'], greaterThan(0)); | 106 expect(second['startedAt'], greaterThan(0)); |
| 106 expect(second['startedAt'], greaterThanOrEqualTo(first['startedAt'])); | 107 expect(second['startedAt'], greaterThanOrEqualTo(first['startedAt'])); |
| 107 | 108 |
| 108 var third = await isolate.invokeRpcNoUpgrade( | 109 var third = await isolate.invokeRpcNoUpgrade( |
| 109 '__getProcessById', { 'id' : all['data'][2]['id'] }); | 110 'ext.dart.io.getProcessById', { 'id' : all['data'][2]['id'] }); |
| 110 expect(third['name'], io.Platform.executable); | 111 expect(third['name'], io.Platform.executable); |
| 111 expect(third['pid'], equals(setup['pids'][2])); | 112 expect(third['pid'], equals(setup['pids'][2])); |
| 112 expect(third['pid'] != first['pid'], isTrue); | 113 expect(third['pid'] != first['pid'], isTrue); |
| 113 expect(third['pid'] != second['pid'], isTrue); | 114 expect(third['pid'] != second['pid'], isTrue); |
| 114 expect(third['startedAt'], greaterThanOrEqualTo(second['startedAt'])); | 115 expect(third['startedAt'], greaterThanOrEqualTo(second['startedAt'])); |
| 115 | 116 |
| 116 await isolate.invokeRpcNoUpgrade('__closeStdin', {}); | 117 await isolate.invokeRpcNoUpgrade('ext.dart.io.closeStdin', {}); |
| 117 all = await isolate.invokeRpcNoUpgrade('__getProcesses', {}); | 118 all = await isolate.invokeRpcNoUpgrade('ext.dart.io.getProcesses', {}); |
| 118 expect(all['type'], equals('_startedprocesses')); | 119 expect(all['type'], equals('_startedprocesses')); |
| 119 expect(all['data'].length, equals(2)); | 120 expect(all['data'].length, equals(2)); |
| 120 } finally { | 121 } finally { |
| 121 await isolate.invokeRpcNoUpgrade('__cleanup', {}); | 122 await isolate.invokeRpcNoUpgrade('ext.dart.io.cleanup', {}); |
| 122 } | 123 } |
| 123 }, | 124 }, |
| 124 ]; | 125 ]; |
| 125 | 126 |
| 126 main(args) async => runIsolateTests(args, processTests, | 127 main(args) async => runIsolateTests(args, processTests, |
| 127 testeeBefore:setupProcesses); | 128 testeeBefore:setupProcesses); |
| OLD | NEW |