Skip to content

Commit

Permalink
Merge pull request #2114 from MohamedSabthar/subscription-disable
Browse files Browse the repository at this point in the history
Add print statements in dataloader tests
  • Loading branch information
MohamedSabthar authored Dec 9, 2024
2 parents 26c2874 + 96f6887 commit 87157c7
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ dependencies = [
{org = "ballerina", name = "graphql"},
{org = "ballerina", name = "graphql_test_common"},
{org = "ballerina", name = "http"},
{org = "ballerina", name = "io"},
{org = "ballerina", name = "test"},
{org = "ballerina", name = "websocket"}
]
Expand Down Expand Up @@ -181,6 +182,9 @@ dependencies = [
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "lang.value"}
]
modules = [
{org = "ballerina", packageName = "io", moduleName = "io"}
]

[[package]]
org = "ballerina"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,33 +18,38 @@ import ballerina/graphql;
import ballerina/graphql_test_common as common;
import ballerina/test;
import ballerina/websocket;
import ballerina/io;

@test:Config {
groups: ["dataloader", "query"],
after: resetDispatchCounters
}
isolated function testDataLoaderWithQuery() returns error? {
io:println("start testDataLoaderWithQuery");
graphql:Client graphqlClient = check new ("localhost:9090/dataloader");
string document = check common:getGraphqlDocumentFromFile("dataloader_with_query");
json response = check graphqlClient->execute(document);
json expectedPayload = check common:getJsonContentFromFile("dataloader_with_query");
common:assertJsonValuesWithOrder(response, expectedPayload);
assertDispatchCountForAuthorLoader(1);
assertDispatchCountForBookLoader(1);
io:println("end testDataLoaderWithQuery");
}

@test:Config {
groups: ["dataloader", "query"],
after: resetDispatchCounters
}
isolated function testDataLoaderWithDifferentAliasForSameField() returns error? {
io:println("start testDataLoaderWithDifferentAliasForSameField");
graphql:Client graphqlClient = check new ("localhost:9090/dataloader");
string document = check common:getGraphqlDocumentFromFile("dataloader_with_different_alias_for_same_field");
json response = check graphqlClient->execute(document);
json expectedPayload = check common:getJsonContentFromFile("dataloader_with_different_alias_for_same_field");
common:assertJsonValuesWithOrder(response, expectedPayload);
assertDispatchCountForAuthorLoader(1);
assertDispatchCountForBookLoader(1);
io:println("end testDataLoaderWithDifferentAliasForSameField");
}

