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

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

Issue 1194893002: Add _getPorts rpc test (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 6 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/observatory/tests/service/get_ports_rpc_test.dart
diff --git a/runtime/observatory/tests/service/get_ports_rpc_test.dart b/runtime/observatory/tests/service/get_ports_rpc_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..b9dcda4a334b29c53d38a332d20430911e6d71db
--- /dev/null
+++ b/runtime/observatory/tests/service/get_ports_rpc_test.dart
@@ -0,0 +1,56 @@
+// 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.
+// VMOptions=--compile-all --error_on_bad_type --error_on_bad_override
+
+library get_ports_rpc_test;
+
+import 'dart:async';
+import 'dart:isolate';
+import 'package:observatory/service_io.dart';
+import 'package:unittest/unittest.dart';
+
+import 'test_helper.dart';
+
+var port1;
+var port2;
+
+void warmup() {
+ port1 = new RawReceivePort(null);
+ port2 = new RawReceivePort((_) {
+ });
+}
+
+int countHandlerMatches(ports, matcher) {
+ var matches = 0;
+ for (var port in ports) {
+ if (matcher(port['handler'])) {
+ matches++;
+ }
+ }
+ return matches;
+}
+
+bool nullMatcher(handler) {
+ return handler.isNull;
+}
+
+bool closureMatcher(handler) {
+ return handler.isClosure;
+}
+
+var tests = [
+ (Isolate isolate) async {
+ var result = await isolate.invokeRpc('_getPorts', {});
+ expect(result['type'], equals('_Ports'));
+ expect(result['ports'], isList);
+ var ports = result['ports'];
+ // There are three ports: the two created in warmup and the stdin listener
+ // created by the test harness.
+ expect(ports.length, equals(3));
+ expect(countHandlerMatches(ports, nullMatcher), equals(1));
+ expect(countHandlerMatches(ports, closureMatcher), equals(2));
+ },
+];
+
+main(args) async => runIsolateTests(args, tests, testeeBefore:warmup);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698