Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 args = ['--pause_isolates_on_start', io.Platform.script.toFilePath()]; | |
| 15 var process1; | |
| 16 var process2; | |
| 17 | |
| 18 void closeDown() { | |
| 19 if (process1 != null) { | |
| 20 process1.kill(); | |
| 21 } | |
| 22 if (process2 != null) { | |
| 23 process2.kill(); | |
| 24 } | |
| 25 } | |
| 26 | |
| 27 Future<ServiceExtensionResponse> cleanup(ignored_a, ignored_b) { | |
| 28 closeDown(); | |
| 29 var result = JSON.encode({'type' : 'foobar'}); | |
| 30 return new Future.value(new ServiceExtensionResponse.result(result)); | |
| 31 } | |
| 32 | |
| 33 Future<ServiceExtensionResponse> setup(ignored_a, ignored_b) async { | |
| 34 try { | |
| 35 process1 = await io.Process.start(io.Platform.executable, args); | |
| 36 process2 = await io.Process.start(io.Platform.executable, | |
| 37 args..add('foobar')); | |
| 38 } catch (e) { | |
| 39 closeDown(); | |
| 40 throw e; | |
| 41 } | |
| 42 var result = JSON.encode({'type' : 'foobar'}); | |
| 43 return new Future.value(new ServiceExtensionResponse.result(result)); | |
| 44 } | |
| 45 registerExtension('__cleanup', cleanup); | |
| 46 registerExtension('__setup', setup); | |
| 47 | |
| 48 } | |
| 49 | |
| 50 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.
| |
| 51 // Stopwatch resolution on windows makes us sometimes report 0; | |
| 52 if (io.Platform.isWindows) { | |
| 53 expect(time, greaterThanOrEqualTo(0)); | |
| 54 } else { | |
| 55 expect(time, greaterThan(0)); | |
| 56 } | |
| 57 } | |
| 58 | |
| 59 var processTests = [ | |
| 60 // Initial. | |
| 61 (Isolate isolate) async { | |
| 62 await isolate.invokeRpcNoUpgrade('__setup', {}); | |
| 63 try { | |
| 64 var all = await isolate.invokeRpcNoUpgrade('__getStartedProcesses', {}); | |
|
Cutch
2015/09/10 16:49:41
Maybe '_getProcesses' ?
ricow1
2015/09/14 07:01:17
Done.
| |
| 65 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
| |
| 66 | |
| 67 expect(all['data'].length, equals(2)); | |
| 68 | |
| 69 var first = await isolate.invokeRpcNoUpgrade( | |
| 70 '__getProcessById', { 'id' : all['data'][0]['id'] }); | |
| 71 expect(first['name'], io.Platform.executable); | |
| 72 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
| |
| 73 expect(first['arguments'].contains('foobar'), isFalse); | |
| 74 | |
| 75 var second = await isolate.invokeRpcNoUpgrade( | |
| 76 '__getProcessById', { 'id' : all['data'][1]['id'] }); | |
| 77 expect(second['name'], io.Platform.executable); | |
| 78 expect(second['pid'], greaterThan(0)); | |
| 79 expect(second['arguments'].contains('foobar'), isTrue); | |
| 80 expect(second['pid'] != first['pid'], isTrue); | |
| 81 | |
|
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.
| |
| 82 } finally { | |
| 83 await isolate.invokeRpcNoUpgrade('__cleanup', {}); | |
| 84 } | |
| 85 }, | |
| 86 ]; | |
| 87 | |
| 88 main(args) async => runIsolateTests(args, processTests, | |
| 89 testeeBefore:setupProcesses); | |
| OLD | NEW |