@test:Config {
Expand Down Expand Up @@ -75,51 +80,59 @@ isolated function testDataLoaderWithSubscription() returns error? {
after: resetDispatchCounters
}
isolated function testDataLoaderWithMutation() returns error? {
io:println("start testDataLoaderWithMutation");
graphql:Client graphqlClient = check new ("localhost:9090/dataloader");
string document = check common:getGraphqlDocumentFromFile("dataloader_with_mutation");
json response = check graphqlClient->execute(document);
json expectedPayload = check common:getJsonContentFromFile("dataloader_with_mutation");
common:assertJsonValuesWithOrder(response, expectedPayload);
assertDispatchCountForUpdateAuthorLoader(1);
assertDispatchCountForBookLoader(1);
io:println("end testDataLoaderWithMutation");
}

@test:Config {
groups: ["dataloader", "interceptor"],
after: resetDispatchCounters
}
isolated function testDataLoaderWithInterceptors() returns error? {
io:println("start testDataLoaderWithInterceptors");
graphql:Client graphqlClient = check new ("localhost:9090/dataloader_with_interceptor");
string document = check common:getGraphqlDocumentFromFile("dataloader_with_interceptor");
json response = check graphqlClient->execute(document);
json expectedPayload = check common:getJsonContentFromFile("dataloader_with_interceptor");
common:assertJsonValuesWithOrder(response, expectedPayload);
assertDispatchCountForAuthorLoader(1);
assertDispatchCountForBookLoader(1);
io:println("end testDataLoaderWithInterceptors");
}

@test:Config {
groups: ["dataloader", "dispatch-error"],
after: resetDispatchCounters
}
isolated function testBatchFunctionReturningErrors() returns error? {
io:println("start testBatchFunctionReturningErrors");
graphql:Client graphqlClient = check new ("localhost:9090/dataloader");
string document = check common:getGraphqlDocumentFromFile("batch_function_returing_errors");
json response = check graphqlClient->execute(document);
json expectedPayload = check common:getJsonContentFromFile("batch_function_returing_errors");
common:assertJsonValuesWithOrder(response, expectedPayload);
assertDispatchCountForAuthorLoader(1);
assertDispatchCountForBookLoader(0);
io:println("end testBatchFunctionReturningErrors");
}

@test:Config {
groups: ["dataloader", "dispatch-error"],
after: resetDispatchCounters
}
isolated function testBatchFunctionReturingNonMatchingNumberOfResults() returns error? {
io:println("start testBatchFunctionReturingNonMatchingNumberOfResults");
graphql:Client graphqlClient = check new ("localhost:9090/dataloader_with_faulty_batch_function");
string document = check common:getGraphqlDocumentFromFile("batch_function_returning_non_matcing_number_of_results");
json response = check graphqlClient->execute(document);
json expectedPayload = check common:getJsonContentFromFile("batch_function_returning_non_matcing_number_of_results");
common:assertJsonValuesWithOrder(response, expectedPayload);
io:println("end testBatchFunctionReturingNonMatchingNumberOfResults");
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@

import ballerina/graphql_test_common as common;
import ballerina/test;
import ballerina/io;

@test:Config {
groups: ["server_cache", "data_loader"],
groups: ["server_cache", "dataloader"],
dataProvider: dataProviderServerCacheWithDataloader
}
isolated function testServerSideCacheWithDataLoader(string documentFile, string[] resourceFileNames, json variables = (), string[] operationNames = []) returns error? {
io:println("start testServerSideCacheWithDataLoader");
string url = "http://localhost:9090/caching_with_dataloader";
string document = check common:getGraphqlDocumentFromFile(documentFile);
foreach int i in 0 ..< resourceFileNames.length() {
Expand All @@ -30,6 +32,7 @@ isolated function testServerSideCacheWithDataLoader(string documentFile, string[
common:assertJsonValuesWithOrder(actualPayload, expectedPayload);
}
resetDispatchCounters();
io:println("end testServerSideCacheWithDataLoader");
}

function dataProviderServerCacheWithDataloader() returns map<[string, string[], json, string[]]> {
Expand All @@ -41,10 +44,11 @@ function dataProviderServerCacheWithDataloader() returns map<[string, string[],
}

@test:Config {
groups: ["server_cache", "data_loader"],
groups: ["server_cache", "dataloader"],
dataProvider: dataProviderServerCacheWithDataloaderInOperationalLevel
}
isolated function testServerSideCacheWithDataLoaderInOperationalLevel(string documentFile, string[] resourceFileNames, json variables = (), string[] operationNames = []) returns error? {
io:println("start testServerSideCacheWithDataLoaderInOperationalLevel");
string url = "http://localhost:9090/caching_with_dataloader_operational";
string document = check common:getGraphqlDocumentFromFile(documentFile);
foreach int i in 0 ..< resourceFileNames.length() {
Expand All @@ -53,6 +57,7 @@ isolated function testServerSideCacheWithDataLoaderInOperationalLevel(string doc
common:assertJsonValuesWithOrder(actualPayload, expectedPayload);
}
resetDispatchCounters();
io:println("end testServerSideCacheWithDataLoaderInOperationalLevel");
}

function dataProviderServerCacheWithDataloaderInOperationalLevel() returns map<[string, string[], json, string[]]> {
Expand Down

0 comments on commit 87157c7

Please sign in to comment.