Skip to content

Commit

Permalink
test: fixed 16948 leaking file descriptors (#17044)
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Kuzmin <[email protected]>
  • Loading branch information
alex-kuzmin-hg authored Dec 12, 2024
1 parent 48c6ade commit a4d668f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import java.util.List;
import java.util.Map;
import java.util.concurrent.CountDownLatch;
import java.util.stream.Stream;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
Expand Down Expand Up @@ -200,9 +201,14 @@ private static void assertDirectoryTreeEquality(final Path treeA, final Path tre
assertEquals(isDirectory(treeA), isDirectory(treeB), "files should be the same type");

if (isDirectory(treeA)) {
final List<Path> childrenA = Files.list(treeA).toList();
final List<Path> childrenB = Files.list(treeB).toList();

final List<Path> childrenA;
final List<Path> childrenB;
try (Stream<Path> list = Files.list(treeA)) {
childrenA = list.toList();
}
try (Stream<Path> list = Files.list(treeB)) {
childrenB = list.toList();
}
assertEquals(childrenA.size(), childrenB.size(), "directories have a different number of files¬");

final Map<String, Path> mapA = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,11 @@ void deletionTest(@NonNull final AncientMode ancientMode) throws IOException {
final Instant now = Instant.now();

// When we start out, the test directory should be empty.
assertEquals(0, Files.list(testDirectory).count());
int filesCount;
try (Stream<Path> list = Files.list(testDirectory)) {
filesCount = (int) list.count();
}
assertEquals(0, filesCount, "Unexpected number of files: " + filesCount);

final List<Instant> times = new ArrayList<>();
times.add(now);
Expand Down Expand Up @@ -306,7 +310,10 @@ void deletionTest(@NonNull final AncientMode ancientMode) throws IOException {
}

// After all files have been deleted, the test directory should be empty again.
assertEquals(0, Files.list(testDirectory).count());
try (Stream<Path> list = Files.list(testDirectory)) {
filesCount = (int) list.count();
}
assertEquals(0, filesCount, "Unexpected number of files: " + filesCount);
}

@SuppressWarnings("resource")
Expand All @@ -332,7 +339,11 @@ void recycleTest(@NonNull final AncientMode ancientMode) throws IOException {
Files.createDirectories(recycleDirectory);

// When we start out, the test directory should be empty.
assertEquals(0, Files.list(streamDirectory).count());
int filesCount;
try (Stream<Path> list = Files.list(streamDirectory)) {
filesCount = (int) list.count();
}
assertEquals(0, filesCount, "Unexpected number of files: " + filesCount);

final List<Instant> times = new ArrayList<>();
times.add(now);
Expand Down Expand Up @@ -380,7 +391,10 @@ void recycleTest(@NonNull final AncientMode ancientMode) throws IOException {
}

// After all files have been deleted, the test directory should be empty again.
assertEquals(0, Files.list(streamDirectory).count());
try (Stream<Path> list = Files.list(streamDirectory)) {
filesCount = (int) list.count();
}
assertEquals(0, filesCount, "Unexpected number of files: " + filesCount);

// All files should have been moved to the recycle directory
for (final PcesFile file : files) {
Expand Down

0 comments on commit a4d668f

Please sign in to comment.