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

Side by Side Diff: runtime/observatory/tests/service/external_service_notification_invocation_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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2017, 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 // VMOptions=--error_on_bad_type --error_on_bad_override
5
6 import 'package:observatory/service_io.dart';
7 import 'package:unittest/unittest.dart';
8 import 'test_helper.dart';
9 import 'dart:io' show WebSocket;
10 import 'dart:convert' show JSON;
11 import 'dart:async' show Future, StreamController;
12
13 var tests = [
14 (Isolate isolate) async {
15 VM vm = isolate.owner;
16
17 final serviceEvents =
18 (await vm.getEventStream('_Service')).asBroadcastStream();
19
20 WebSocket _socket =
21 await WebSocket.connect((vm as WebSocketVM).target.networkAddress);
22 WebSocket _socket_invoker =
23 await WebSocket.connect((vm as WebSocketVM).target.networkAddress);
24
25 final socket = new StreamController();
26 final socket_invoker = new StreamController();
27
28 // Avoid to manually encode and decode messages from the stream
29 socket.stream.map(JSON.encode).pipe(_socket);
30 socket_invoker.stream.map(JSON.encode).pipe(_socket_invoker);
31 final client = _socket.map(JSON.decode).asBroadcastStream();
32 final client_invoker = _socket_invoker.map(JSON.decode).asBroadcastStream();
33
34 const serviceName = 'successService';
35 const serviceAlias = 'serviceAlias';
36 const paramKey = 'pkey';
37 const paramValue = 'pvalue';
38 const repetition = 5;
39
40 socket.add({
41 'jsonrpc': '2.0',
42 'id': 1,
43 'method': '_registerService',
44 'params': {'service': serviceName, 'alias': serviceAlias}
45 });
46
47 // Avoid flaky test.
48 // We cannot assume the order in which two messages will arrive
49 // from two different sockets
50 await Future.wait([client.first, serviceEvents.first]);
51
52 client_invoker.first.then((_) {
53 expect(false, isTrue, reason: 'shouldn\'t get here');
54 }).catchError((e) => e);
55
56 // Testing serial invocation of service which succedes
57 for (var iteration = 0; iteration < repetition; iteration++) {
58 final end = iteration.toString();
59 socket_invoker.add({
60 'jsonrpc': '2.0',
61 'method': vm.services.first.method,
62 'params': {paramKey + end: paramValue + end}
63 });
64 final request = await client.first;
65
66 expect(request, contains('id'));
67 expect(request['id'], isNotNull);
68 expect(request['method'], equals(serviceName));
69 expect(request['params'], isNotNull);
70 expect(request['params'][paramKey + end], equals(paramValue + end));
71
72 socket.add({'jsonrpc': '2.0', 'id': request['id'], 'result': {}});
73 }
74
75 await socket.close();
76 await socket_invoker.close();
77 },
78 ];
79
80 main(args) => runIsolateTests(args, tests);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698