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

Side by Side Diff: runtime/observatory/tests/service/tcp_socket_service_test.dart

Issue 1680593004: dart:developer service extension fixes (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 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 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:convert'; 6 import 'dart:convert';
7 import 'dart:io' as io; 7 import 'dart:io' as io;
8 import 'package:observatory/service_io.dart'; 8 import 'package:observatory/service_io.dart';
9 import 'package:unittest/unittest.dart'; 9 import 'package:unittest/unittest.dart';
10 import 'test_helper.dart'; 10 import 'test_helper.dart';
(...skipping 12 matching lines...) Expand all
23 await socket.flush(); 23 await socket.flush();
24 24
25 var socket2 = await io.Socket.connect("127.0.0.1", serverSocket.port); 25 var socket2 = await io.Socket.connect("127.0.0.1", serverSocket.port);
26 socket2.write("foobarfoobar"); 26 socket2.write("foobarfoobar");
27 await socket2.flush(); 27 await socket2.flush();
28 } 28 }
29 29
30 var tcpTests = [ 30 var tcpTests = [
31 // Initial. 31 // Initial.
32 (Isolate isolate) async { 32 (Isolate isolate) async {
33 var result = await isolate.invokeRpcNoUpgrade('__getOpenSockets', {}); 33 var result =
34 await isolate.invokeRpcNoUpgrade('ext.dart.io.getOpenSockets', {});
34 expect(result['type'], equals('_opensockets')); 35 expect(result['type'], equals('_opensockets'));
35 // We expect 3 sockets to be open (in this order): 36 // We expect 3 sockets to be open (in this order):
36 // The server socket accepting connections, on port X 37 // The server socket accepting connections, on port X
37 // The accepted connection on the client, on port Y 38 // The accepted connection on the client, on port Y
38 // The client connection, on port X 39 // The client connection, on port X
39 if (result['data'].length != 5) { 40 if (result['data'].length != 5) {
40 print(result['data']); 41 print(result['data']);
41 } 42 }
42 expect(result['data'].length, equals(5)); 43 expect(result['data'].length, equals(5));
43 // The first socket will have a name like listening:127.0.0.1:X 44 // The first socket will have a name like listening:127.0.0.1:X
44 // The second will have a name like 127.0.0.1:Y 45 // The second will have a name like 127.0.0.1:Y
45 // The third will have a name like 127.0.0.1:X 46 // The third will have a name like 127.0.0.1:X
46 expect(result['data'][0]['name'].startsWith('listening:127.0.0.1'), isTrue); 47 expect(result['data'][0]['name'].startsWith('listening:127.0.0.1'), isTrue);
47 expect(result['data'][1]['name'].startsWith('127.0.0.1:'), isTrue); 48 expect(result['data'][1]['name'].startsWith('127.0.0.1:'), isTrue);
48 expect(result['data'][2]['name'].startsWith('127.0.0.1:'), isTrue); 49 expect(result['data'][2]['name'].startsWith('127.0.0.1:'), isTrue);
49 50
50 var listening = await isolate.invokeRpcNoUpgrade( 51 var listening = await isolate.invokeRpcNoUpgrade(
51 '__getSocketByID', { 'id' : result['data'][0]['id'] }); 52 'ext.dart.io.getSocketByID', { 'id' : result['data'][0]['id'] });
52 expect(listening['id'], equals(result['data'][0]['id'])); 53 expect(listening['id'], equals(result['data'][0]['id']));
53 expect(listening['listening'], isTrue); 54 expect(listening['listening'], isTrue);
54 expect(listening['socketType'], equals('TCP')); 55 expect(listening['socketType'], equals('TCP'));
55 expect(listening['port'], greaterThanOrEqualTo(1024)); 56 expect(listening['port'], greaterThanOrEqualTo(1024));
56 expect(listening['lastRead'], greaterThan(0)); 57 expect(listening['lastRead'], greaterThan(0));
57 58
58 expect(listening['totalRead'], equals(2)); 59 expect(listening['totalRead'], equals(2));
59 expect(listening['lastWrite'], equals(0)); 60 expect(listening['lastWrite'], equals(0));
60 expect(listening['totalWritten'], equals(0)); 61 expect(listening['totalWritten'], equals(0));
61 expect(listening['writeCount'], equals(0)); 62 expect(listening['writeCount'], equals(0));
62 expect(listening['readCount'], equals(2)); 63 expect(listening['readCount'], equals(2));
63 expect(listening['remoteHost'], equals('NA')); 64 expect(listening['remoteHost'], equals('NA'));
64 expect(listening['remotePort'], equals('NA')); 65 expect(listening['remotePort'], equals('NA'));
65 66
66 var client = await isolate.invokeRpcNoUpgrade( 67 var client = await isolate.invokeRpcNoUpgrade(
67 '__getSocketByID', { 'id' : result['data'][1]['id'] }); 68 'ext.dart.io.getSocketByID', { 'id' : result['data'][1]['id'] });
68 expect(client['id'], equals(result['data'][1]['id'])); 69 expect(client['id'], equals(result['data'][1]['id']));
69 70
70 var server = await isolate.invokeRpcNoUpgrade( 71 var server = await isolate.invokeRpcNoUpgrade(
71 '__getSocketByID', { 'id' : result['data'][2]['id'] }); 72 'ext.dart.io.getSocketByID', { 'id' : result['data'][2]['id'] });
72 expect(server['id'], equals(result['data'][2]['id'])); 73 expect(server['id'], equals(result['data'][2]['id']));
73 74
74 // We expect the client to be connected on the port and 75 // We expect the client to be connected on the port and
75 // host of the listening socket. 76 // host of the listening socket.
76 expect(client['remotePort'], equals(listening['port'])); 77 expect(client['remotePort'], equals(listening['port']));
77 expect(client['remoteHost'], equals(listening['host'])); 78 expect(client['remoteHost'], equals(listening['host']));
78 // We expect the third socket (accepted server) to be connected to the 79 // We expect the third socket (accepted server) to be connected to the
79 // same port and host as the listening socket (the listening one). 80 // same port and host as the listening socket (the listening one).
80 expect(server['port'], equals(listening['port'])); 81 expect(server['port'], equals(listening['port']));
81 expect(server['host'], equals(listening['host'])); 82 expect(server['host'], equals(listening['host']));
(...skipping 26 matching lines...) Expand all
108 109
109 // Order 110 // Order
110 // Stopwatch resolution on windows can make us have the same timestamp. 111 // Stopwatch resolution on windows can make us have the same timestamp.
111 if (io.Platform.isWindows) { 112 if (io.Platform.isWindows) {
112 expect(server['lastRead'], greaterThanOrEqualTo(client['lastWrite'])); 113 expect(server['lastRead'], greaterThanOrEqualTo(client['lastWrite']));
113 } else { 114 } else {
114 expect(server['lastRead'], greaterThan(client['lastWrite'])); 115 expect(server['lastRead'], greaterThan(client['lastWrite']));
115 } 116 }
116 117
117 var secondClient = await isolate.invokeRpcNoUpgrade( 118 var secondClient = await isolate.invokeRpcNoUpgrade(
118 '__getSocketByID', { 'id' : result['data'][3]['id'] }); 119 'ext.dart.io.getSocketByID', { 'id' : result['data'][3]['id'] });
119 expect(secondClient['id'], equals(result['data'][3]['id'])); 120 expect(secondClient['id'], equals(result['data'][3]['id']));
120 var secondServer = await isolate.invokeRpcNoUpgrade( 121 var secondServer = await isolate.invokeRpcNoUpgrade(
121 '__getSocketByID', { 'id' : result['data'][4]['id'] }); 122 'ext.dart.io.getSocketByID', { 'id' : result['data'][4]['id'] });
122 expect(secondServer['id'], equals(result['data'][4]['id'])); 123 expect(secondServer['id'], equals(result['data'][4]['id']));
123 124
124 // We expect the client to be connected on the port and 125 // We expect the client to be connected on the port and
125 // host of the listening socket. 126 // host of the listening socket.
126 expect(secondClient['remotePort'], equals(listening['port'])); 127 expect(secondClient['remotePort'], equals(listening['port']));
127 expect(secondClient['remoteHost'], equals(listening['host'])); 128 expect(secondClient['remoteHost'], equals(listening['host']));
128 // We expect the third socket (accepted server) to be connected to the 129 // We expect the third socket (accepted server) to be connected to the
129 // same port and host as the listening socket (the listening one). 130 // same port and host as the listening socket (the listening one).
130 expect(secondServer['port'], equals(listening['port'])); 131 expect(secondServer['port'], equals(listening['port']));
131 expect(secondServer['host'], equals(listening['host'])); 132 expect(secondServer['host'], equals(listening['host']));
(...skipping 28 matching lines...) Expand all
160 // Stopwatch resolution on windows make us sometimes report the same value. 161 // Stopwatch resolution on windows make us sometimes report the same value.
161 if (io.Platform.isWindows) { 162 if (io.Platform.isWindows) {
162 expect(server['lastRead'], greaterThanOrEqualTo(client['lastWrite'])); 163 expect(server['lastRead'], greaterThanOrEqualTo(client['lastWrite']));
163 } else { 164 } else {
164 expect(server['lastRead'], greaterThan(client['lastWrite'])); 165 expect(server['lastRead'], greaterThan(client['lastWrite']));
165 } 166 }
166 }, 167 },
167 ]; 168 ];
168 169
169 main(args) async => runIsolateTests(args, tcpTests, testeeBefore:setupTCP); 170 main(args) async => runIsolateTests(args, tcpTests, testeeBefore:setupTCP);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698