OLD | NEW |
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 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 | 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 import "dart:async"; | 5 import "dart:async"; |
6 import "dart:io"; | 6 import "dart:io"; |
7 import "dart:isolate"; | 7 import "dart:isolate"; |
8 import "dart:math"; | 8 import "dart:math"; |
9 | 9 |
10 import "package:async_helper/async_helper.dart"; | 10 import "package:async_helper/async_helper.dart"; |
11 import "package:expect/expect.dart"; | 11 import "package:expect/expect.dart"; |
12 | 12 |
13 const String LOOPBACK_IP_V4_STRING = "127.0.0.1"; | 13 const String LOOPBACK_IP_V4_STRING = "127.0.0.1"; |
14 | 14 |
15 void testArguments() { | 15 void testArguments() { |
16 Expect.throws(() => RawSynchronousSocket.connectSync(null, 0)); | 16 Expect.throws(() => RawSynchronousSocket.connectSync(null, 0)); |
17 Expect.throws( | 17 Expect.throws( |
18 () => RawSynchronousSocket.connectSync(LOOPBACK_IP_V4_STRING, null)); | 18 () => RawSynchronousSocket.connectSync(LOOPBACK_IP_V4_STRING, null)); |
19 Expect.throws( | 19 Expect.throws( |
20 () => RawSynchronousSocket.connectSync(LOOPBACK_IP_V4_STRING, 65536)); | 20 () => RawSynchronousSocket.connectSync(LOOPBACK_IP_V4_STRING, 65536)); |
21 Expect.throws( | 21 Expect.throws( |
22 () => RawSynchronousSocket.connectSync(LOOPBACK_IP_V4_STRING, -1)); | 22 () => RawSynchronousSocket.connectSync(LOOPBACK_IP_V4_STRING, -1)); |
23 Expect.throws(() => | |
24 RawSynchronousSocket.connectSync(LOOPBACK_IP_V4_STRING, 0, backlog: -1)); | |
25 } | 23 } |
26 | 24 |
27 // The connection attempt happens on the main Dart thread and the OS timeout can | 25 // The connection attempt happens on the main Dart thread and the OS timeout can |
28 // be arbitrarily long, causing timeout issues on the build bots. This isn't an | 26 // be arbitrarily long, causing timeout issues on the build bots. This isn't an |
29 // issue with the async sockets since the lookup for a connect call happens on | 27 // issue with the async sockets since the lookup for a connect call happens on |
30 // the IO service thread. | 28 // the IO service thread. |
31 /* | 29 /* |
32 void testInvalidConnect() { | 30 void testInvalidConnect() { |
33 // Connect to an unknown DNS name. | 31 // Connect to an unknown DNS name. |
34 try { | 32 try { |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 }, onDone: () { | 180 }, onDone: () { |
183 Expect.isTrue(closedEventReceived); | 181 Expect.isTrue(closedEventReceived); |
184 connections++; | 182 connections++; |
185 if (connections >= connection_count) { | 183 if (connections >= connection_count) { |
186 server.close(); | 184 server.close(); |
187 } | 185 } |
188 }); | 186 }); |
189 }, onDone: () { | 187 }, onDone: () { |
190 // Let the client know we're shutting down then kill the isolate. | 188 // Let the client know we're shutting down then kill the isolate. |
191 sendPort.send(null); | 189 sendPort.send(null); |
192 kill(); | 190 Isolate.current.kill(); |
193 }); | 191 }); |
194 }); | 192 }); |
195 } | 193 } |
196 | 194 |
197 Future testSimpleReadWrite({bool dropReads}) async { | 195 Future testSimpleReadWrite({bool dropReads}) async { |
198 asyncStart(); | 196 asyncStart(); |
199 // This test creates a server and a client connects. The client writes data | 197 // This test creates a server and a client connects. The client writes data |
200 // to the socket and the server echos it back. The client confirms the data it | 198 // to the socket and the server echos it back. The client confirms the data it |
201 // reads is the same as the data sent, then closes the socket, resulting in | 199 // reads is the same as the data sent, then closes the socket, resulting in |
202 // the closing of the server, which responds on receivePort with null to | 200 // the closing of the server, which responds on receivePort with null to |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
484 await testShutdown(); | 482 await testShutdown(); |
485 testSimpleConnect(); | 483 testSimpleConnect(); |
486 testServerListenAfterConnect(); | 484 testServerListenAfterConnect(); |
487 await testSimpleReadWrite(); | 485 await testSimpleReadWrite(); |
488 await testPartialRead(); | 486 await testPartialRead(); |
489 await testPartialWrite(); | 487 await testPartialWrite(); |
490 testInvalidReadWriteOperations(); | 488 testInvalidReadWriteOperations(); |
491 testClosedError(); | 489 testClosedError(); |
492 asyncEnd(); | 490 asyncEnd(); |
493 } | 491 } |
OLD | NEW |