Skip to content

Commit

Permalink
fix(ci): graphql coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
micimize committed Mar 6, 2021
1 parent aa5373c commit d47852a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Expand Up @@ -184,7 +184,7 @@ workflows:
nightly:
triggers:
- schedule:
cron: "0 * * * *"
cron: "38 * * * *"
filters:
branches:
only:
Expand Down
Expand Up @@ -261,6 +261,7 @@ class SocketClient {
}

void onConnectionLost([e]) {
socketChannel?.sink?.close(ws_status.goingAway);
if (e != null) {
print('There was an error causing connection lost: $e');
}
Expand All @@ -284,7 +285,8 @@ class SocketClient {
if (config.autoReconnect && !_connectionStateController.isClosed) {
if (config.delayBetweenReconnectionAttempts != null) {
print(
'Scheduling to connect in ${config.delayBetweenReconnectionAttempts.inSeconds} seconds...');
'Scheduling to connect in ${config.delayBetweenReconnectionAttempts.inSeconds} seconds...',
);

_reconnectTimer = Timer(
config.delayBetweenReconnectionAttempts,
Expand All @@ -309,10 +311,9 @@ class SocketClient {
_reconnectTimer?.cancel();

await Future.wait([
socketChannel.sink.close(ws_status.goingAway),
socketChannel?.sink?.close(ws_status.goingAway),
_messageSubscription?.cancel(),
_connectionStateController?.close(),
_keepAliveSubscription?.cancel()
].where((future) => future != null).toList());
}

Expand Down
45 changes: 25 additions & 20 deletions packages/graphql/test/websocket_test.dart
Expand Up @@ -32,9 +32,7 @@ class EchoSink extends DelegatingStreamSink implements WebSocketSink {
class EchoSocket implements WebSocketChannel {
final StreamController controller;

EchoSocket.connect(BehaviorSubject controller)
: controller = controller,
sink = EchoSink(controller.sink);
EchoSocket.connect(this.controller) : sink = EchoSink(controller.sink);

@override
Stream get stream => controller.stream;
Expand Down Expand Up @@ -88,6 +86,18 @@ class EchoSocket implements WebSocketChannel {
throw UnimplementedError();
}

SocketClient getTestClient([StreamController controller]) => SocketClient(
'ws://echo.websocket.org',
connect: (_, __) => EchoSocket.connect(controller ?? BehaviorSubject()),
protocols: null,
config: SocketClientConfig(
delayBetweenReconnectionAttempts: Duration(milliseconds: 1),
),
randomBytesForUuid: Uint8List.fromList(
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16],
),
);

void main() {
group('InitOperation', () {
test('null payload', () {
Expand Down Expand Up @@ -124,26 +134,18 @@ void main() {

group('SocketClient without payload', () {
SocketClient socketClient;
StreamController controller;
final expectedMessage = r'{'
r'"type":"start","id":"01020304-0506-4708-890a-0b0c0d0e0f10",'
r'"payload":{"operationName":null,"variables":{},"query":"subscription {\n \n}"}'
r'}';
setUp(overridePrint((log) {
socketClient = SocketClient(
'ws://echo.websocket.org',
connect: (_, __) => EchoSocket.connect(BehaviorSubject()),
protocols: null,
config: SocketClientConfig(
delayBetweenReconnectionAttempts: Duration(milliseconds: 1),
),
randomBytesForUuid: Uint8List.fromList(
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16],
),
);
}));
tearDown(overridePrint((log) async {
await socketClient.dispose();
controller = StreamController(sync: true);
socketClient = getTestClient(controller);
}));
tearDown(overridePrint(
(log) => socketClient.dispose(),
));
test('connection', () async {
await expectLater(
socketClient.connectionState.asBroadcastStream(),
Expand Down Expand Up @@ -269,9 +271,12 @@ void main() {
);
}));

tearDown(overridePrint((log) async {
await socketClient.dispose();
}));
tearDown(overridePrint(
(log) => expectLater(
socketClient.dispose().timeout(Duration(seconds: 1)),
completion(null),
),
));

test('connection', () async {
await socketClient.connectionState
Expand Down

0 comments on commit d47852a

Please sign in to comment.