Skip to content

Commit

Permalink
Merge pull request #2013 from ballerina-platform/caching-with-execute…
Browse files Browse the repository at this point in the history
…-7.x

[2201.7.x] Fix caching issues with execute action
  • Loading branch information
TharmiganK authored May 29, 2024
2 parents e8325a8 + 6a7754c commit b6d5801
Show file tree
Hide file tree
Showing 30 changed files with 133 additions and 72 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-with-bal-test-graalvm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
call_stdlib_workflow:
name: Run StdLib Workflow
if: ${{ github.event_name != 'schedule' || (github.event_name == 'schedule' && github.repository_owner == 'ballerina-platform') }}
uses: ballerina-platform/ballerina-standard-library/.github/workflows/[email protected]
uses: ballerina-platform/ballerina-library/.github/workflows/[email protected]
with:
lang_tag: ${{ inputs.lang_tag }}
lang_version: ${{ inputs.lang_version }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/process-load-test-result.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
jobs:
call_stdlib_process_load_test_results_workflow:
name: Run StdLib Process Load Test Results Workflow
uses: ballerina-platform/ballerina-standard-library/.github/workflows/process-load-test-results-template.yml@main
uses: ballerina-platform/ballerina-library/.github/workflows/process-load-test-results-template.yml@main
with:
results: ${{ toJson(github.event.client_payload.results) }}
secrets:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/trigger-load-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
call_stdlib_trigger_load_test_workflow:
name: Run StdLib Load Test Workflow
if: ${{ github.event_name != 'schedule' || (github.event_name == 'schedule' && github.repository_owner == 'ballerina-platform') }}
uses: ballerina-platform/ballerina-standard-library/.github/workflows/trigger-load-tests-template.yml@main
uses: ballerina-platform/ballerina-library/.github/workflows/trigger-load-tests-template.yml@main
with:
repo_name: 'module-ballerina-http'
runtime_artifacts_url: 'https://api.github.com/repos/ballerina-platform/module-ballerina-http/actions/artifacts'
Expand Down
6 changes: 3 additions & 3 deletions ballerina-tests/http-advanced-tests/Ballerina.toml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
[package]
org = "ballerina"
name = "http_advanced_tests"
version = "2.9.8"
version = "2.9.9"

[[dependency]]
org = "ballerina"
name = "http_test_common"
repository = "local"
version = "2.9.8"
version = "2.9.9"

[platform.java11]
graalvmCompatible = true

[[platform.java11.dependency]]
scope = "testOnly"
path = "../../test-utils/build/libs/http-test-utils-2.9.8.jar"
path = "../../test-utils/build/libs/http-test-utils-2.9.9-SNAPSHOT.jar"
6 changes: 3 additions & 3 deletions ballerina-tests/http-advanced-tests/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ modules = [
[[package]]
org = "ballerina"
name = "http"
version = "2.9.8"
version = "2.9.9"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "auth"},
Expand Down Expand Up @@ -105,7 +105,7 @@ modules = [
[[package]]
org = "ballerina"
name = "http_advanced_tests"
version = "2.9.8"
version = "2.9.9"
dependencies = [
{org = "ballerina", name = "crypto"},
{org = "ballerina", name = "file"},
Expand All @@ -125,7 +125,7 @@ modules = [
[[package]]
org = "ballerina"
name = "http_test_common"
version = "2.9.8"
version = "2.9.9"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "lang.string"},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ isolated int noCacheHitCountNew = 0;
isolated int maxAgeHitCountNew = 0;
isolated int numberOfHitsNew = 0;
isolated int statusHits = 0;
isolated int greetingHits = 0;
final readonly & xml maxAgePayload1 = xml `<message>before cache expiration</message>`;
final readonly & xml maxAgePayload2 = xml `<message>after cache expiration</message>`;
readonly & string errorBody = "Error";
Expand Down Expand Up @@ -160,6 +161,13 @@ service / on new http:Listener(cacheAnnotationTestPort2, httpVersion = http:HTTP
return err;
}
}

resource function default greeting() returns @http:Cache {maxAge: 10} json {
lock {
greetingHits += 1;
}
return {"message": "Hello, World!"};
}
}

@test:Config {}
Expand Down Expand Up @@ -318,3 +326,50 @@ function testReturnStatusCodeResponsesWithAnnotation() returns error? {
common:assertTextPayload(response.getTextPayload(), errorBody);
return;
}

@test:Config {}
function testBasicCachingBehaviourWithExecute() returns error? {
check checkBasicCachingBehaviourWithExecute("GET", 1);
runtime:sleep(1);
check checkBasicCachingBehaviourWithExecute("get", 1);
runtime:sleep(1);
check checkBasicCachingBehaviourWithExecute("HEAD", 2);
runtime:sleep(1);
check checkBasicCachingBehaviourWithExecute("head", 2);
}

function checkBasicCachingBehaviourWithExecute(string method, int hitCount) returns error? {
http:Response|error response = cacheBackendEP->execute(method, "/greeting", new http:Request());
if response is http:Response {
test:assertEquals(response.statusCode, 200, msg = "Found unexpected output");
lock {
test:assertEquals(greetingHits, hitCount);
}
} else {
test:assertFail(msg = "Found unexpected output type: " + response.message());
}

runtime:sleep(1);

response = cacheBackendEP->execute(method, "/greeting", new http:Request());
if response is http:Response {
test:assertEquals(response.statusCode, 200, msg = "Found unexpected output");
lock {
test:assertEquals(greetingHits, hitCount);
}
} else {
test:assertFail(msg = "Found unexpected output type: " + response.message());
}

runtime:sleep(1);

response = cacheBackendEP->execute(method, "/greeting", new http:Request());
if response is http:Response {
test:assertEquals(response.statusCode, 200, msg = "Found unexpected output");
lock {
test:assertEquals(greetingHits, hitCount);
}
} else {
test:assertFail(msg = "Found unexpected output type: " + response.message());
}
}
6 changes: 3 additions & 3 deletions ballerina-tests/http-client-tests/Ballerina.toml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
[package]
org = "ballerina"
name = "http_client_tests"
version = "2.9.8"
version = "2.9.9"

[[dependency]]
org = "ballerina"
name = "http_test_common"
repository = "local"
version = "2.9.8"
version = "2.9.9"

[platform.java11]
graalvmCompatible = true

[[platform.java11.dependency]]
scope = "testOnly"
path = "../../test-utils/build/libs/http-test-utils-2.9.8.jar"
path = "../../test-utils/build/libs/http-test-utils-2.9.9-SNAPSHOT.jar"
6 changes: 3 additions & 3 deletions ballerina-tests/http-client-tests/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ dependencies = [
[[package]]
org = "ballerina"
name = "http"
version = "2.9.8"
version = "2.9.9"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "auth"},
Expand Down Expand Up @@ -102,7 +102,7 @@ modules = [
[[package]]
org = "ballerina"
name = "http_client_tests"
version = "2.9.8"
version = "2.9.9"
dependencies = [
{org = "ballerina", name = "constraint"},
{org = "ballerina", name = "http"},
Expand All @@ -121,7 +121,7 @@ modules = [
[[package]]
org = "ballerina"
name = "http_test_common"
version = "2.9.8"
version = "2.9.9"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "lang.string"},
Expand Down
6 changes: 3 additions & 3 deletions ballerina-tests/http-dispatching-tests/Ballerina.toml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
[package]
org = "ballerina"
name = "http_dispatching_tests"
version = "2.9.8"
version = "2.9.9"

[[dependency]]
org = "ballerina"
name = "http_test_common"
repository = "local"
version = "2.9.8"
version = "2.9.9"

[platform.java11]
graalvmCompatible = true

[[platform.java11.dependency]]
scope = "testOnly"
path = "../../test-utils/build/libs/http-test-utils-2.9.8.jar"
path = "../../test-utils/build/libs/http-test-utils-2.9.9-SNAPSHOT.jar"
6 changes: 3 additions & 3 deletions ballerina-tests/http-dispatching-tests/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ dependencies = [
[[package]]
org = "ballerina"
name = "http"
version = "2.9.8"
version = "2.9.9"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "auth"},
Expand Down Expand Up @@ -102,7 +102,7 @@ modules = [
[[package]]
org = "ballerina"
name = "http_dispatching_tests"
version = "2.9.8"
version = "2.9.9"
dependencies = [
{org = "ballerina", name = "constraint"},
{org = "ballerina", name = "http"},
Expand All @@ -124,7 +124,7 @@ modules = [
[[package]]
org = "ballerina"
name = "http_test_common"
version = "2.9.8"
version = "2.9.9"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "lang.string"},
Expand Down
6 changes: 3 additions & 3 deletions ballerina-tests/http-interceptor-tests/Ballerina.toml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
[package]
org = "ballerina"
name = "http_interceptor_tests"
version = "2.9.8"
version = "2.9.9"

[[dependency]]
org = "ballerina"
name = "http_test_common"
repository = "local"
version = "2.9.8"
version = "2.9.9"

[platform.java11]
graalvmCompatible = true

[[platform.java11.dependency]]
scope = "testOnly"
path = "../../test-utils/build/libs/http-test-utils-2.9.8.jar"
path = "../../test-utils/build/libs/http-test-utils-2.9.9-SNAPSHOT.jar"
6 changes: 3 additions & 3 deletions ballerina-tests/http-interceptor-tests/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ dependencies = [
[[package]]
org = "ballerina"
name = "http"
version = "2.9.8"
version = "2.9.9"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "auth"},
Expand Down Expand Up @@ -99,7 +99,7 @@ modules = [
[[package]]
org = "ballerina"
name = "http_interceptor_tests"
version = "2.9.8"
version = "2.9.9"
dependencies = [
{org = "ballerina", name = "http"},
{org = "ballerina", name = "http_test_common"},
Expand All @@ -115,7 +115,7 @@ modules = [
[[package]]
org = "ballerina"
name = "http_test_common"
version = "2.9.8"
version = "2.9.9"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "lang.string"},
Expand Down
6 changes: 3 additions & 3 deletions ballerina-tests/http-misc-tests/Ballerina.toml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
[package]
org = "ballerina"
name = "http_misc_tests"
version = "2.9.8"
version = "2.9.9"

[[dependency]]
org = "ballerina"
name = "http_test_common"
repository = "local"
version = "2.9.8"
version = "2.9.9"

[platform.java11]
graalvmCompatible = true

[[platform.java11.dependency]]
scope = "testOnly"
path = "../../test-utils/build/libs/http-test-utils-2.9.8.jar"
path = "../../test-utils/build/libs/http-test-utils-2.9.9-SNAPSHOT.jar"
6 changes: 3 additions & 3 deletions ballerina-tests/http-misc-tests/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ dependencies = [
[[package]]
org = "ballerina"
name = "http"
version = "2.9.8"
version = "2.9.9"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "auth"},
Expand Down Expand Up @@ -99,7 +99,7 @@ modules = [
[[package]]
org = "ballerina"
name = "http_misc_tests"
version = "2.9.8"
version = "2.9.9"
dependencies = [
{org = "ballerina", name = "http"},
{org = "ballerina", name = "http_test_common"},
Expand All @@ -118,7 +118,7 @@ modules = [
[[package]]
org = "ballerina"
name = "http_test_common"
version = "2.9.8"
version = "2.9.9"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "lang.string"},
Expand Down
6 changes: 3 additions & 3 deletions ballerina-tests/http-resiliency-tests/Ballerina.toml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
[package]
org = "ballerina"
name = "http_resiliency_tests"
version = "2.9.8"
version = "2.9.9"

[[dependency]]
org = "ballerina"
name = "http_test_common"
repository = "local"
version = "2.9.8"
version = "2.9.9"

[platform.java11]
graalvmCompatible = true

[[platform.java11.dependency]]
scope = "testOnly"
path = "../../test-utils/build/libs/http-test-utils-2.9.8.jar"
path = "../../test-utils/build/libs/http-test-utils-2.9.9-SNAPSHOT.jar"
6 changes: 3 additions & 3 deletions ballerina-tests/http-resiliency-tests/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ dependencies = [
[[package]]
org = "ballerina"
name = "http"
version = "2.9.8"
version = "2.9.9"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "auth"},
Expand Down Expand Up @@ -99,7 +99,7 @@ modules = [
[[package]]
org = "ballerina"
name = "http_resiliency_tests"
version = "2.9.8"
version = "2.9.9"
dependencies = [
{org = "ballerina", name = "http"},
{org = "ballerina", name = "http_test_common"},
Expand All @@ -116,7 +116,7 @@ modules = [
[[package]]
org = "ballerina"
name = "http_test_common"
version = "2.9.8"
version = "2.9.9"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "lang.string"},
Expand Down
Loading

0 comments on commit b6d5801

Please sign in to comment.