Skip to content

Commit 6a7dc43

Browse files
Merge pull request #48584 from holly-cummins/reorder-test-methods
Reorder test methods for Redis dev services
2 parents 39231c8 + 0b48790 commit 6a7dc43

File tree

1 file changed

+70
-70
lines changed

1 file changed

+70
-70
lines changed

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

Lines changed: 70 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -76,76 +76,6 @@ public void testContinuousTestingDisablesDevServicesWhenPropertiesChange() {
7676
// We could check the container goes away, but we'd have to check slowly, because ryuk can be slow
7777
}
7878

79-
// This tests behaviour in dev mode proper when combined with continuous testing. This creates a possibility of port conflicts, false sharing of state, and all sorts of race conditions.
80-
@Test
81-
public void testDevModeCoexistingWithContinuousTestingServiceUpdatesContainersOnConfigChange() {
82-
// Note that driving continuous testing concurrently can sometimes cause 500s caused by containers not yet being available on slow machines
83-
ContinuousTestingTestUtils continuousTestingTestUtils = new ContinuousTestingTestUtils();
84-
ContinuousTestingTestUtils.TestStatus result = continuousTestingTestUtils.waitForNextCompletion();
85-
assertEquals(result.getTotalTestsPassed(), 1);
86-
assertEquals(result.getTotalTestsFailed(), 0);
87-
// Interacting with the app will force a refresh
88-
ping();
89-
90-
List<Container> started = getRedisContainers();
91-
assertFalse(started.isEmpty());
92-
Container container = started.get(0);
93-
assertTrue(Arrays.stream(container.getPorts()).noneMatch(p -> p.getPublicPort() == 6377),
94-
"Expected random port, but got: " + Arrays.toString(container.getPorts()));
95-
96-
int newPort = 6388;
97-
int testPort = newPort + 1;
98-
// Continuous tests and dev mode should *not* share containers, even if the port is fixed
99-
// Specify that the fixed port is for dev mode, or one launch will fail with port conflicts
100-
test.modifyResourceFile("application.properties",
101-
s -> ContinuousTestingTestUtils.appProperties("%dev.quarkus.redis.devservices.port=" + newPort
102-
+ "\n%test.quarkus.redis.devservices.port=" + testPort));
103-
test.modifyTestSourceFile(PlainQuarkusTest.class, s -> s.replaceAll("redisClient", "updatedRedisClient"));
104-
105-
// Force another refresh
106-
result = continuousTestingTestUtils.waitForNextCompletion();
107-
assertEquals(result.getTotalTestsPassed(), 1);
108-
assertEquals(result.getTotalTestsFailed(), 0);
109-
ping();
110-
111-
List<Container> newContainers = getRedisContainersExcludingExisting(started);
112-
113-
// We expect 2 new containers, since test was also refreshed
114-
assertEquals(2, newContainers.size(),
115-
"New containers: "
116-
+ prettyPrintContainerList(newContainers)
117-
+ "\n Old containers: " + prettyPrintContainerList(started) + "\n All containers: "
118-
+ prettyPrintContainerList(getAllContainers())); // this can be wrong
119-
// 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
120-
boolean hasRightPort = newContainers.stream()
121-
.anyMatch(newContainer -> hasPublicPort(newContainer, newPort));
122-
assertTrue(hasRightPort,
123-
"Expected port " + newPort + ", but got: "
124-
+ newContainers.stream().map(c -> Arrays.toString(c.getPorts())).collect(Collectors.joining(", ")));
125-
boolean hasRightTestPort = newContainers.stream()
126-
.anyMatch(newContainer -> hasPublicPort(newContainer, testPort));
127-
assertTrue(hasRightTestPort,
128-
"Expected port " + testPort + ", but got: "
129-
+ newContainers.stream().map(c -> Arrays.toString(c.getPorts())).collect(Collectors.joining(", ")));
130-
131-
}
132-
133-
private static String prettyPrintContainerList(List<Container> newContainers) {
134-
return newContainers.stream()
135-
.map(c -> Arrays.toString(c.getPorts()) + " -- " + Arrays.toString(c.getNames()) + " -- " + c.getLabels())
136-
.collect(Collectors.joining(", \n"));
137-
}
138-
139-
private static boolean hasPublicPort(Container newContainer, int newPort) {
140-
return Arrays.stream(newContainer.getPorts()).anyMatch(p -> p.getPublicPort() == newPort);
141-
}
142-
143-
void ping() {
144-
when().get("/bundled/ping").then()
145-
.statusCode(200)
146-
.body(is("PONG"));
147-
}
148-
14979
@Test
15080
public void testContinuousTestingReusesInstanceWhenPropertiesAreNotChanged() {
15181

@@ -224,6 +154,76 @@ public void testContinuousTestingCreatesANewInstanceWhenPropertiesAreChanged() {
224154
}
225155
}
226156

