-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Support multiple HTTP status codes for HttpWaitStrategy #630
Changes from 14 commits
cf637ce
da44bd9
0af2eab
e5ddd16
1b7cbaf
f2d1592
bf12100
3b34909
afe06dc
9f1b28a
cb4875d
bb39373
10ca9cd
370c35a
808dcf8
d6837f7
6b24c2a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,17 @@ | ||
package org.testcontainers.junit.wait; | ||
package org.testcontainers.junit.wait.strategy; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm... I'm not sure these changes are related to the PR There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's somewhat needed to test the new methods I added. See There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should just start using new implementation (under There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dadoonet ping :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hum. I'm missing something. I probably misunderstood what you are expecting. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But I added a call to my method There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But I added a call to my method There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should just fix the imports in the old test and start using new wait strategies, so that you can also add your new method to that test There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Works for me. I'll do that. In which case, I'll also move the tests to the new package, right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, thanks :) |
||
|
||
import org.jetbrains.annotations.NotNull; | ||
import org.junit.Before; | ||
import org.rnorth.ducttape.RetryCountExceededException; | ||
import org.rnorth.visibleassertions.VisibleAssertions; | ||
import org.testcontainers.containers.ContainerLaunchException; | ||
import org.testcontainers.containers.GenericContainer; | ||
import org.testcontainers.containers.wait.WaitStrategy; | ||
import org.testcontainers.containers.wait.strategy.WaitStrategy; | ||
|
||
import java.time.Duration; | ||
import java.util.concurrent.atomic.AtomicBoolean; | ||
|
||
import static org.junit.Assert.*; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
/** | ||
* Common test methods for {@link WaitStrategy} implementations. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
package org.testcontainers.junit.wait; | ||
package org.testcontainers.junit.wait.strategy; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
import org.junit.Test; | ||
import org.rnorth.ducttape.RetryCountExceededException; | ||
import org.testcontainers.containers.wait.HttpWaitStrategy; | ||
import org.testcontainers.containers.wait.strategy.HttpWaitStrategy; | ||
|
||
import java.util.concurrent.atomic.AtomicBoolean; | ||
|
||
|
@@ -24,7 +24,7 @@ public class HttpWaitStrategyTest extends AbstractWaitStrategyTest<HttpWaitStrat | |
* Expects that the WaitStrategy returns successfully after receiving an HTTP 200 response from the container. | ||
*/ | ||
@Test | ||
public void testWaitUntilReady_Success() { | ||
public void testWaitUntilReadyWithSuccess() { | ||
waitUntilReadyAndSucceed(createShellCommand("200 OK", GOOD_RESPONSE_BODY)); | ||
} | ||
|
||
|
@@ -33,7 +33,7 @@ public void testWaitUntilReady_Success() { | |
* response from the container within the timeout period. | ||
*/ | ||
@Test | ||
public void testWaitUntilReady_Timeout() { | ||
public void testWaitUntilReadyWithTimeout() { | ||
waitUntilReadyAndTimeout(createShellCommand("400 Bad Request", GOOD_RESPONSE_BODY)); | ||
} | ||
|
||
|
@@ -42,7 +42,7 @@ public void testWaitUntilReady_Timeout() { | |
* from the container within the timeout period. | ||
*/ | ||
@Test | ||
public void testWaitUntilReady_Timeout_BadResponseBody() { | ||
public void testWaitUntilReadyWithTimeoutAndBadResponseBody() { | ||
waitUntilReadyAndTimeout(createShellCommand("200 OK", "Bad Response")); | ||
} | ||
|
||
|
@@ -59,7 +59,9 @@ protected void waitUntilReady() { | |
super.waitUntilReady(); | ||
ready.set(true); | ||
} | ||
}.forResponsePredicate(s -> s.equals(GOOD_RESPONSE_BODY)); | ||
} | ||
.forResponsePredicate(s -> s.equals(GOOD_RESPONSE_BODY)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please add a test where both There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good call. My code is actually failing! :p There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But we're still missing a test where we call
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So should I clone the class or just change the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just add a test method which is not based on There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did it. A bit differently though so I can reuse most of the existing code and that could help in the future. |
||
.forStatusCodeMatching(it -> it >= 200 && it < 300 || it == 401); | ||
} | ||
|
||
private String createShellCommand(String header, String responseBody) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm thinking about the use case where somebody will call
Wait.forHttp().forStatusCode(200).forStatusCodeMatching(it -> it > 400)
. Maybe we should throw an error, or handle both statuses?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do really like the Predicate approach here - it opens the door to having some useful ready-to-use predicates in the future (e.g.
anySuccessfulStatusCode()
oranyServerErrorStatusCode()
etc...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the latest change below I'm now hopefully supporting both.