| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2015, 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 import 'dart:async'; | |
| 6 import 'dart:convert'; | |
| 7 import 'dart:io' as io; | |
| 8 import 'package:observatory/service_io.dart'; | |
| 9 import 'package:unittest/unittest.dart'; | |
| 10 import 'test_helper.dart'; | |
| 11 | |
| 12 Future setupUDP() async { | |
| 13 var server = await io.RawDatagramSocket.bind('127.0.0.1', 0); | |
| 14 server.listen((io.RawSocketEvent event) { | |
| 15 if(event == io.RawSocketEvent.READ) { | |
| 16 io.Datagram dg = server.receive(); | |
| 17 dg.data.forEach((x) => true); | |
| 18 } | |
| 19 }); | |
| 20 var client = await io.RawDatagramSocket.bind('127.0.0.1', 0); | |
| 21 client.send(UTF8.encoder.convert('foobar'), | |
| 22 new io.InternetAddress('127.0.0.1'), server.port); | |
| 23 } | |
| 24 | |
| 25 var udpTests = [ | |
| 26 // Initial. | |
| 27 (Isolate isolate) async { | |
| 28 var result = await isolate.invokeRpcNoUpgrade('__getOpenSockets', {}); | |
| 29 expect(result['type'], equals('_opensockets')); | |
| 30 // We expect 2 sockets to be open (in this order): | |
| 31 // The server socket accepting connections, on port X | |
| 32 // The client socket on port Y | |
| 33 expect(result['data'].length, equals(2)); | |
| 34 // The first socket will have a name like listening:127.0.0.1:X | |
| 35 // The second will have a name like 127.0.0.1:Y | |
| 36 // The third will have a name like 127.0.0.1:X | |
| 37 expect(result['data'][0]['name'].startsWith('127.0.0.1'), isTrue); | |
| 38 expect(result['data'][1]['name'].startsWith('127.0.0.1:'), isTrue); | |
| 39 | |
| 40 var server = await isolate.invokeRpcNoUpgrade( | |
| 41 '__getSocketByID', { 'id' : result['data'][0]['id'] }); | |
| 42 expect(server['id'], equals(result['data'][0]['id'])); | |
| 43 expect(server['remote_port'], equals('NA')); | |
| 44 expect(server['remote_host'], equals('NA')); | |
| 45 expect(server['listening'], isFalse); | |
| 46 expect(server['socket_type'], equals('UDP')); | |
| 47 expect(server['port'], greaterThanOrEqualTo(1024)); | |
| 48 expect(server['last_read'], greaterThan(0)); | |
| 49 expect(server['total_read'], equals(6)); | |
| 50 expect(server['last_write'], equals(0)); | |
| 51 expect(server['total_written'], equals(0)); | |
| 52 expect(server['write_count'], equals(0)); | |
| 53 expect(server['read_count'], equals(1)); | |
| 54 | |
| 55 var client = await isolate.invokeRpcNoUpgrade( | |
| 56 '__getSocketByID', { 'id' : result['data'][1]['id'] }); | |
| 57 expect(client['id'], equals(result['data'][1]['id'])); | |
| 58 expect(client['remote_port'], equals('NA')); | |
| 59 expect(client['remote_host'], equals('NA')); | |
| 60 expect(client['listening'], isFalse); | |
| 61 expect(client['socket_type'], equals('UDP')); | |
| 62 expect(client['port'], greaterThanOrEqualTo(1024)); | |
| 63 expect(client['last_read'], equals(0)); | |
| 64 expect(client['total_read'], equals(0)); | |
| 65 expect(client['last_write'], greaterThan(0)); | |
| 66 expect(client['total_written'], equals(6)); | |
| 67 expect(client['write_count'], equals(1)); | |
| 68 expect(client['read_count'], equals(0)); | |
| 69 }, | |
| 70 ]; | |
| 71 | |
| 72 main(args) async => runIsolateTests(args, udpTests, testeeBefore:setupUDP); | |
| OLD | NEW |