Skip to content

Commit

Permalink
Adds 2% tolerance, i.e. compressor would have to get 2% or more WORSE…
Browse files Browse the repository at this point in the history
… at compressing our example to trigger a failure.
  • Loading branch information
Karm committed Jun 10, 2024
1 parent b41b6ed commit cc361d1
Showing 1 changed file with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class Testflow {
// Depending on the defaults of the compression algorithm,
// the compressed content length may vary slightly between
// Vert.x/Netty versions over time.
public static final int COMPRESSION_TOLERANCE_BYTES = 2;
public static final int COMPRESSION_TOLERANCE_PERCENT = 2;

/**
* This test logic is shared by both "all" module and "some" module.
Expand Down Expand Up @@ -86,10 +86,17 @@ public static void runTest(String endpoint, String acceptEncoding, String conten
final int receivedLength = parseInt(response.headers().get("content-length"));
final int expectedLength = parseInt(contentLength);

assertTrue(receivedLength <= expectedLength + COMPRESSION_TOLERANCE_BYTES,
"Compression apparently failed: receivedLength: " + receivedLength +
" was supposed to be less or equal to expectedLength: " +
expectedLength + COMPRESSION_TOLERANCE_BYTES);
if (contentEncoding == null) {
assertEquals(expectedLength, receivedLength,
"No compression was expected, so the content-length must match exactly.");
} else {
final int expectedLengthWithTolerance = expectedLength + (expectedLength / 100 * COMPRESSION_TOLERANCE_PERCENT);
assertTrue(receivedLength <= expectedLengthWithTolerance,
"Compression apparently failed: receivedLength: " + receivedLength +
" was supposed to be less or equal to expectedLength: " +
expectedLength + " plus " + COMPRESSION_TOLERANCE_PERCENT + "% tolerance, i.e. "
+ expectedLengthWithTolerance + ".");
}

final String body;
if (actualEncoding != null && !"identity".equalsIgnoreCase(actualEncoding)) {
Expand Down

0 comments on commit cc361d1

Please sign in to comment.