Chromium Code Reviews| Index: runtime/observatory/tests/service/process_service_test.dart |
| diff --git a/runtime/observatory/tests/service/process_service_test.dart b/runtime/observatory/tests/service/process_service_test.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..4c22142f48b161f6d8d04e3a5c7b28ac6b6c7475 |
| --- /dev/null |
| +++ b/runtime/observatory/tests/service/process_service_test.dart |
| @@ -0,0 +1,89 @@ |
| +// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
| +// for details. All rights reserved. Use of this source code is governed by a |
| +// BSD-style license that can be found in the LICENSE file. |
| + |
| +import 'dart:async'; |
| +import 'dart:convert'; |
| +import 'dart:developer'; |
| +import 'dart:io' as io; |
| +import 'package:observatory/service_io.dart'; |
| +import 'package:unittest/unittest.dart'; |
| +import 'test_helper.dart'; |
| + |
| +Future setupProcesses() async { |
| + var args = ['--pause_isolates_on_start', io.Platform.script.toFilePath()]; |
| + var process1; |
| + var process2; |
| + |
| + void closeDown() { |
| + if (process1 != null) { |
| + process1.kill(); |
| + } |
| + if (process2 != null) { |
| + process2.kill(); |
| + } |
| + } |
| + |
| + Future<ServiceExtensionResponse> cleanup(ignored_a, ignored_b) { |
| + closeDown(); |
| + var result = JSON.encode({'type' : 'foobar'}); |
| + return new Future.value(new ServiceExtensionResponse.result(result)); |
| + } |
| + |
| + Future<ServiceExtensionResponse> setup(ignored_a, ignored_b) async { |
| + try { |
| + process1 = await io.Process.start(io.Platform.executable, args); |
| + process2 = await io.Process.start(io.Platform.executable, |
| + args..add('foobar')); |
| + } catch (e) { |
| + closeDown(); |
| + throw e; |
| + } |
| + var result = JSON.encode({'type' : 'foobar'}); |
| + return new Future.value(new ServiceExtensionResponse.result(result)); |
| + } |
| + registerExtension('__cleanup', cleanup); |
| + registerExtension('__setup', setup); |
| + |
| +} |
| + |
| +void expectTimeBiggerThanZero(time) { |
|
Søren Gjesse
2015/09/10 17:43:34
This function is not used in this test.
ricow1
2015/09/14 07:01:17
Done.
|
| + // Stopwatch resolution on windows makes us sometimes report 0; |
| + if (io.Platform.isWindows) { |
| + expect(time, greaterThanOrEqualTo(0)); |
| + } else { |
| + expect(time, greaterThan(0)); |
| + } |
| +} |
| + |
| +var processTests = [ |
| + // Initial. |
| + (Isolate isolate) async { |
| + await isolate.invokeRpcNoUpgrade('__setup', {}); |
| + try { |
| + var all = await isolate.invokeRpcNoUpgrade('__getStartedProcesses', {}); |
|
Cutch
2015/09/10 16:49:41
Maybe '_getProcesses' ?
ricow1
2015/09/14 07:01:17
Done.
|
| + expect(all['type'], equals('_startedprocesses')); |
|
Cutch
2015/09/10 16:49:41
Maybe '_Process' ?
ricow1
2015/09/14 07:01:17
Changed to processes - this is after all, more tha
|
| + |
| + expect(all['data'].length, equals(2)); |
| + |
| + var first = await isolate.invokeRpcNoUpgrade( |
| + '__getProcessById', { 'id' : all['data'][0]['id'] }); |
| + expect(first['name'], io.Platform.executable); |
| + expect(first['pid'], greaterThan(0)); |
|
Søren Gjesse
2015/09/10 17:43:34
Couldn't you somehow also check the pid?
ricow1
2015/09/14 07:01:16
Done
|
| + expect(first['arguments'].contains('foobar'), isFalse); |
| + |
| + var second = await isolate.invokeRpcNoUpgrade( |
| + '__getProcessById', { 'id' : all['data'][1]['id'] }); |
| + expect(second['name'], io.Platform.executable); |
| + expect(second['pid'], greaterThan(0)); |
| + expect(second['arguments'].contains('foobar'), isTrue); |
| + expect(second['pid'] != first['pid'], isTrue); |
| + |
|
Søren Gjesse
2015/09/10 17:43:34
Can the test be extended to also test what happens
ricow1
2015/09/14 07:01:17
Done.
|
| + } finally { |
| + await isolate.invokeRpcNoUpgrade('__cleanup', {}); |
| + } |
| + }, |
| +]; |
| + |
| +main(args) async => runIsolateTests(args, processTests, |
| + testeeBefore:setupProcesses); |