Skip to content

Commit 08ef2c3

Browse files
authored
fix(cupertino_http): Disable local close code tests on macOS (#1844)
1 parent c8355d1 commit 08ef2c3

File tree

4 files changed

+60
-22
lines changed

4 files changed

+60
-22
lines changed

pkgs/cupertino_http/example/integration_test/url_session_task_test.dart

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -67,24 +67,32 @@ void testWebSocketTask() {
6767
session.finishTasksAndInvalidate();
6868
});
6969

70-
test('client code and reason', () async {
71-
final session = URLSession.sharedSession();
72-
final task = session.webSocketTaskWithRequest(
73-
URLRequest.fromUrl(Uri.parse('ws://localhost:${server.port}/?noclose')),
74-
)..resume();
75-
await task.sendMessage(
76-
URLSessionWebSocketMessage.fromString('Hello World!'),
77-
);
78-
await task.receiveMessage();
79-
task.cancelWithCloseCode(4998, 'Bye'.codeUnits.toNSData());
80-
81-
// Allow the server to run and save the close code.
82-
while (lastCloseCode == null) {
83-
await Future<void>.delayed(const Duration(milliseconds: 10));
84-
}
85-
expect(lastCloseCode, 4998);
86-
expect(lastCloseReason, 'Bye');
87-
});
70+
test(
71+
'client code and reason',
72+
() async {
73+
final session = URLSession.sharedSession();
74+
final task = session.webSocketTaskWithRequest(
75+
URLRequest.fromUrl(
76+
Uri.parse('ws://localhost:${server.port}/?noclose'),
77+
),
78+
)..resume();
79+
await task.sendMessage(
80+
URLSessionWebSocketMessage.fromString('Hello World!'),
81+
);
82+
await task.receiveMessage();
83+
task.cancelWithCloseCode(4998, 'Bye'.codeUnits.toNSData());
84+
85+
// Allow the server to run and save the close code.
86+
while (lastCloseCode == null) {
87+
await Future<void>.delayed(const Duration(milliseconds: 10));
88+
}
89+
expect(lastCloseCode, 4998);
90+
expect(lastCloseReason, 'Bye');
91+
},
92+
skip: Platform.isMacOS
93+
? 'https://github.com/dart-lang/http/issues/1814'
94+
: false,
95+
);
8896

8997
test('server code and reason', () async {
9098
final session = URLSession.sharedSession();

pkgs/cupertino_http/example/integration_test/web_socket_conformance_test.dart

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,39 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5+
import 'dart:io';
6+
57
import 'package:cupertino_http/cupertino_http.dart';
68
import 'package:test/test.dart';
9+
import 'package:web_socket/web_socket.dart';
710
import 'package:web_socket_conformance_tests/web_socket_conformance_tests.dart';
811

9-
void main() {
10-
testAll(CupertinoWebSocket.connect);
12+
void runTests(
13+
Future<WebSocket> Function(Uri uri, {Iterable<String>? protocols})
14+
webSocketFactory,
15+
) {
16+
if (Platform.isMacOS) {
17+
// TODO(https://github.com/dart-lang/http/issues/1814): Fix web socket tests
18+
// on macOS.
19+
testCloseRemote(webSocketFactory);
20+
testConnectUri(webSocketFactory);
21+
testDisconnectAfterUpgrade(webSocketFactory);
22+
testNoUpgrade(webSocketFactory);
23+
testPayloadTransfer(webSocketFactory);
24+
testPeerProtocolErrors(webSocketFactory);
25+
testProtocols(webSocketFactory);
26+
} else {
27+
testAll(webSocketFactory);
28+
}
29+
}
1130

31+
void main() {
1232
group('defaultSessionConfiguration', () {
13-
testAll(CupertinoWebSocket.connect);
33+
runTests(CupertinoWebSocket.connect);
1434
});
1535
group('fromSessionConfiguration', () {
1636
final config = URLSessionConfiguration.ephemeralSessionConfiguration();
17-
testAll(
37+
runTests(
1838
(uri, {protocols}) =>
1939
CupertinoWebSocket.connect(uri, protocols: protocols, config: config),
2040
);

pkgs/cupertino_http/example/pubspec.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ dev_dependencies:
3333
sdk: flutter
3434
objective_c: ^8.1.0
3535
test: ^1.21.1
36+
web_socket: '^1.0.0'
3637
web_socket_conformance_tests:
3738
path: ../../web_socket_conformance_tests/
3839

pkgs/web_socket_conformance_tests/lib/web_socket_conformance_tests.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@ import 'src/payload_transfer_tests.dart';
1212
import 'src/peer_protocol_errors_tests.dart';
1313
import 'src/protocol_tests.dart';
1414

15+
export 'src/close_local_tests.dart';
16+
export 'src/close_remote_tests.dart';
17+
export 'src/connect_uri_tests.dart';
18+
export 'src/disconnect_after_upgrade_tests.dart';
19+
export 'src/no_upgrade_tests.dart';
20+
export 'src/payload_transfer_tests.dart';
21+
export 'src/peer_protocol_errors_tests.dart';
22+
export 'src/protocol_tests.dart';
23+
1524
/// Runs the entire test suite against the given [WebSocket].
1625
void testAll(
1726
Future<WebSocket> Function(Uri uri, {Iterable<String>? protocols})

0 commit comments

Comments
 (0)