Skip to content

Commit dc9a9f2

Browse files
sntiwari1claude
andcommitted
Fix async E2E failures: OIDC timeout, metrics crash, Karate timeout
Three related fixes for the second (async) test suite: 1. CustomJwtDecoderProviderConfigurationUtils: the lazy OIDC decoder's RestTemplate had no timeout. Under CI load with 16 services, the OIDC discovery call to keycloak:8080 could take >30s, blocking all 5 parallel Karate threads until Karate's own 30s timeout fired. Add connectTimeout=10s and readTimeout=15s via SimpleClientHttpRequestFactory so the call fails fast and retries. 2. docker-compose-v1.yml: metrics depends_on now includes clickhouse:service_healthy. The metrics service calls log.Fatal on any ClickHouse query error, killing the process. Without the dependency, metrics started before ClickHouse was ready, received its first Kafka metric, tried to insert, got a connection error, and crashed — making port 8070 disappear after wait_for_port passed. 3. karate-config.js: raise Karate's readTimeout from the default 30s to 90s and connectTimeout to 10s. With 16+ containers running on a shared CI runner, operations that take 1-5s in the first test suite (6 containers) can take 30-60s in the second (16 containers). The old 30s Karate timeout was too tight for this environment. 4. Makefile: add explicit OIDC endpoint readiness check (curl --retry on .well-known/openid-configuration) before both test suites. This ensures the lazy decoder's very first call finds Keycloak fully initialized, not just TCP-reachable on port 8080. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 94ce471 commit dc9a9f2

4 files changed

Lines changed: 16 additions & 1 deletion

File tree

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ test: build
3333
@docker-compose -f docker-compose-v1.yml --env-file test_environments/test_with_distributedDefManager_nativeSearch.env up -d db keycloak registry certificate-signer certificate-api redis
3434
@echo "Starting the test" && sh build/wait_for_port.sh 8080
3535
@echo "Starting the test" && sh build/wait_for_port.sh 8081
36+
@echo "Waiting for Keycloak OIDC endpoint..." && curl --retry 30 --retry-delay 5 --retry-all-errors -sf -o /dev/null http://localhost:8080/auth/realms/sunbird-rc/.well-known/openid-configuration
3637
@docker-compose -f docker-compose-v1.yml ps
3738
@curl -v http://localhost:8081/health
3839
@cd java/apitest && ../mvnw -Pe2e test
@@ -42,6 +43,7 @@ test: build
4243
@docker-compose -f docker-compose-v1.yml --env-file test_environments/test_with_asyncCreate_events_notifications.env up -d db es clickhouse redis keycloak registry certificate-signer certificate-api kafka zookeeper notification-ms metrics
4344
@echo "Starting the test" && sh build/wait_for_port.sh 8080
4445
@echo "Starting the test" && sh build/wait_for_port.sh 8081
46+
@echo "Waiting for Keycloak OIDC endpoint..." && curl --retry 30 --retry-delay 5 --retry-all-errors -sf -o /dev/null http://localhost:8080/auth/realms/sunbird-rc/.well-known/openid-configuration
4547
@echo "Starting the test" && sh build/wait_for_port.sh 8070
4648
@docker-compose -f docker-compose-v1.yml ps
4749
@curl -v http://localhost:8081/health

docker-compose-v1.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,8 @@ services:
338338
condition: service_healthy
339339
registry:
340340
condition: service_healthy
341+
clickhouse:
342+
condition: service_healthy
341343
redis:
342344
image: redis:latest
343345
ports:

java/apitest/src/test/java/karate-config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ function fn() {
88
env: env,
99
baseurl: 'http://localhost:8081'
1010
}
11+
// CI can be slow with 16+ containers running; give services 90s to respond
12+
karate.configure('connectTimeout', 10000);
13+
karate.configure('readTimeout', 90000);
1114
if (env == 'dev') {
1215
// customize
1316
// e.g. config.foo = 'bar';

java/middleware/registry-middleware/authorization/src/main/java/dev/sunbirdrc/registry/authorization/CustomJwtDecoderProviderConfigurationUtils.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import org.springframework.core.ParameterizedTypeReference;
44
import org.springframework.http.RequestEntity;
55
import org.springframework.http.ResponseEntity;
6+
import org.springframework.http.client.SimpleClientHttpRequestFactory;
67
import org.springframework.web.client.HttpClientErrorException;
78
import org.springframework.web.client.RestTemplate;
89
import org.springframework.web.util.UriComponentsBuilder;
@@ -13,7 +14,14 @@
1314

1415
final class CustomJwtDecoderProviderConfigurationUtils {
1516
private static final String OIDC_METADATA_PATH = "/.well-known/openid-configuration";
16-
private static final RestTemplate rest = new RestTemplate();
17+
private static final RestTemplate rest = buildRestTemplate();
18+
19+
private static RestTemplate buildRestTemplate() {
20+
SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
21+
factory.setConnectTimeout(10_000);
22+
factory.setReadTimeout(15_000);
23+
return new RestTemplate(factory);
24+
}
1725
private static final ParameterizedTypeReference<Map<String, Object>> typeReference =
1826
new ParameterizedTypeReference<Map<String, Object>>() {};
1927

0 commit comments

Comments
 (0)