Skip to content

Comments

Add HttpWaitStrategy#237

Merged
jarlah merged 5 commits intotestcontainers:mainfrom
gossi:http-wait-strategy
Feb 15, 2026
Merged

Add HttpWaitStrategy#237
jarlah merged 5 commits intotestcontainers:mainfrom
gossi:http-wait-strategy

Conversation

@gossi
Copy link
Contributor

@gossi gossi commented Feb 3, 2026

Impl for #236

I originally build this for Req. Then saw, there is Tesla. I followed their docs to build the client and make a request - I never used tesla before. I checked the response type from tesla and req and they are pretty equal for the response.

While I tested this with Req, this PR is completely untested - but I thought it's good enough to say hello :)

@jarlah
Copy link
Member

jarlah commented Feb 3, 2026

looks useful :) should be very easy to test it in a isolated manner outside a container configuration. Just start a container with the exunit macro and then construct and call the strategy ? then another test would be to create a special container, maybe an nginx container, that serves a specific html file or something. However it seems to always take a map in the match function. Is it a requirement as the strategy is now that response must be json ? Should it require that?

@gossi
Copy link
Contributor Author

gossi commented Feb 10, 2026

I did a test-case, verifying the default index.html file from nginx is up.

Is it a requirement as the strategy is now that response must be json ? Should it require that?

I don't think at all. You are free to pass headers and a matcher to adjust to your setting.

@gossi
Copy link
Contributor Author

gossi commented Feb 10, 2026

And I hit a timeout on CI. Quite ironic, it is a :socket_closed_remotely error, addressing that is the reason for this PR 😅

But apparently this is a layer lower - any idea for this?

@jarlah
Copy link
Member

jarlah commented Feb 10, 2026

being so random, i try to run them again. they told me nothing. It could be the engine, testcontainers calling the strategy, but meh .. i will think about it

@gossi
Copy link
Contributor Author

gossi commented Feb 13, 2026

I think what happens is: Tesla makes a request to a non-yet-existing endpoint and waits the timeout for it to return. What we want is: Use the timeout window to retry until the request passes.

Req has retry on by default (with exponential backoff) - Tesla has a ready-to-use middleware. I think, we want then this config:

  • max_retries - default to: 3?
  • timeout - default to: 10_000

And then in the request:

  • :timeout (middleware) - timeout / max_retries
  • no delay
  • no exponential backoff
  • no jitter

@gossi
Copy link
Contributor Author

gossi commented Feb 13, 2026

That might have done it. I think the failures are coming from unrelated tests? (I cannot re-run them)

@jarlah
Copy link
Member

jarlah commented Feb 13, 2026

think there is a direct failure here

** (FunctionClauseError) no function clause matching in Testcontainers.WaitStrategy.Testcontainers.HttpWaitStrategy.validate_response/1
(testcontainers 2.0.0-rc) lib/wait_strategy/http_wait_strategy.ex:98: Testcontainers.WaitStrategy.Testcontainers.HttpWaitStrategy.validate_response({:error, :socket_closed_remotely})
(testcontainers 2.0.0-rc) lib/wait_strategy/http_wait_strategy.ex:86: Testcontainers.WaitStrategy.Testcontainers.HttpWaitStrategy.wait_until_container_is_ready/3
(elixir 1.18.4) lib/enum.ex:2546: Enum."-reduce/3-lists^foldl/2-0-"/3
(testcontainers 2.0.0-rc) lib/testcontainers.ex:374: Testcontainers.create_and_start_container/3
(testcontainers 2.0.0-rc) lib/testcontainers.ex:181: anonymous fn/3 in Testcontainers.handle_call/3
(elixir 1.18.4) lib/task/supervised.ex:101: Task.Supervised.invoke_mfa/2
(elixir 1.18.4) lib/task/supervised.ex:36: Task.Supervised.reply/4
Function: #Function<1.21825989/0 in Testcontainers.handle_call/3>
Args: []

but it could also be wierd corner case, due to timeout of course

@jarlah
Copy link
Member

jarlah commented Feb 13, 2026

i think the toxiproxy containers test is a bit flaky too .. so some flaky tests happen. its a symptom but i dont have time to dig into everything :) i will rerun one more time

@jarlah
Copy link
Member

jarlah commented Feb 13, 2026

copilot suggest this

change this

defp validate_response({:ok, response}), do: response

to this

defp validate_response({:ok, response}), do: response
defp validate_response({:error, reason}), do: {:error, reason}

@jarlah
Copy link
Member

jarlah commented Feb 13, 2026

has to be something with that specific elixir version or something ...

@jarlah
Copy link
Member

jarlah commented Feb 13, 2026

ill try to rerun all ;)

Co-authored-by: Jarl André Hübenthal <jarlah@protonmail.com>
@gossi
Copy link
Contributor Author

gossi commented Feb 13, 2026

copilot suggestion was false. Actually, that's the "case falling through" in the with clause then catched already - but always worth a try when out of options 😂

The weird part: This PR fails on tests, that "never" use the code added in here o_O

@jarlah
Copy link
Member

jarlah commented Feb 13, 2026

Well actually the error disappeared. Its only toxiproxy tests failing. And they failed before from time too. I think you are in the clear. I will look into the failing and irrelevant tests

@jarlah
Copy link
Member

jarlah commented Feb 15, 2026

Marked the toxiproxy test as flaky and updated this pr

@jarlah jarlah merged commit 644f5bd into testcontainers:main Feb 15, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants