Merge branch '5.3.x'
This commit is contained in:
commit
d76953c166
|
|
@ -63,7 +63,7 @@ class ResourceRegionEncoderTests extends AbstractLeakCheckingTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
void shouldEncodeResourceRegionFileResource() throws Exception {
|
||||
void shouldEncodeResourceRegionFileResource() {
|
||||
ResourceRegion region = new ResourceRegion(
|
||||
new ClassPathResource("ResourceRegionEncoderTests.txt", getClass()), 0, 6);
|
||||
Flux<DataBuffer> result = this.encoder.encode(Mono.just(region), this.bufferFactory,
|
||||
|
|
|
|||
|
|
@ -16,6 +16,8 @@
|
|||
|
||||
package org.springframework.core.testfixture.io.buffer;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
|
||||
import org.springframework.core.io.buffer.DataBufferFactory;
|
||||
|
|
@ -42,7 +44,7 @@ public abstract class AbstractLeakCheckingTests {
|
|||
*/
|
||||
@AfterEach
|
||||
final void checkForLeaks() {
|
||||
this.bufferFactory.checkForLeaks();
|
||||
this.bufferFactory.checkForLeaks(Duration.ofSeconds(1));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -80,13 +80,21 @@ public class LeakAwareDataBufferFactory implements DataBufferFactory {
|
|||
* method.
|
||||
*/
|
||||
public void checkForLeaks() {
|
||||
checkForLeaks(Duration.ofSeconds(0));
|
||||
}
|
||||
|
||||
/**
|
||||
* Variant of {@link #checkForLeaks()} with the option to wait for buffer release.
|
||||
* @param timeout how long to wait for buffers to be released; 0 for no waiting
|
||||
*/
|
||||
public void checkForLeaks(Duration timeout) {
|
||||
this.trackCreated.set(false);
|
||||
Instant start = Instant.now();
|
||||
while (true) {
|
||||
if (this.created.stream().noneMatch(LeakAwareDataBuffer::isAllocated)) {
|
||||
return;
|
||||
}
|
||||
if (Instant.now().isBefore(start.plus(Duration.ofSeconds(5)))) {
|
||||
if (Instant.now().isBefore(start.plus(timeout))) {
|
||||
try {
|
||||
Thread.sleep(50);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue