Skip to content

Commit

Permalink
Remove connection closure
Browse files Browse the repository at this point in the history
  • Loading branch information
ThisaruGuruge committed Jan 27, 2025
1 parent 1f497c2 commit d0d9776
Show file tree
Hide file tree
Showing 11 changed files with 0 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ isolated function testDataLoaderWithSubscription() returns error? {
check common:validateNextMessage(wsClient, expectedMsgPayload, id = "1");
}
assertDispatchCountForBookLoader(5);
common:closeWebsocketClient(wsClient);
}

@test:Config {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,4 @@ function testAttachServiceWithSubscriptionToHttp1BasedListener() returns error?
check common:validateNextMessage(wsClient1, expectedMsgPayload, id = "1");
check common:validateNextMessage(wsClient2, expectedMsgPayload, id = "2");
}
common:closeWebsocketClient(wsClient1);
common:closeWebsocketClient(wsClient2);
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ isolated function testContextWithSubscriptions() returns error? {
json expectedMsgPayload = {data: {messages: i}};
check common:validateNextMessage(wsClient, expectedMsgPayload);
}
common:closeWebsocketClient(wsClient);
}

@test:Config {
Expand All @@ -63,5 +62,4 @@ isolated function testContextWithInvalidScopeInSubscriptions() returns error? {
}
];
check common:validateErrorMessage(wsClient, expectedErrorPayload);
common:closeWebsocketClient(wsClient);
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ isolated function testSubscriptionWithConstraints() returns error? {
check common:sendSubscriptionMessage(wsClient, document, operationName = "Sub");
json expectedMsgPayload = check common:getJsonContentFromFile("constraints_with_subscription");
check common:validateErrorMessage(wsClient, expectedMsgPayload);
common:closeWebsocketClient(wsClient);
}

@test:Config {
Expand All @@ -51,6 +50,4 @@ isolated function testMultipleSubscriptionClientsWithConstraints() returns error
json expectedMsgPayload = check common:getJsonContentFromFile("constraints_with_subscription");
check common:validateErrorMessage(wsClient1, expectedMsgPayload, "1");
check common:validateErrorMessage(wsClient2, expectedMsgPayload, "2");
common:closeWebsocketClient(wsClient1);
common:closeWebsocketClient(wsClient2);
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ isolated function testSubscriptionMultiplexing() returns error? {
json expectedPayload = {'type: common:WS_NEXT, id: subscriptionId, payload: payload};
test:assertEquals(actualPayload, expectedPayload);
}
common:closeWebsocketClient(wsClient);
}

@test:Config {
Expand All @@ -67,7 +66,6 @@ isolated function testInvalidWebSocketRequestWithEmptyQuery() returns error? {
check common:sendSubscriptionMessage(wsClient, document);
json expectedMsgPayload = {errors: [{message: "An empty query is found"}]};
check common:validateErrorMessage(wsClient, expectedMsgPayload);
common:closeWebsocketClient(wsClient);
}

@test:Config {
Expand All @@ -83,7 +81,6 @@ isolated function testInvalidWebSocketRequestWithInvalidQuery() returns error? {
string expectedErrorMsg = "Invalid format: payload does not conform to the format required by the" +
" 'graphql-transport-ws' subprotocol: Status code: 1003";
common:validateConnectionClosureWithError(wsClient, expectedErrorMsg);
common:closeWebsocketClient(wsClient);
}

@test:Config {
Expand All @@ -98,7 +95,6 @@ isolated function testInvalidWebSocketRequestWithoutQuery() returns error? {
string expectedErrorMsg = "Invalid format: payload does not conform to the format required by the" +
" 'graphql-transport-ws' subprotocol: Status code: 1003";
common:validateConnectionClosureWithError(wsClient, expectedErrorMsg);
common:closeWebsocketClient(wsClient);
}

@test:Config {
Expand All @@ -115,7 +111,6 @@ isolated function testInvalidVariableInWebSocketPayload() returns error? {
string expectedErrorMsg = "Invalid format: payload does not conform to the format required by the" +
" 'graphql-transport-ws' subprotocol: Status code: 1003";
common:validateConnectionClosureWithError(wsClient, expectedErrorMsg);
common:closeWebsocketClient(wsClient);
}

@test:Config {
Expand All @@ -130,7 +125,6 @@ isolated function testEmptyWebSocketPayload() returns error? {
string expectedErrorMsg = "Invalid format: payload does not conform to the format required by the" +
" 'graphql-transport-ws' subprotocol: Status code: 1003";
common:validateConnectionClosureWithError(wsClient, expectedErrorMsg);
common:closeWebsocketClient(wsClient);
}

@test:Config {
Expand All @@ -144,5 +138,4 @@ isolated function testInvalidWebSocketPayload() returns error? {
string expectedErrorMsg = "Invalid format: payload does not conform to the format required by the"
+ " 'graphql-transport-ws' subprotocol: Status code: 1003";
common:validateConnectionClosureWithError(wsClient, expectedErrorMsg);
common:closeWebsocketClient(wsClient);
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ isolated function testSubscription() returns error? {
check common:validateNextMessage(wsClient, expectedMsgPayload);
expectedMsgPayload = {data: {name: "Skyler"}};
check common:validateNextMessage(wsClient, expectedMsgPayload);
common:closeWebsocketClient(wsClient);
}

@test:Config {
Expand Down Expand Up @@ -74,8 +73,6 @@ isolated function testSubscriptionsWithMultipleOperations() returns error? {
json actualPayload = check common:getJsonPayloadFromService(httpUrl, document, operationName = "getName");
json expectedPayload = {data: {name: "Walter White"}};
common:assertJsonValuesWithOrder(actualPayload, expectedPayload);
common:closeWebsocketClient(wsClient1);
common:closeWebsocketClient(wsClient2);
}

@test:Config {
Expand All @@ -93,7 +90,6 @@ isolated function testSubscriptionWithRecords() returns error? {
check common:validateNextMessage(wsClient, expectedMsgPayload);
expectedMsgPayload = {data: {books: {name: "A Game of Thrones", author: "George R.R. Martin"}}};
check common:validateNextMessage(wsClient, expectedMsgPayload);
common:closeWebsocketClient(wsClient);
}

@test:Config {
Expand Down Expand Up @@ -122,7 +118,6 @@ isolated function testSubscriptionWithFragments() returns error? {
check common:validateNextMessage(wsClient, expectedMsgPayload);
expectedMsgPayload = {data: {students: {id: 2, name: "Mikasa Ackerman"}}};
check common:validateNextMessage(wsClient, expectedMsgPayload);
common:closeWebsocketClient(wsClient);
}

@test:Config {
Expand All @@ -140,7 +135,6 @@ isolated function testSubscriptionWithUnionType() returns error? {
check common:validateNextMessage(wsClient, expectedMsgPayload);
expectedMsgPayload = {data: {multipleValues: {name: "Walter White", subject: "Chemistry"}}};
check common:validateNextMessage(wsClient, expectedMsgPayload);
common:closeWebsocketClient(wsClient);
}

@test:Config {
Expand All @@ -159,5 +153,4 @@ isolated function testSubscriptionWithVariables() returns error? {
json expectedMsgPayload = {data: {filterValues: i}};
check common:validateNextMessage(wsClient, expectedMsgPayload);
}
common:closeWebsocketClient(wsClient);
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,4 @@ isolated function testConnectionClosureWhenPongNotReceived() returns error? {
}
test:assertTrue(response is error, "Expected connection closure error");
test:assertEquals((<error>response).message(), "Request timeout: Status code: 4408");
common:closeWebsocketClient(wsClient);
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ isolated function testInterceptorsWithSubscriptionReturningScalar() returns erro
check common:validateNextMessage(wsClient1, expectedMsgPayload, id = "1");
check common:validateNextMessage(wsClient2, expectedMsgPayload, id = "2");
}
common:closeWebsocketClient(wsClient1);
common:closeWebsocketClient(wsClient2);
}

@test:Config {
Expand All @@ -62,8 +60,6 @@ isolated function testInterceptorsWithSubscriptionReturningRecord() returns erro
check common:sendSubscriptionMessage(wsClient2, document, operationName = "B");
expectedMsgPayload = {data: {newBooks: {name: "A Game of Thrones", author: "George R.R. Martin"}}};
check common:validateNextMessage(wsClient2, expectedMsgPayload);
common:closeWebsocketClient(wsClient1);
common:closeWebsocketClient(wsClient2);
}

@test:Config {
Expand All @@ -86,8 +82,6 @@ isolated function testInterceptorsWithSubscriptionAndFragments() returns error?
check common:sendSubscriptionMessage(wsClient2, document, operationName = "getNewStudents");
expectedMsgPayload = {data: {newStudents: {id: 4, name: "Ron Weasley"}}};
check common:validateNextMessage(wsClient2, expectedMsgPayload);
common:closeWebsocketClient(wsClient1);
common:closeWebsocketClient(wsClient2);
}

@test:Config {
Expand Down Expand Up @@ -131,8 +125,6 @@ isolated function testInterceptorsWithUnionTypeSubscription() returns error? {
}
};
check common:validateNextMessage(wsClient2, expectedMsgPayload);
common:closeWebsocketClient(wsClient1);
common:closeWebsocketClient(wsClient2);
}

@test:Config {
Expand All @@ -155,8 +147,6 @@ isolated function testInterceptorsReturnBeforeResolverWithSubscription() returns
check common:validateNextMessage(wsClient1, expectedMsgPayload, id = "1");
check common:validateNextMessage(wsClient2, expectedMsgPayload, id = "2");
}
common:closeWebsocketClient(wsClient1);
common:closeWebsocketClient(wsClient2);
}

@test:Config {
Expand Down Expand Up @@ -205,8 +195,6 @@ isolated function testInterceptorsDestructiveModificationWithSubscription() retu
check common:validateNextMessage(wsClient1, expectedMsgPayload, id = "1");
check common:validateNextMessage(wsClient2, expectedMsgPayload, id = "2");
}
common:closeWebsocketClient(wsClient1);
common:closeWebsocketClient(wsClient2);
}

@test:Config {
Expand Down Expand Up @@ -246,9 +234,6 @@ isolated function testInterceptorsWithSubscribersRunSimultaniously1() returns er
}
check wait A;
check wait B;
common:closeWebsocketClient(wsClient1);
common:closeWebsocketClient(wsClient2);
common:closeWebsocketClient(wsClient3);
}

@test:Config {
Expand Down Expand Up @@ -308,6 +293,4 @@ isolated function testInterceptorsWithSubscribersRunSimultaniously2() returns er
}
check wait A;
check wait B;
common:closeWebsocketClient(wsClient1);
common:closeWebsocketClient(wsClient2);
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ function testAlreadyExistingSubscriber() returns error? {
}
}
test:assertEquals((<error>response).message(), expectedErrorMsg);
common:closeWebsocketClient(wsClient);
}

@test:Config {
Expand All @@ -61,7 +60,6 @@ isolated function testOnPing() returns error? {
check wsClient->writeMessage({'type: common:WS_PING});
json response = check wsClient->readMessage();
test:assertEquals(response.'type, common:WS_PONG);
common:closeWebsocketClient(wsClient);
}

@test:Config {
Expand Down Expand Up @@ -94,7 +92,6 @@ isolated function testErrorsInStreams() returns error? {
check common:validateNextMessage(wsClient, expectedMsgPayload);
expectedMsgPayload = {data: {evenNumber: 6}};
check common:validateNextMessage(wsClient, expectedMsgPayload);
common:closeWebsocketClient(wsClient);
}

@test:Config {
Expand All @@ -120,7 +117,6 @@ isolated function testMultipleSubscriptionUsingSingleClient() returns error? {
check common:validateNextMessage(wsClient, expectedMsgPayload, id = "2");
}
check common:validateCompleteMessage(wsClient, id = "2");
common:closeWebsocketClient(wsClient);
}

@test:Config {
Expand All @@ -137,7 +133,6 @@ isolated function testSubscriptionWithInvalidPayload() returns error? {
string expectedErrorMsg = "Invalid format: payload does not conform to the format required by the" +
" 'graphql-transport-ws' subprotocol: Status code: 1003";
common:validateConnectionClosureWithError(wsClient, expectedErrorMsg);
common:closeWebsocketClient(wsClient);
}

@test:Config {
Expand All @@ -153,7 +148,6 @@ isolated function testResolverReturingStreamOfRecordsWithServiceObjects() return

json expectedPayload = {data: {live: {product: {id: "1"}, score: 20}}};
check common:validateNextMessage(wsClient, expectedPayload);
common:closeWebsocketClient(wsClient);
}

@test:Config {
Expand All @@ -171,5 +165,4 @@ isolated function testResolverReturingStreamOfRecordsWithMapOfServiceObjects() r
check common:validateNextMessage(wsClient, expectedMsgPayload);
expectedMsgPayload = {data: {accountUpdates: {details: {name: "James Deen"}}}};
check common:validateNextMessage(wsClient, expectedMsgPayload);
common:closeWebsocketClient(wsClient);
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ isolated function testSubscriptionWithIntrospectionInFields() returns error? {

json expectedMsgPayload = {data: {students: {__typename: "StudentService"}}};
check common:validateNextMessage(wsClient, expectedMsgPayload);
common:closeWebsocketClient(wsClient);
}

@test:Config {
Expand All @@ -47,7 +46,6 @@ isolated function testInvalidSubscription() returns error? {

json expectedMsgPayload = check common:getJsonContentFromFile("subscription_invalid_field");
check common:validateErrorMessage(wsClient, expectedMsgPayload);
common:closeWebsocketClient(wsClient);
}

@test:Config {
Expand All @@ -69,7 +67,6 @@ isolated function testSubscriptionFunctionWithErrors() returns error? {
}
];
check common:validateErrorMessage(wsClient, expectedErrorPayload);
common:closeWebsocketClient(wsClient);
}

@test:Config {
Expand All @@ -88,7 +85,6 @@ isolated function testSubscriptionWithServiceObjects() returns error? {
expectedMsgPayload = {data: {students: {id: 2, name: "Mikasa Ackerman"}}};
check common:validateNextMessage(wsClient, expectedMsgPayload);
check common:validateCompleteMessage(wsClient);
common:closeWebsocketClient(wsClient);
}

@test:Config {
Expand All @@ -114,8 +110,6 @@ isolated function testSubscriptionWithMultipleClients() returns error? {
}
check common:validateCompleteMessage(wsClient1, id = "1");
check common:validateCompleteMessage(wsClient2, id = "2");
common:closeWebsocketClient(wsClient1);
common:closeWebsocketClient(wsClient2);
}

@test:Config {
Expand All @@ -127,7 +121,6 @@ isolated function testConnectionInitMessage() returns error? {
websocket:Client wsClient = check new (url, config);
check common:sendConnectionInitMessage(wsClient);
check common:validateConnectionAckMessage(wsClient);
common:closeWebsocketClient(wsClient);
}

@test:Config {
Expand All @@ -142,7 +135,6 @@ isolated function testInvalidMultipleConnectionInitMessages() returns error? {

string expectedErrorMsg = "Too many initialisation requests: Status code: 4429";
common:validateConnectionClosureWithError(wsClient, expectedErrorMsg);
common:closeWebsocketClient(wsClient);
}

@test:Config {
Expand All @@ -157,5 +149,4 @@ isolated function testUnauthorizedAccess() returns error? {

string expectedErrorMsg = "Unauthorized: Status code: 4401";
common:validateConnectionClosureWithError(wsClient, expectedErrorMsg);
common:closeWebsocketClient(wsClient);
}
13 changes: 0 additions & 13 deletions ballerina-tests/graphql-test-common/utils.bal
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import ballerina/file;
import ballerina/graphql;
import ballerina/http;
import ballerina/io;
import ballerina/log;
import ballerina/test;
import ballerina/websocket;

Expand Down Expand Up @@ -179,15 +178,3 @@ public isolated function validateConnectionClosureWithError(websocket:Client wsC
}
test:assertFail(string `Unexpected Error found : ${response.toString()}`);
}

public isolated function closeWebsocketClient(websocket:Client wsClient) {
string id = wsClient.getConnectionId();
error? result = wsClient->writeMessage({'type: WS_COMPLETE, id});
if result is error {
log:printError("Error occurred while sending the complete message: ", result);
}
result = wsClient->close(timeout = 1);
if result is error {
log:printError("Error occurred while closing the websocket client: ", result);
}
}

0 comments on commit d0d9776

Please sign in to comment.