Skip to content

Commit 83ecd12

Browse files
authored
Merge pull request #48 from FusionAuth/degroff/fix_flaky_test
Improve tests for GHA runner
2 parents a7070c3 + c12894e commit 83ecd12

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

src/test/java/io/fusionauth/http/ChunkedTest.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ public void chunkedRequest(String scheme) throws Exception {
102102
}
103103
}
104104

105-
@SuppressWarnings({"SpellCheckingInspection", "GrazieInspection"})
106105
@Test(dataProvider = "schemes")
107106
public void chunkedRequest_doNotReadTheInputStream(String scheme) throws Exception {
108107
// Use a large chunked request
@@ -140,7 +139,8 @@ public void chunkedRequest_doNotReadTheInputStream(String scheme) throws Excepti
140139
URI uri = makeURI(scheme, "");
141140

142141
// This ensures we are not just passing the test because we interrupt the InputStream and cause it to not hang.
143-
for (int i = 0; i < 10; i++) {
142+
int iterations = 50;
143+
for (int i = 0; i < iterations; i++) {
144144
var response = client.send(HttpRequest.newBuilder()
145145
.uri(uri)
146146
.header(Headers.ContentType, "text/plain")
@@ -154,13 +154,11 @@ public void chunkedRequest_doNotReadTheInputStream(String scheme) throws Excepti
154154

155155
assertEquals(response.statusCode(), 200);
156156
assertEquals(response.body(), ExpectedResponse);
157-
// We didn't read the InputStream, but the drain() will have - so this will count as a chunkedRequest.
158-
// - Note if you run this a bunch of times in a tight loop this next check doesn't always line up. I think it is because of the
159-
// Java HTTP client being slow. If I just run it 10 times in a loop it is fine, if I run it 100 times in a loop it fails interminttentl
160-
// and the error is the chunked requests don't match the iteration count. I can confirm the getChunkedRequests() matches
161-
// the number of times we commit the InputStream which causes us to mark the request as chunked.
162-
assertEquals(instrumenter.getChunkedRequests(), i + 1);
163157
}
158+
159+
// Expect that we counted the correct number of chunked requests.
160+
long chunkedRequests = instrumenter.getChunkedRequests();
161+
assertEquals(chunkedRequests, iterations);
164162
}
165163
}
166164

src/test/java/io/fusionauth/http/CompressionTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public void compress(String scheme, String contentEncoding, String acceptEncodin
128128
.header(Headers.AcceptEncoding, acceptEncoding)
129129
.header(Headers.ContentEncoding, contentEncoding)
130130
.header(Headers.ContentType, "text/plain")
131-
// In general using a BodyPublishers.ofInputStream causes the client to use chunked transfer encoding.
131+
// In general, using a BodyPublishers.ofInputStream causes the client to use chunked transfer encoding.
132132
// - Manually set the header because the body is small, and it may not chunk it otherwise.
133133
.header(Headers.TransferEncoding, "chunked")
134134
.POST(BodyPublishers.ofInputStream(() -> new ByteArrayInputStream(requestPayload)))

0 commit comments

Comments
 (0)