OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 library test.channel; | 5 library test.channel; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 | 8 |
9 import 'package:analysis_server/src/channel.dart'; | 9 import 'package:analysis_server/src/channel.dart'; |
10 import 'package:analysis_server/src/protocol.dart'; | 10 import 'package:analysis_server/src/protocol.dart'; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 } | 54 } |
55 | 55 |
56 static Future close() { | 56 static Future close() { |
57 var timeout = new Duration(seconds: 1); | 57 var timeout = new Duration(seconds: 1); |
58 var future = client.responseStream.drain().timeout(timeout); | 58 var future = client.responseStream.drain().timeout(timeout); |
59 client.close(); | 59 client.close(); |
60 return future; | 60 return future; |
61 } | 61 } |
62 | 62 |
63 static Future invalidJsonToClient() { | 63 static Future invalidJsonToClient() { |
64 socket.twin.add('{"foo":"bar"}'); | 64 var result = client.responseStream |
65 server.sendResponse(new Response('myId')); | |
66 return client.responseStream | |
67 .first | 65 .first |
68 .timeout(new Duration(seconds: 1)) | 66 .timeout(new Duration(seconds: 1)) |
69 .then((Response response) { | 67 .then((Response response) { |
70 expect(response.id, equals('myId')); | 68 expect(response.id, equals('myId')); |
71 expectMsgCount(responseCount: 1); | 69 expectMsgCount(responseCount: 1); |
72 }); | 70 }); |
| 71 socket.twin.add('{"foo":"bar"}'); |
| 72 server.sendResponse(new Response('myId')); |
| 73 return result; |
73 } | 74 } |
74 | 75 |
75 static Future invalidJsonToServer() { | 76 static Future invalidJsonToServer() { |
76 socket.add('"blat"'); | 77 var result = client.responseStream |
77 return client.responseStream | |
78 .first | 78 .first |
79 .timeout(new Duration(seconds: 1)) | 79 .timeout(new Duration(seconds: 1)) |
80 .then((Response response) { | 80 .then((Response response) { |
81 expect(response.id, equals('')); | 81 expect(response.id, equals('')); |
82 expect(response.error, isNotNull); | 82 expect(response.error, isNotNull); |
83 expectMsgCount(responseCount: 1); | 83 expectMsgCount(responseCount: 1); |
84 }); | 84 }); |
| 85 socket.add('"blat"'); |
| 86 return result; |
85 } | 87 } |
86 | 88 |
87 static Future notification() { | 89 static Future notification() { |
88 server.sendNotification(new Notification('myEvent')); | 90 var result = client.notificationStream |
89 return client.notificationStream | |
90 .first | 91 .first |
91 .timeout(new Duration(seconds: 1)) | 92 .timeout(new Duration(seconds: 1)) |
92 .then((Notification notification) { | 93 .then((Notification notification) { |
93 expect(notification.event, equals('myEvent')); | 94 expect(notification.event, equals('myEvent')); |
94 expectMsgCount(notificationCount: 1); | 95 expectMsgCount(notificationCount: 1); |
95 | |
96 expect(notificationsReceived.first, equals(notification)); | 96 expect(notificationsReceived.first, equals(notification)); |
97 }); | 97 }); |
| 98 server.sendNotification(new Notification('myEvent')); |
| 99 return result; |
98 } | 100 } |
99 | 101 |
100 static Future notificationAndResponse() { | 102 static Future notificationAndResponse() { |
101 server | 103 var result = Future |
102 ..sendNotification(new Notification('myEvent')) | |
103 ..sendResponse(new Response('myId')); | |
104 return Future | |
105 .wait([ | 104 .wait([ |
106 client.notificationStream.first, | 105 client.notificationStream.first, |
107 client.responseStream.first]) | 106 client.responseStream.first]) |
108 .timeout(new Duration(seconds: 1)) | 107 .timeout(new Duration(seconds: 1)) |
109 .then((_) => expectMsgCount(responseCount: 1, notificationCount: 1)); | 108 .then((_) => expectMsgCount(responseCount: 1, notificationCount: 1)); |
| 109 server |
| 110 ..sendNotification(new Notification('myEvent')) |
| 111 ..sendResponse(new Response('myId')); |
| 112 return result; |
110 } | 113 } |
111 | 114 |
112 static void request() { | 115 static void request() { |
113 client.sendRequest(new Request('myId', 'myMth')); | 116 client.sendRequest(new Request('myId', 'myMth')); |
114 server.listen((Request request) { | 117 server.listen((Request request) { |
115 expect(request.id, equals('myId')); | 118 expect(request.id, equals('myId')); |
116 expect(request.method, equals('myMth')); | 119 expect(request.method, equals('myMth')); |
117 expectMsgCount(requestCount: 1); | 120 expectMsgCount(requestCount: 1); |
118 }); | 121 }); |
119 } | 122 } |
(...skipping 28 matching lines...) Expand all Loading... |
148 } | 151 } |
149 | 152 |
150 static void expectMsgCount({requestCount: 0, | 153 static void expectMsgCount({requestCount: 0, |
151 responseCount: 0, | 154 responseCount: 0, |
152 notificationCount: 0}) { | 155 notificationCount: 0}) { |
153 expect(requestsReceived, hasLength(requestCount)); | 156 expect(requestsReceived, hasLength(requestCount)); |
154 expect(responsesReceived, hasLength(responseCount)); | 157 expect(responsesReceived, hasLength(responseCount)); |
155 expect(notificationsReceived, hasLength(notificationCount)); | 158 expect(notificationsReceived, hasLength(notificationCount)); |
156 } | 159 } |
157 } | 160 } |
OLD | NEW |