diff --git a/links/gql_websocket_link/pubspec.yaml b/links/gql_websocket_link/pubspec.yaml index 362bbb30..867268fb 100644 --- a/links/gql_websocket_link/pubspec.yaml +++ b/links/gql_websocket_link/pubspec.yaml @@ -11,7 +11,8 @@ dependencies: meta: ^1.3.0 rxdart: '>=0.26.0 <0.28.0' uuid: '>=3.0.0 <5.0.0' - web_socket_channel: ^2.0.0 + web_socket_channel: ^3.0.0 + web_socket: ^0.1.5 dev_dependencies: gql_pedantic: ^1.0.2 mockito: ^5.0.0 diff --git a/links/gql_websocket_link/test/gql_websocket_link_test.dart b/links/gql_websocket_link/test/gql_websocket_link_test.dart index 6d881d97..376110eb 100644 --- a/links/gql_websocket_link/test/gql_websocket_link_test.dart +++ b/links/gql_websocket_link/test/gql_websocket_link_test.dart @@ -156,6 +156,8 @@ void _testLinks( link = makeLink(null, channelGenerator: () => channel); // link.request(request).listen(print); + + await server.close(); }, ); @@ -204,6 +206,8 @@ void _testLinks( ); // link.request(request).listen(print); + + await server.close(); }, ); @@ -254,6 +258,8 @@ void _testLinks( ); // link.request(request).listen(print); + + await server.close(); }, ); @@ -341,6 +347,8 @@ void _testLinks( }, ), ); + + await server.close(); }, ); @@ -465,6 +473,8 @@ void _testLinks( count: maxCall, ), ); + + await server.close(); }, ); @@ -567,6 +577,8 @@ void _testLinks( }, ), ); + + await server.close(); }, ); @@ -703,6 +715,8 @@ void _testLinks( count: maxCall, ), ); + + await server.close(); }, ); @@ -757,6 +771,7 @@ void _testLinks( webSocket = await WebSocket.connect("ws://localhost:${server.port}"); channel = IOWebSocketChannel(webSocket); link = makeLink(null, channelGenerator: () => channel); + await server.close(); expect( link.request(request).first, throwsA(isA()), @@ -812,6 +827,7 @@ void _testLinks( webSocket = await WebSocket.connect("ws://localhost:${server.port}"); channel = IOWebSocketChannel(webSocket); link = makeLink(null, channelGenerator: () => channel); + await server.close(); expect( link.request(request).first, throwsA(isA()), @@ -822,7 +838,7 @@ void _testLinks( HttpServer server; WebSocket webSocket; IOWebSocketChannel channel; - Link link; + late Link link; Request request; request = Request( @@ -836,10 +852,16 @@ void _testLinks( server.transform(WebSocketTransformer()); webSocket = await WebSocket.connect("ws://localhost:${server.port}"); - // Close the socket to cause network error. - await webSocket.close(); channel = IOWebSocketChannel(webSocket); - link = makeLink(null, channelGenerator: () => channel); + channel.stream.listen(null, onError: (err) {}); + + await webSocket.close(); + link = makeLink( + null, + channelGenerator: () => channel, + autoReconnect: false, + ); + await server.close(); expect( link.request(request).first, throwsA(isA()), @@ -908,6 +930,8 @@ void _testLinks( channel = IOWebSocketChannel(webSocket); link = makeLink(null, channelGenerator: () => channel); responseSub = link.request(request).listen(print); + + await server.close(); }); test( @@ -1065,7 +1089,7 @@ void _testLinks( ConnectionAck(), ), ); - webSocket.close(websocket_status.goingAway); + webSocket.close(websocket_status.normalClosure); } messageCount++; }, @@ -1079,16 +1103,11 @@ void _testLinks( ), ); - link = makeLink( - null, - channelGenerator: () async { - final webSocket = - await WebSocket.connect("ws://localhost:${server.port}"); - return IOWebSocketChannel(webSocket); - }, - reconnectInterval: Duration(milliseconds: 500), - ); - // + link = makeLink(null, channelGenerator: () async { + final webSocket = + await WebSocket.connect("ws://localhost:${server.port}"); + return IOWebSocketChannel(webSocket); + }, reconnectInterval: Duration(milliseconds: 500), autoReconnect: true); link.request(request).listen(print, onError: print); }, ); @@ -1137,7 +1156,7 @@ void _testLinks( expect(map["type"], startMessageType); subId = map["id"] as String?; // disconnect - webSocket.close(websocket_status.goingAway); + webSocket.close(websocket_status.normalClosure); } messageCount++; },