Skip to content

Commit 93cb613

Browse files
authored
Merge pull request #48293 from holly-cummins/clarify-what-is-being-tested-in-redis-dev-service-tests
Split out 'easy' test for dev mode only, and harder test for dev and test
2 parents d4bc475 + 0345645 commit 93cb613

File tree

1 file changed

+56
-4
lines changed

1 file changed

+56
-4
lines changed

integration-tests/redis-devservices/src/test/java/io/quarkus/redis/devservices/continuoustesting/it/DevServicesRedisContinuousTestingTest.java

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,26 +71,78 @@ public void testContinuousTestingDisablesDevServicesWhenPropertiesChange() {
7171

7272
// This tests behaviour in dev mode proper (rather than continuous testing)
7373
@Test
74-
public void testDevModeServiceUpdatesContainersOnConfigChange() {
75-
List<Container> started = getRedisContainers();
74+
public void testDevModeCoexistingWithContinuousTestingServiceUpdatesContainersOnConfigChange() {
7675
// Interacting with the app will force a refresh
76+
// Note that driving continuous testing concurrently can sometimes cause 500s caused by containers not yet being available on slow machines
77+
ContinuousTestingTestUtils continuousTestingTestUtils = new ContinuousTestingTestUtils();
78+
ContinuousTestingTestUtils.TestStatus result = continuousTestingTestUtils.waitForNextCompletion();
79+
assertEquals(result.getTotalTestsPassed(), 1);
80+
assertEquals(result.getTotalTestsFailed(), 0);
7781
ping();
7882

83+
List<Container> started = getRedisContainers();
7984
assertFalse(started.isEmpty());
8085
Container container = started.get(0);
8186
assertTrue(Arrays.stream(container.getPorts()).noneMatch(p -> p.getPublicPort() == 6377),
8287
"Expected random port, but got: " + Arrays.toString(container.getPorts()));
8388

8489
int newPort = 6388;
90+
int testPort = newPort + 1;
8591
// Continuous tests and dev mode should *not* share containers, even if the port is fixed
86-
// Specify that the fixed port is for dev mode
92+
// Specify that the fixed port is for dev mode, or one launch will fail with port conflicts
93+
test.modifyResourceFile("application.properties",
94+
s -> ContinuousTestingTestUtils.appProperties("%dev.quarkus.redis.devservices.port=" + newPort
95+
+ "\n%test.quarkus.redis.devservices.port=" + testPort));
96+
test.modifyTestSourceFile(PlainQuarkusTest.class, s -> s.replaceAll("redisClient", "updatedRedisClient"));
97+
98+
// Force another refresh
99+
result = continuousTestingTestUtils.waitForNextCompletion();
100+
assertEquals(result.getTotalTestsPassed(), 1);
101+
assertEquals(result.getTotalTestsFailed(), 0);
102+
ping();
103+
104+
List<Container> newContainers = getRedisContainersExcludingExisting(started);
105+
106+
// We expect 2 new containers, since test was also refreshed
107+
assertEquals(2, newContainers.size(),
108+
"New containers: "
109+
+ prettyPrintContainerList(newContainers)
110+
+ "\n Old containers: " + prettyPrintContainerList(started) + "\n All containers: "
111+
+ prettyPrintContainerList(getAllContainers())); // this can be wrong
112+
// We need to inspect the dev-mode container; we don't have a non-brittle way of distinguishing them, so just look in them all
113+
boolean hasRightPort = newContainers.stream()
114+
.anyMatch(newContainer -> hasPublicPort(newContainer, newPort));
115+
assertTrue(hasRightPort,
116+
"Expected port " + newPort + ", but got: "
117+
+ newContainers.stream().map(c -> Arrays.toString(c.getPorts())).collect(Collectors.joining(", ")));
118+
boolean hasRightTestPort = newContainers.stream()
119+
.anyMatch(newContainer -> hasPublicPort(newContainer, testPort));
120+
assertTrue(hasRightTestPort,
121+
"Expected port " + testPort + ", but got: "
122+
+ newContainers.stream().map(c -> Arrays.toString(c.getPorts())).collect(Collectors.joining(", ")));
123+
124+
}
125+
126+
@Test
127+
public void testDevModeServiceUpdatesContainersOnConfigChange() {
128+
// Interacting with the app will force a refresh
129+
ping();
130+
List<Container> started = getRedisContainers();
131+
132+
assertFalse(started.isEmpty());
133+
Container container = started.get(0);
134+
assertTrue(Arrays.stream(container.getPorts()).noneMatch(p -> p.getPublicPort() == 6377),
135+
"Expected random port, but got: " + Arrays.toString(container.getPorts()));
136+
137+
int newPort = 6388;
87138
test.modifyResourceFile("application.properties",
88139
s -> ContinuousTestingTestUtils.appProperties("quarkus.redis.devservices.port=" + newPort));
89140

90141
// Force another refresh
91142
ping();
92143
List<Container> newContainers = getRedisContainersExcludingExisting(started);
93144

145+
// We expect 1 new containers, since test was not refreshed
94146
assertEquals(1, newContainers.size(),
95147
"New containers: "
96148
+ prettyPrintContainerList(newContainers)
@@ -106,8 +158,8 @@ public void testDevModeServiceUpdatesContainersOnConfigChange() {
106158

107159
@Test
108160
public void testDevModeServiceDoesNotRestartContainersOnCodeChange() {
109-
List<Container> started = getRedisContainers();
110161
ping();
162+
List<Container> started = getRedisContainers();
111163

112164
assertFalse(started.isEmpty());
113165
Container container = started.get(0);

0 commit comments

Comments
 (0)