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

Unified Diff: tests/standalone/io/raw_server_socket_cancel_test.dart

Issue 12381013: dart:io | Split raw_server_socket_cancel test off from raw_socket_test. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 10 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 | tests/standalone/io/raw_socket_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/standalone/io/raw_server_socket_cancel_test.dart
diff --git a/tests/standalone/io/raw_server_socket_cancel_test.dart b/tests/standalone/io/raw_server_socket_cancel_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..0062a6e0db6670fe39af10f78f0bec6c120b6ad0
--- /dev/null
+++ b/tests/standalone/io/raw_server_socket_cancel_test.dart
@@ -0,0 +1,72 @@
+// Copyright (c) 2013, 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=
+// VMOptions=--short_socket_read
+// VMOptions=--short_socket_write
+// VMOptions=--short_socket_read --short_socket_write
+
+import "dart:async";
+import "dart:io";
+import "dart:isolate";
+
+void testCancelResubscribeServerSocket() {
+ const int socketCount = 10;
+ var acceptCount = 0;
+ var doneCount = 0;
+ var closeCount = 0;
+ var errorCount = 0;
+
+ ReceivePort port = new ReceivePort();
+
+ RawServerSocket.bind().then((server) {
+ Expect.isTrue(server.port > 0);
+
+ void checkDone() {
+ if (doneCount == socketCount &&
+ closeCount + errorCount == socketCount) {
+ port.close();
+ }
+ }
+
+ // Subscribe the server socket. Then cancel subscription and
+ // subscribe again.
+ var subscription;
+ subscription = server.listen((client) {
+ if (++acceptCount == socketCount / 2) {
+ subscription.cancel();
+ Timer.run(() {
+ subscription = server.listen((_) {
+ // Close on cancel, so no more events.
+ Expect.fail("Event after closed through cancel");
+ });
+ });
+ }
+ // Close the client socket.
+ client.close();
+ });
+
+ // Connect a number of sockets.
+ for (int i = 0; i < socketCount; i++) {
+ RawSocket.connect("127.0.0.1", server.port).then((socket) {
+ socket.writeEventsEnabled = false;
+ var subscription;
+ subscription = socket.listen((event) {
+ Expect.equals(RawSocketEvent.READ_CLOSED, event);
+ socket.close();
+ closeCount++;
+ checkDone();
+ },
+ onDone: () { doneCount++; checkDone(); },
+ onError: (e) { errorCount++; checkDone(); });
+ }).catchError((e) {
+ errorCount++; checkDone();
+ });
+ }
+ });
+}
+
+void main() {
+ testCancelResubscribeServerSocket();
+}
« no previous file with comments | « no previous file | tests/standalone/io/raw_socket_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698