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

Unified Diff: runtime/observatory/tests/service/external_service_disappear_test.dart

Issue 2980733003: Introduced support for external services registration in the ServiceProtocol (Closed)
Patch Set: Address comments Created 3 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: runtime/observatory/tests/service/external_service_disappear_test.dart
diff --git a/runtime/observatory/tests/service/external_service_disappear_test.dart b/runtime/observatory/tests/service/external_service_disappear_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..f43a8913765f262a4aaef7e5e3306785cfb766c2
--- /dev/null
+++ b/runtime/observatory/tests/service/external_service_disappear_test.dart
@@ -0,0 +1,87 @@
+// Copyright (c) 2017, 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.
+// VMOptions=--error_on_bad_type --error_on_bad_override
+
+import 'package:observatory/service_io.dart';
+import 'package:unittest/unittest.dart';
+import 'test_helper.dart';
+import 'dart:io' show WebSocket;
+import 'dart:convert' show JSON;
+import 'dart:async' show Future, StreamController;
+
+var tests = [
+ (Isolate isolate) async {
+ VM vm = isolate.owner;
+
+ final serviceEvents =
+ (await vm.getEventStream('_Service')).asBroadcastStream();
+
+ WebSocket _socket =
+ await WebSocket.connect((vm as WebSocketVM).target.networkAddress);
+
+ final socket = new StreamController();
+
+ // Avoid to manually encode and decode messages from the stream
+ socket.stream.map(JSON.encode).pipe(_socket);
+ final client = _socket.map(JSON.decode).asBroadcastStream();
+
+ // Note: keep this in sync with sdk/lib/vmservice.dart
+ const kServiceDisappeared = 111;
+ const kServiceDisappeared_Msg = 'Service has disappeared';
+
+ const serviceName = 'disapearService';
+ const serviceAlias = 'serviceAlias';
+ const paramKey = 'pkey';
+ const paramValue = 'pvalue';
+ const repetition = 5;
+
+ socket.add({
+ 'jsonrpc': '2.0',
+ 'id': 1,
+ 'method': '_registerService',
+ 'params': {'service': serviceName, 'alias': serviceAlias}
+ });
+
+ // Avoid flaky test.
+ // We cannot assume the order in which two messages will arrive
+ // from two different sockets
+ await Future.wait([client.first, serviceEvents.first]);
+
+ // Testing invocation of service which disappear
+ {
+ final results = new List<Future<Map>>.generate(repetition, (iteration) {
+ final end = iteration.toString();
+ return vm.invokeRpcRaw(
+ vm.services.first.method, {paramKey + end: paramValue + end});
+ });
+ final requests = await (client.take(repetition).toList());
+
+ requests.forEach((final request) {
+ final iteration = requests.indexOf(request);
+ final end = iteration.toString();
+
+ // check requests while they arrive
+ expect(request, contains('id'));
+ expect(request['id'], isNotNull);
+ expect(request['method'], equals(serviceName));
+ expect(request['params'], isNotNull);
+ expect(request['params'][paramKey + end], equals(paramValue + end));
+ });
+
+ await socket.close();
+
+ await Future.wait(results.map((future) {
+ return future.then((_) {
+ expect(false, isTrue, reason: 'shouldn\'t get here');
+ }).catchError((ServerRpcException error) {
+ expect(error, isNotNull);
+ expect(error.code, equals(kServiceDisappeared));
+ expect(error.message, equals(kServiceDisappeared_Msg));
+ });
+ }));
+ }
+ },
+];
+
+main(args) => runIsolateTests(args, tests);

Powered by Google App Engine
This is Rietveld 408576698