From 67dd77b567879be7a2b599549ab4663d95657ca5 Mon Sep 17 00:00:00 2001 From: Thisaru Guruge Date: Mon, 10 Mar 2025 22:37:44 +0530 Subject: [PATCH] Enable subscription tests --- ballerina-tests/tests/01_listener_test.bal | 3 +- .../tests/02_request_validation.bal | 18 ++--- ballerina-tests/tests/27_context.bal | 3 +- ballerina-tests/tests/34_graphiql_client.bal | 3 +- ballerina-tests/tests/36_subscriptions.bal | 78 +++++++------------ ballerina-tests/tests/38_interceptors.bal | 24 ++---- ballerina-tests/tests/41_dataloader.bal | 6 +- .../tests/42_constraint_validation.bal | 6 +- ballerina/websocket_utils.bal | 8 +- 9 files changed, 50 insertions(+), 99 deletions(-) diff --git a/ballerina-tests/tests/01_listener_test.bal b/ballerina-tests/tests/01_listener_test.bal index 0a53fc976..cafa718ce 100644 --- a/ballerina-tests/tests/01_listener_test.bal +++ b/ballerina-tests/tests/01_listener_test.bal @@ -124,8 +124,7 @@ function testAttachServiceWithMutationToHttp1BasedListenerAndClient() returns er } @test:Config { - groups: ["listener", "subscriptions"], - enable: false + groups: ["listener", "subscriptions"] } function testAttachServiceWithSubscriptionToHttp1BasedListener() returns error? { string document = string `subscription { messages }`; diff --git a/ballerina-tests/tests/02_request_validation.bal b/ballerina-tests/tests/02_request_validation.bal index c1ea767e7..83dd12495 100644 --- a/ballerina-tests/tests/02_request_validation.bal +++ b/ballerina-tests/tests/02_request_validation.bal @@ -147,8 +147,7 @@ isolated function testInvalidRequestBody() returns error? { } @test:Config { - groups: ["request_validation", "websocket", "subscriptions"], - enable: false + groups: ["request_validation", "websocket", "subscriptions"] } isolated function testInvalidWebSocketRequestWithEmptyQuery() returns error? { string document = ""; @@ -162,8 +161,7 @@ isolated function testInvalidWebSocketRequestWithEmptyQuery() returns error? { } @test:Config { - groups: ["request_validation", "websocket", "subscriptions"], - enable: false + groups: ["request_validation", "websocket", "subscriptions"] } isolated function testInvalidWebSocketRequestWithInvalidQuery() returns error? { string url = "ws://localhost:9099/subscriptions"; @@ -178,8 +176,7 @@ isolated function testInvalidWebSocketRequestWithInvalidQuery() returns error? { } @test:Config { - groups: ["request_validation", "websocket", "subscriptions"], - enable: false + groups: ["request_validation", "websocket", "subscriptions"] } isolated function testInvalidWebSocketRequestWithoutQuery() returns error? { string url = "ws://localhost:9099/subscriptions"; @@ -193,8 +190,7 @@ isolated function testInvalidWebSocketRequestWithoutQuery() returns error? { } @test:Config { - groups: ["request_validation", "websocket", "subscriptions"], - enable: false + groups: ["request_validation", "websocket", "subscriptions"] } isolated function testInvalidVariableInWebSocketPayload() returns error? { string document = check getGraphqlDocumentFromFile("subscriptions_with_variable_values"); @@ -210,8 +206,7 @@ isolated function testInvalidVariableInWebSocketPayload() returns error? { } @test:Config { - groups: ["request_validation", "websocket", "subscriptions"], - enable: false + groups: ["request_validation", "websocket", "subscriptions"] } isolated function testEmptyWebSocketPayload() returns error? { string url = "ws://localhost:9099/subscriptions"; @@ -225,8 +220,7 @@ isolated function testEmptyWebSocketPayload() returns error? { } @test:Config { - groups: ["request_validation", "websocket", "subscriptions"], - enable: false + groups: ["request_validation", "websocket", "subscriptions"] } isolated function testInvalidWebSocketPayload() returns error? { string url = "ws://localhost:9099/subscriptions"; diff --git a/ballerina-tests/tests/27_context.bal b/ballerina-tests/tests/27_context.bal index 93b1d6e00..6336f1a6c 100644 --- a/ballerina-tests/tests/27_context.bal +++ b/ballerina-tests/tests/27_context.bal @@ -317,8 +317,7 @@ isolated function testContextWithSubscriptions() returns error? { } @test:Config { - groups: ["context", "subscriptions"], - enable: false + groups: ["context", "subscriptions"] } isolated function testContextWithInvalidScopeInSubscriptions() returns error? { string url = "ws://localhost:9092/context"; diff --git a/ballerina-tests/tests/34_graphiql_client.bal b/ballerina-tests/tests/34_graphiql_client.bal index 11f1273d9..f5ffbd4e6 100644 --- a/ballerina-tests/tests/34_graphiql_client.bal +++ b/ballerina-tests/tests/34_graphiql_client.bal @@ -19,8 +19,7 @@ import ballerina/http; import ballerina/test; @test:Config { - groups: ["listener", "graphiql"], - enable: false + groups: ["listener", "graphiql"] } function testGraphiqlWithSamePathAsGraphQLService() returns error? { graphql:Error? result = basicListener.attach(graphiqlConfigService, "ballerina/graphiql"); diff --git a/ballerina-tests/tests/36_subscriptions.bal b/ballerina-tests/tests/36_subscriptions.bal index 3712fbf8c..4a2731f57 100644 --- a/ballerina-tests/tests/36_subscriptions.bal +++ b/ballerina-tests/tests/36_subscriptions.bal @@ -18,8 +18,7 @@ import ballerina/test; import ballerina/websocket; @test:Config { - groups: ["subscriptions"], - enable: false + groups: ["subscriptions"] } isolated function testSubscription() returns error? { string document = string `subscription { name }`; @@ -36,8 +35,7 @@ isolated function testSubscription() returns error? { } @test:Config { - groups: ["subscriptions"], - enable: false + groups: ["subscriptions"] } isolated function testSubscriptionWithoutSubProtocol() returns error? { string url = "ws://localhost:9099/subscriptions"; @@ -48,8 +46,7 @@ isolated function testSubscriptionWithoutSubProtocol() returns error? { } @test:Config { - groups: ["subscriptions"], - enable: false + groups: ["subscriptions"] } isolated function testSubscriptionsWithMultipleOperations() returns error? { string document = check getGraphqlDocumentFromFile("subscriptions_with_multiple_operations"); @@ -78,8 +75,7 @@ isolated function testSubscriptionsWithMultipleOperations() returns error? { } @test:Config { - groups: ["records", "subscriptions"], - enable: false + groups: ["records", "subscriptions"] } isolated function testSubscriptionWithRecords() returns error? { string document = check getGraphqlDocumentFromFile("subscriptions_with_records"); @@ -96,8 +92,7 @@ isolated function testSubscriptionWithRecords() returns error? { } @test:Config { - groups: ["subscriptions"], - enable: false + groups: ["subscriptions"] } isolated function testQueryWithSameSubscriptionFieldName() returns error? { string document = string `query { name }`; @@ -108,8 +103,7 @@ isolated function testQueryWithSameSubscriptionFieldName() returns error? { } @test:Config { - groups: ["fragments", "subscriptions"], - enable: false + groups: ["fragments", "subscriptions"] } isolated function testSubscriptionWithFragments() returns error? { string document = check getGraphqlDocumentFromFile("subscriptions_with_fragments"); @@ -126,8 +120,7 @@ isolated function testSubscriptionWithFragments() returns error? { } @test:Config { - groups: ["union", "subscriptions"], - enable: false + groups: ["union", "subscriptions"] } isolated function testSubscriptionWithUnionType() returns error? { string document = check getGraphqlDocumentFromFile("subscriptions_with_union_type"); @@ -144,8 +137,7 @@ isolated function testSubscriptionWithUnionType() returns error? { } @test:Config { - groups: ["variables", "subscriptions"], - enable: false + groups: ["variables", "subscriptions"] } isolated function testSubscriptionWithVariables() returns error? { string document = check getGraphqlDocumentFromFile("subscriptions_with_variable_values"); @@ -163,8 +155,7 @@ isolated function testSubscriptionWithVariables() returns error? { } @test:Config { - groups: ["introspection", "typename", "subscriptions"], - enable: false + groups: ["introspection", "typename", "subscriptions"] } isolated function testSubscriptionWithIntrospectionInFields() returns error? { string document = string `subscription { students { __typename } }`; @@ -179,8 +170,7 @@ isolated function testSubscriptionWithIntrospectionInFields() returns error? { } @test:Config { - groups: ["subscriptions"], - enable: false + groups: ["subscriptions"] } isolated function testInvalidSubscription() returns error? { string document = string `subscription { invalidField }`; @@ -195,8 +185,7 @@ isolated function testInvalidSubscription() returns error? { } @test:Config { - groups: ["subscriptions"], - enable: false + groups: ["subscriptions"] } isolated function testSubscriptionFunctionWithErrors() returns error? { string document = string `subscription getNames { values }`; @@ -217,8 +206,7 @@ isolated function testSubscriptionFunctionWithErrors() returns error? { } @test:Config { - groups: ["service", "subscriptions"], - enable: false + groups: ["service", "subscriptions"] } isolated function testSubscriptionWithServiceObjects() returns error? { string document = check getGraphqlDocumentFromFile("subscriptions_with_service_objects"); @@ -236,8 +224,7 @@ isolated function testSubscriptionWithServiceObjects() returns error? { } @test:Config { - groups: ["subscriptions"], - enable: false + groups: ["subscriptions"] } isolated function testSubscriptionWithMultipleClients() returns error? { string document = string `subscription { messages }`; @@ -262,8 +249,7 @@ isolated function testSubscriptionWithMultipleClients() returns error? { } @test:Config { - groups: ["subscriptions"], - enable: false + groups: ["subscriptions"] } isolated function testConnectionInitMessage() returns error? { string url = "ws://localhost:9099/subscriptions"; @@ -274,8 +260,7 @@ isolated function testConnectionInitMessage() returns error? { } @test:Config { - groups: ["subscriptions"], - enable: false + groups: ["subscriptions"] } isolated function testInvalidMultipleConnectionInitMessages() returns error? { string url = "ws://localhost:9099/subscriptions"; @@ -289,8 +274,7 @@ isolated function testInvalidMultipleConnectionInitMessages() returns error? { } @test:Config { - groups: ["subscriptions"], - enable: false + groups: ["subscriptions"] } isolated function testUnauthorizedAccess() returns error? { string document = check getGraphqlDocumentFromFile("subscriptions_with_service_objects"); @@ -304,8 +288,7 @@ isolated function testUnauthorizedAccess() returns error? { } @test:Config { - groups: ["subscriptions"], - enable: false + groups: ["subscriptions"] } function testAlreadyExistingSubscriber() returns error? { string document = check getGraphqlDocumentFromFile("subscriptions_with_service_objects"); @@ -337,8 +320,7 @@ function testAlreadyExistingSubscriber() returns error? { } @test:Config { - groups: ["subscriptions"], - enable: false + groups: ["subscriptions"] } isolated function testOnPing() returns error? { string url = "ws://localhost:9099/subscriptions"; @@ -350,8 +332,7 @@ isolated function testOnPing() returns error? { } @test:Config { - groups: ["subscriptions"], - enable: false + groups: ["subscriptions"] } isolated function testInvalidSubProtocolInSubscriptions() returns error? { string url = "ws://localhost:9099/subscriptions"; @@ -365,8 +346,7 @@ isolated function testInvalidSubProtocolInSubscriptions() returns error? { } @test:Config { - groups: ["subscriptions", "runtime_errors"], - enable: false + groups: ["subscriptions", "runtime_errors"] } isolated function testErrorsInStreams() returns error? { string document = "subscription { evenNumber }"; @@ -385,8 +365,7 @@ isolated function testErrorsInStreams() returns error? { } @test:Config { - groups: ["subscriptions"], - enable: false + groups: ["subscriptions"] } isolated function testMultipleSubscriptionUsingSingleClient() returns error? { string document = string `subscription { messages }`; @@ -411,8 +390,7 @@ isolated function testMultipleSubscriptionUsingSingleClient() returns error? { } @test:Config { - groups: ["subscriptions"], - enable: false + groups: ["subscriptions"] } isolated function testSubscriptionWithInvalidPayload() returns error? { string url = "ws://localhost:9099/subscriptions"; @@ -428,8 +406,7 @@ isolated function testSubscriptionWithInvalidPayload() returns error? { } @test:Config { - groups: ["subscriptions", "records", "service"], - enable: false + groups: ["subscriptions", "records", "service"] } isolated function testResolverReturingStreamOfRecordsWithServiceObjects() returns error? { string document = "subscription { live { product { id } score } }"; @@ -444,8 +421,7 @@ isolated function testResolverReturingStreamOfRecordsWithServiceObjects() return } @test:Config { - groups: ["subscriptions", "records", "service", "maps"], - enable: false + groups: ["subscriptions", "records", "service", "maps"] } isolated function testResolverReturingStreamOfRecordsWithMapOfServiceObjects() returns error? { string document = string `subscription { accountUpdates { details(key: "acc1") { name } } }`; @@ -462,8 +438,7 @@ isolated function testResolverReturingStreamOfRecordsWithMapOfServiceObjects() r } @test:Config { - groups: ["subscriptions", "multiplexing"], - enable: false + groups: ["subscriptions", "multiplexing"] } isolated function testSubscriptionMultiplexing() returns error? { string document = string `subscription { refresh }`; @@ -498,8 +473,7 @@ isolated function testSubscriptionMultiplexing() returns error? { } @test:Config { - groups: ["subscriptions", "records", "service"], - enable: false + groups: ["subscriptions", "records", "service"] } isolated function testConnectionClousureWhenPongNotRecived() returns error? { string url = "ws://localhost:9090/reviews"; diff --git a/ballerina-tests/tests/38_interceptors.bal b/ballerina-tests/tests/38_interceptors.bal index 33ed11323..661133ab7 100644 --- a/ballerina-tests/tests/38_interceptors.bal +++ b/ballerina-tests/tests/38_interceptors.bal @@ -91,8 +91,7 @@ function dataProviderInterceptors() returns string[][] { } @test:Config { - groups: ["interceptors", "subscriptions"], - enable: false + groups: ["interceptors", "subscriptions"] } isolated function testInterceptorsWithSubscriptionReturningScalar() returns error? { string document = string `subscription { messages }`; @@ -114,8 +113,7 @@ isolated function testInterceptorsWithSubscriptionReturningScalar() returns erro } @test:Config { - groups: ["interceptors", "subscriptions", "records"], - enable: false + groups: ["interceptors", "subscriptions", "records"] } isolated function testInterceptorsWithSubscriptionReturningRecord() returns error? { string document = check getGraphqlDocumentFromFile("interceptors_with_subscription_return_records"); @@ -137,8 +135,7 @@ isolated function testInterceptorsWithSubscriptionReturningRecord() returns erro } @test:Config { - groups: ["interceptors", "fragments", "subscriptions"], - enable: false + groups: ["interceptors", "fragments", "subscriptions"] } isolated function testInterceptorsWithSubscriptionAndFragments() returns error? { string document = check getGraphqlDocumentFromFile("interceptors_with_fragments_and_subscription"); @@ -160,8 +157,7 @@ isolated function testInterceptorsWithSubscriptionAndFragments() returns error? } @test:Config { - groups: ["interceptors", "union", "subscriptions"], - enable: false + groups: ["interceptors", "union", "subscriptions"] } isolated function testInterceptorsWithUnionTypeSubscription() returns error? { string document = check getGraphqlDocumentFromFile("interceptors_with_subscription_return_union_type"); @@ -204,8 +200,7 @@ isolated function testInterceptorsWithUnionTypeSubscription() returns error? { } @test:Config { - groups: ["interceptors", "subscriptions"], - enable: false + groups: ["interceptors", "subscriptions"] } isolated function testInterceptorsReturnBeforeResolverWithSubscription() returns error? { string document = string `subscription { messages }`; @@ -227,8 +222,7 @@ isolated function testInterceptorsReturnBeforeResolverWithSubscription() returns } @test:Config { - groups: ["interceptors", "subscriptions"], - enable: false + groups: ["interceptors", "subscriptions"] } isolated function testInterceptorsDestructiveModificationWithSubscription() returns error? { string document = string `subscription { messages }`; @@ -276,8 +270,7 @@ isolated function testInterceptorsDestructiveModificationWithSubscription() retu } @test:Config { - groups: ["interceptors", "subscriptions"], - enable: false + groups: ["interceptors", "subscriptions"] } isolated function testInterceptorsWithSubscribersRunSimultaniously1() returns error? { final string document = string `subscription { messages }`; @@ -316,8 +309,7 @@ isolated function testInterceptorsWithSubscribersRunSimultaniously1() returns er } @test:Config { - groups: ["interceptors", "union", "subscriptions"], - enable: false + groups: ["interceptors", "union", "subscriptions"] } isolated function testInterceptorsWithSubscribersRunSimultaniously2() returns error? { final string document = check getGraphqlDocumentFromFile("interceptors_with_subscription_return_union_type"); diff --git a/ballerina-tests/tests/41_dataloader.bal b/ballerina-tests/tests/41_dataloader.bal index 22ecbda3c..f567675ed 100644 --- a/ballerina-tests/tests/41_dataloader.bal +++ b/ballerina-tests/tests/41_dataloader.bal @@ -48,8 +48,7 @@ isolated function testDataLoaderWithDifferentAliasForSameField() returns error? @test:Config { groups: ["dataloader", "subscription"], - after: resetDispatchCounters, - enable: false + after: resetDispatchCounters } isolated function testDataLoaderWithSubscription() returns error? { string document = check getGraphqlDocumentFromFile("dataloader_with_subscription"); @@ -68,8 +67,7 @@ isolated function testDataLoaderWithSubscription() returns error? { @test:Config { groups: ["dataloader", "mutation"], dependsOn: [testDataLoaderWithQuery, testDataLoaderWithSubscription], - after: resetDispatchCounters, - enable: false + after: resetDispatchCounters } isolated function testDataLoaderWithMutation() returns error? { graphql:Client graphqlClient = check new ("localhost:9090/dataloader"); diff --git a/ballerina-tests/tests/42_constraint_validation.bal b/ballerina-tests/tests/42_constraint_validation.bal index 459eb0c77..e5741e670 100644 --- a/ballerina-tests/tests/42_constraint_validation.bal +++ b/ballerina-tests/tests/42_constraint_validation.bal @@ -64,8 +64,7 @@ function dataProviderConstraintValidation() returns map<[string, string, string, } @test:Config { - groups: ["constraints", "subscriptions"], - enable: false + groups: ["constraints", "subscriptions"] } isolated function testSubscriptionWithConstraints() returns error? { string document = check getGraphqlDocumentFromFile("constraints"); @@ -79,8 +78,7 @@ isolated function testSubscriptionWithConstraints() returns error? { } @test:Config { - groups: ["constraints", "subscriptions"], - enable: false + groups: ["constraints", "subscriptions"] } isolated function testMultipleSubscriptionClientsWithConstraints() returns error? { string document = check getGraphqlDocumentFromFile("constraints"); diff --git a/ballerina/websocket_utils.bal b/ballerina/websocket_utils.bal index e0105115a..ef245236d 100644 --- a/ballerina/websocket_utils.bal +++ b/ballerina/websocket_utils.bal @@ -143,10 +143,8 @@ isolated function logError(string message, error cause) { } isolated function writeMessage(websocket:Caller caller, OutboundMessage message) returns websocket:Error? { - lock { - if !caller.isOpen() { - return; - } - check caller->writeMessage(message); + if !caller.isOpen() { + return; } + check caller->writeMessage(message); }