[Bug]: HttpWaitStrategy removes line breaks in http response body before responsePredicate invocation

Open Beginner friendly
#7,326 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
68/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Quiet
Tech stack
docker, java
Domain
testing

Research direction

Start in org.testcontainers.containers.wait.strategy.HttpWaitStrategy, focusing on getResponseBody and the responsePredicate call. Reproduce the behavior with a multiline HTTP response, then verify that responsePredicate receives the line breaks and that the relevant Core wait-strategy tests pass.

Written by the indexing model from the issue text.

Description

resolution/waiting-for-info type/bug
Module

Core

Testcontainers version

1.18.3

Using the latest Testcontainers version?

Yes

Host OS

Linux

Host Arch

x86

Docker version
Client:
 Version:           20.10.21
 API version:       1.41
 Go version:        go1.18.1
 Git commit:        20.10.21-0ubuntu1~22.04.3
 Built:             Thu Apr 27 05:57:17 2023
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server:
 Engine:
  Version:          20.10.21
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.18.1
  Git commit:       20.10.21-0ubuntu1~22.04.3
  Built:            Thu Apr 27 05:37:25 2023
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.12-0ubuntu1~22.04.3
  GitCommit:        
 runc:
  Version:          1.1.4-0ubuntu1~22.04.3
  GitCommit:        
 docker-init:
  Version:          0.19.0
  GitCommit:
What happened?

for some reason, the HttpWaitStrategy reads the response line by line, but does not save the line break characters. In some cases it is really bad, for example, parsing the prometheus metric of springboot application becomes a nightmare.

from org.testcontainers.containers.wait.strategy.HttpWaitStrategy

   private String getResponseBody(HttpURLConnection connection) throws IOException {
        BufferedReader reader;
        if (200 <= connection.getResponseCode() && connection.getResponseCode() <= 299) {
            reader = new BufferedReader(new InputStreamReader((connection.getInputStream())));
        } else {
            reader = new BufferedReader(new InputStreamReader((connection.getErrorStream())));
        }

        StringBuilder builder = new StringBuilder();
        String line;
        while ((line = reader.readLine()) != null) {
            builder.append(line);  // THIS ROW!!!!!!!
        }
        return builder.toString();
    }
Relevant log output

No response

Additional Information

No response

Dominant language
Java
Stars
8.7k
Forks
1.9k
Avg merge
2d 17h
Merged PRs (30d)
9

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from testcontainers/testcontainers-java

All issues in testcontainers/testcontainers-java

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.