Skip to content

Commit 73100a4

Browse files
authored
Merge pull request #45 from FusionAuth/degroff/gha_test_improvement
Make tests less brittle on GHA.
2 parents 10fc594 + 07fbe1f commit 73100a4

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

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

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
import io.fusionauth.http.server.HTTPServerConfiguration;
3434
import org.testng.annotations.Test;
3535
import static org.testng.Assert.assertEquals;
36-
import static org.testng.Assert.assertNotNull;
3736
import static org.testng.Assert.assertNull;
3837

3938
/**
@@ -84,7 +83,7 @@ public void post_server_configuration_max_form_data(String scheme, boolean chunk
8483
content-length: 0\r
8584
\r
8685
""")
87-
.expectExceptionOnWrite(SocketException.class);
86+
.assertOptionalExceptionOnWrite(SocketException.class);
8887

8988
// Large, but max size has been disabled
9089
withScheme(scheme)
@@ -115,7 +114,7 @@ public void post_server_configuration_max_form_data(String scheme, boolean chunk
115114
content-length: 0\r
116115
\r
117116
""")
118-
.expectExceptionOnWrite(SocketException.class);
117+
.assertOptionalExceptionOnWrite(SocketException.class);
119118
}
120119

121120
@Test(dataProvider = "schemes")
@@ -154,7 +153,7 @@ public void post_server_configuration_max_request_header_size(String scheme) thr
154153
content-length: 0\r
155154
\r
156155
""")
157-
.expectExceptionOnWrite(SocketException.class);
156+
.assertOptionalExceptionOnWrite(SocketException.class);
158157

159158
// Same big size, but disable header size limit.
160159
withScheme(scheme)
@@ -198,12 +197,6 @@ public Builder(String scheme) {
198197
this.scheme = scheme;
199198
}
200199

201-
public Builder expectExceptionOnWrite(Class<? extends Exception> clazz) {
202-
assertNotNull(thrownOnWrite);
203-
assertEquals(thrownOnWrite.getClass(), clazz);
204-
return this;
205-
}
206-
207200
public Builder expectNoExceptionOnWrite() {
208201
assertNull(thrownOnWrite);
209202
return this;
@@ -314,6 +307,18 @@ public Builder expectResponse(String response) throws Exception {
314307
return this;
315308
}
316309

310+
public Builder assertOptionalExceptionOnWrite(Class<? extends Exception> clazz) {
311+
// Note that this assertion really depends upon the system the test is run on, the size of the request, and the amount of data that can be cached.
312+
// - So this is an optional assertion - if exception is not null, then we should be able to assert some attributes.
313+
// - With the larger sizes this exception is mostly always thrown when running tests locally, but in GHA, it doesn't always occur.
314+
if (thrownOnWrite != null) {
315+
assertEquals(thrownOnWrite.getClass(), clazz);
316+
assertEquals(thrownOnWrite.getMessage(), "Broken pipe");
317+
}
318+
319+
return this;
320+
}
321+
317322
public Builder withBodyParameterCount(int bodyParameterCount) {
318323
this.bodyParameterCount = bodyParameterCount;
319324
return this;

0 commit comments

Comments
 (0)