Skip to content

Fix for Integration Tests with test profiles: dev services config overrides #48627

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/native-tests.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
{
"category": "Cache",
"timeout": 75,
"test-modules": "infinispan-cache-jpa, infinispan-client, cache, redis-cache, infinispan-cache",
"test-modules": "infinispan-cache-jpa, infinispan-client, cache, redis-cache, redis-devservices, infinispan-cache",
"os-name": "ubuntu-latest"
},
{
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package io.quarkus.redis.devservices.it;

import io.quarkus.test.junit.QuarkusIntegrationTest;

@QuarkusIntegrationTest
public class DevServicesRedisIT extends DevServicesRedisITest {

}
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package io.quarkus.redis.devservices.it;

import java.util.Arrays;

import jakarta.inject.Inject;
import static io.restassured.RestAssured.when;
import static org.hamcrest.Matchers.is;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import io.quarkus.redis.client.RedisClient;
import io.quarkus.redis.devservices.it.profiles.DevServiceRedis;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.TestProfile;
Expand All @@ -19,12 +17,11 @@
@TestProfile(DevServiceRedis.class)
public class DevServicesRedisITest {

@Inject
RedisClient redisClient;

@BeforeEach
public void setUp() {
redisClient.set(Arrays.asList("anykey", "anyvalue"));
when().get("/set/anykey/anyvalue").then()
.statusCode(200)
.body(is("OK"));
}

@Test
Expand All @@ -36,7 +33,9 @@ public void shouldStartRedisContainer() {
@Test
@DisplayName("given redis container must communicate with it and return value by key")
public void shouldReturnAllKeys() {
Assertions.assertEquals("anyvalue", redisClient.get("anykey").toString());
when().get("/get/anykey").then()
.statusCode(200)
.body(is("anyvalue"));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package io.quarkus.redis.devservices.it;

import io.quarkus.test.junit.QuarkusIntegrationTest;

@QuarkusIntegrationTest
public class DevServicesRedisRandomPortIT extends DevServicesRedisRandomPortITest {

}
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package io.quarkus.redis.devservices.it;

import jakarta.inject.Inject;
import static io.restassured.RestAssured.when;
import static org.hamcrest.Matchers.is;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import io.quarkus.redis.datasource.RedisDataSource;
import io.quarkus.redis.devservices.it.profiles.DevServicesRandomPortProfile;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.TestProfile;
Expand All @@ -16,18 +15,19 @@
@TestProfile(DevServicesRandomPortProfile.class)
public class DevServicesRedisRandomPortITest {

@Inject
RedisDataSource redisClient;

@BeforeEach
public void setUp() {
redisClient.value(String.class).set("anykey", "anyvalue");
when().get("/set/anykey/anyvalue").then()
.statusCode(200)
.body(is("OK"));
}

@Test
@DisplayName("given redis container must communicate with it and return value by key")
public void shouldReturnAllKeys() {
Assertions.assertEquals("anyvalue", redisClient.value(String.class).get("anykey").toString());
when().get("/get/anykey").then()
.statusCode(200)
.body(is("anyvalue"));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -197,21 +197,24 @@ private QuarkusTestExtensionState doProcessStart(Properties quarkusArtifactPrope
boolean isDockerLaunch = isContainer(artifactType)
|| (isJar(artifactType) && "test-with-native-agent".equals(testConfig.integrationTestProfile()));

ArtifactLauncher.InitContext.DevServicesLaunchResult devServicesLaunchResult = handleDevServices(context,
isDockerLaunch);
devServicesProps = devServicesLaunchResult.properties();
containerNetworkId = devServicesLaunchResult.networkId();
quarkusTestProfile = profile;
currentJUnitTestClass = context.getRequiredTestClass();
TestResourceManager testResourceManager = null;
try {
Class<?> requiredTestClass = context.getRequiredTestClass();

Map<String, String> sysPropRestore = getSysPropsToRestore();

TestProfileAndProperties testProfileAndProperties = determineTestProfileAndProperties(profile, sysPropRestore);
// prepare dev services after profile and properties have been determined
ArtifactLauncher.InitContext.DevServicesLaunchResult devServicesLaunchResult = handleDevServices(context,
isDockerLaunch);

devServicesProps = devServicesLaunchResult.properties();
containerNetworkId = devServicesLaunchResult.networkId();
for (String devServicesProp : devServicesProps.keySet()) {
sysPropRestore.put(devServicesProp, null); // used to signal that the property needs to be cleared
}
TestProfileAndProperties testProfileAndProperties = determineTestProfileAndProperties(profile, sysPropRestore);

testResourceManager = new TestResourceManager(requiredTestClass, quarkusTestProfile,
copyEntriesFromProfile(testProfileAndProperties.testProfile,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,6 @@ public void beforeEach(ExtensionContext context) throws Exception {
private LaunchResult doLaunch(ExtensionContext context, String[] arguments) throws Exception {
JBossVersion.disableVersionLogging();

if (quarkusArtifactProperties == null) {
prepare(context);
}
var result = doProcessStart(context, arguments);
List<String> out = Arrays.asList(new String(result.getOutput(), StandardCharsets.UTF_8).split("\n"));
List<String> err = Arrays.asList(new String(result.getStderror(), StandardCharsets.UTF_8).split("\n"));
Expand Down Expand Up @@ -109,8 +106,7 @@ private void prepare(ExtensionContext extensionContext) throws Exception {
boolean isDockerLaunch = isContainer(artifactType)
|| (isJar(artifactType) && "test-with-native-agent".equals(testConfig.integrationTestProfile()));

devServicesLaunchResult = handleDevServices(extensionContext,
isDockerLaunch);
devServicesLaunchResult = handleDevServices(extensionContext, isDockerLaunch);
devServicesProps = devServicesLaunchResult.properties();

ExtensionContext root = extensionContext.getRoot();
Expand All @@ -122,12 +118,16 @@ private ArtifactLauncher.LaunchResult doProcessStart(ExtensionContext context, S
Class<? extends QuarkusTestProfile> profile = IntegrationTestUtil.findProfile(context.getRequiredTestClass());
TestResourceManager testResourceManager = null;
Map<String, String> old = new HashMap<>();
String artifactType = quarkusArtifactProperties.getProperty("type");
try {
Class<?> requiredTestClass = context.getRequiredTestClass();

Map<String, String> sysPropRestore = getSysPropsToRestore();
TestProfileAndProperties testProfileAndProperties = determineTestProfileAndProperties(profile, sysPropRestore);
// prepare dev services after profile and properties have been determined
if (quarkusArtifactProperties == null) {
prepare(context);
}
String artifactType = quarkusArtifactProperties.getProperty("type");

testResourceManager = new TestResourceManager(requiredTestClass, profile,
copyEntriesFromProfile(testProfileAndProperties.testProfile,
Expand Down
Loading