Fix MultiPartServletTest race. (#9629)

The writing of the large content may see an EofException before the 400 response has been processed and delivered to the listener.
This commit is contained in:
Greg Wilkins 2023-04-05 22:41:13 +02:00 committed by GitHub
parent 98c1fe24a2
commit 10abcbcf8e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 6 deletions

View File

@ -23,6 +23,7 @@ import java.nio.file.Path;
import java.util.Arrays;
import java.util.Collection;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.zip.GZIPInputStream;
@ -256,9 +257,18 @@ public class MultiPartServletTest
assertThat(writeError, instanceOf(EofException.class));
// We should get 400 response, for some reason reading the content throws EofException.
Response response = listener.get(30, TimeUnit.SECONDS);
assertThat(response.getStatus(), equalTo(HttpStatus.BAD_REQUEST_400));
// There is a race here, either we fail trying to write some more content OR
// we get 400 response, for some reason reading the content throws EofException.
try
{
Response response = listener.get(30, TimeUnit.SECONDS);
assertThat(response.getStatus(), equalTo(HttpStatus.BAD_REQUEST_400));
}
catch (ExecutionException e)
{
Throwable cause = e.getCause();
assertThat(cause, instanceOf(EofException.class));
}
}
@Test

View File

@ -20,6 +20,7 @@ import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.zip.GZIPInputStream;
@ -273,9 +274,18 @@ public class MultiPartServletTest
assertThat(writeError, instanceOf(EofException.class));
// We should get 400 response, for some reason reading the content throws EofException.
Response response = listener.get(30, TimeUnit.SECONDS);
assertThat(response.getStatus(), equalTo(HttpStatus.BAD_REQUEST_400));
// There is a race here, either we fail trying to write some more content OR
// we get 400 response, for some reason reading the content throws EofException.
try
{
Response response = listener.get(30, TimeUnit.SECONDS);
assertThat(response.getStatus(), equalTo(HttpStatus.BAD_REQUEST_400));
}
catch (ExecutionException e)
{
Throwable cause = e.getCause();
assertThat(cause, instanceOf(EofException.class));
}
}
@Test