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

Side by Side 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, 9 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | tests/standalone/io/raw_socket_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2013, 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 //
5 // VMOptions=
6 // VMOptions=--short_socket_read
7 // VMOptions=--short_socket_write
8 // VMOptions=--short_socket_read --short_socket_write
9
10 import "dart:async";
11 import "dart:io";
12 import "dart:isolate";
13
14 void testCancelResubscribeServerSocket() {
15 const int socketCount = 10;
16 var acceptCount = 0;
17 var doneCount = 0;
18 var closeCount = 0;
19 var errorCount = 0;
20
21 ReceivePort port = new ReceivePort();
22
23 RawServerSocket.bind().then((server) {
24 Expect.isTrue(server.port > 0);
25
26 void checkDone() {
27 if (doneCount == socketCount &&
28 closeCount + errorCount == socketCount) {
29 port.close();
30 }
31 }
32
33 // Subscribe the server socket. Then cancel subscription and
34 // subscribe again.
35 var subscription;
36 subscription = server.listen((client) {
37 if (++acceptCount == socketCount / 2) {
38 subscription.cancel();
39 Timer.run(() {
40 subscription = server.listen((_) {
41 // Close on cancel, so no more events.
42 Expect.fail("Event after closed through cancel");
43 });
44 });
45 }
46 // Close the client socket.
47 client.close();
48 });
49
50 // Connect a number of sockets.
51 for (int i = 0; i < socketCount; i++) {
52 RawSocket.connect("127.0.0.1", server.port).then((socket) {
53 socket.writeEventsEnabled = false;
54 var subscription;
55 subscription = socket.listen((event) {
56 Expect.equals(RawSocketEvent.READ_CLOSED, event);
57 socket.close();
58 closeCount++;
59 checkDone();
60 },
61 onDone: () { doneCount++; checkDone(); },
62 onError: (e) { errorCount++; checkDone(); });
63 }).catchError((e) {
64 errorCount++; checkDone();
65 });
66 }
67 });
68 }
69
70 void main() {
71 testCancelResubscribeServerSocket();
72 }
OLDNEW
« 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