157+
// This tests behaviour in dev mode proper when combined with continuous testing. This creates a possibility of port conflicts, false sharing of state, and all sorts of race conditions.
158+
@Test
159+
public void testDevModeCoexistingWithContinuousTestingServiceUpdatesContainersOnConfigChange() {
160+
// Note that driving continuous testing concurrently can sometimes cause 500s caused by containers not yet being available on slow machines
161+
ContinuousTestingTestUtils continuousTestingTestUtils = new ContinuousTestingTestUtils();
162+
ContinuousTestingTestUtils.TestStatus result = continuousTestingTestUtils.waitForNextCompletion();
163+
assertEquals(result.getTotalTestsPassed(), 1);
164+
assertEquals(result.getTotalTestsFailed(), 0);
165+
// Interacting with the app will force a refresh
166+
ping();
167+
168+
List<Container> started = getRedisContainers();
169+
assertFalse(started.isEmpty());
170+
Container container = started.get(0);
171+
assertTrue(Arrays.stream(container.getPorts()).noneMatch(p -> p.getPublicPort() == 6377),
172+
"Expected random port, but got: " + Arrays.toString(container.getPorts()));
173+
174+
int newPort = 6388;
175+
int testPort = newPort + 1;
176+
// Continuous tests and dev mode should *not* share containers, even if the port is fixed
177+
// Specify that the fixed port is for dev mode, or one launch will fail with port conflicts
178+
test.modifyResourceFile("application.properties",
179+
s -> ContinuousTestingTestUtils.appProperties("%dev.quarkus.redis.devservices.port=" + newPort
180+
+ "\n%test.quarkus.redis.devservices.port=" + testPort));
181+
test.modifyTestSourceFile(PlainQuarkusTest.class, s -> s.replaceAll("redisClient", "updatedRedisClient"));
182+
183+
// Force another refresh
184+
result = continuousTestingTestUtils.waitForNextCompletion();
185+
assertEquals(result.getTotalTestsPassed(), 1);
186+
assertEquals(result.getTotalTestsFailed(), 0);
187+
ping();
188+
189+
List<Container> newContainers = getRedisContainersExcludingExisting(started);
190+
191+
// We expect 2 new containers, since test was also refreshed
192+
assertEquals(2, newContainers.size(),
193+
"New containers: "
194+
+ prettyPrintContainerList(newContainers)
195+
+ "\n Old containers: " + prettyPrintContainerList(started) + "\n All containers: "
196+
+ prettyPrintContainerList(getAllContainers())); // this can be wrong
197+
// 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
198+
boolean hasRightPort = newContainers.stream()
199+
.anyMatch(newContainer -> hasPublicPort(newContainer, newPort));
200+
assertTrue(hasRightPort,
201+
"Expected port " + newPort + ", but got: "
202+
+ newContainers.stream().map(c -> Arrays.toString(c.getPorts())).collect(Collectors.joining(", ")));
203+
boolean hasRightTestPort = newContainers.stream()
204+
.anyMatch(newContainer -> hasPublicPort(newContainer, testPort));
205+
assertTrue(hasRightTestPort,
206+
"Expected port " + testPort + ", but got: "
207+
+ newContainers.stream().map(c -> Arrays.toString(c.getPorts())).collect(Collectors.joining(", ")));
208+
209+
}
210+
211+
void ping() {
212+
when().get("/bundled/ping").then()
213+
.statusCode(200)
214+
.body(is("PONG"));
215+
}
216+
217+
private static boolean hasPublicPort(Container newContainer, int newPort) {
218+
return Arrays.stream(newContainer.getPorts()).anyMatch(p -> p.getPublicPort() == newPort);
219+
}
220+
221+
private static String prettyPrintContainerList(List<Container> newContainers) {
222+
return newContainers.stream()
223+
.map(c -> Arrays.toString(c.getPorts()) + " -- " + Arrays.toString(c.getNames()) + " -- " + c.getLabels())
224+
.collect(Collectors.joining(", \n"));
225+
}
226+
227227
private static List<Container> getAllContainers() {
228228
return DockerClientFactory.lazyClient().listContainersCmd().exec().stream()
229229
.filter(container -> isRedisContainer(container)).toList();

0 commit comments

Comments
 (0)