Skip to content

Commit 2ee4783

Browse files
authored
Fix flaky native sessions files tests (#5053)
1 parent 7b940f8 commit 2ee4783

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

firebase-crashlytics/src/androidTest/java/com/google/firebase/crashlytics/internal/common/NativeSessionFileGzipperTest.java

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,19 @@
1414

1515
package com.google.firebase.crashlytics.internal.common;
1616

17+
import static java.util.Arrays.stream;
18+
1719
import android.content.Context;
1820
import com.google.firebase.crashlytics.internal.CrashlyticsTestCase;
1921
import java.io.ByteArrayOutputStream;
2022
import java.io.File;
2123
import java.io.FileOutputStream;
22-
import java.io.IOException;
2324
import java.util.Arrays;
2425
import java.util.List;
2526
import org.junit.Test;
2627
import org.mockito.internal.util.collections.Sets;
2728

29+
@SuppressWarnings("ResultOfMethodCallIgnored") // Convenient use of files.
2830
public class NativeSessionFileGzipperTest extends CrashlyticsTestCase {
2931
byte[] testContents = {0, 2, 20, 10};
3032
File testFile;
@@ -47,8 +49,17 @@ protected void setUp() throws Exception {
4749
gzipDir.mkdirs();
4850
}
4951

52+
@Override
53+
protected void tearDown() throws Exception {
54+
super.tearDown();
55+
File[] gzipFiles = gzipDir.listFiles();
56+
if (gzipFiles != null) {
57+
stream(gzipFiles).forEach(File::delete);
58+
}
59+
}
60+
5061
@Test
51-
public void testProcessNativeSessions_putsFilesInCorrectLocation() throws IOException {
62+
public void testProcessNativeSessions_putsFilesInCorrectLocation() {
5263
String fileBackedSessionName = "file";
5364
String byteBackedSessionName = "byte";
5465
FileBackedNativeSessionFile fileSession =
@@ -58,10 +69,12 @@ public void testProcessNativeSessions_putsFilesInCorrectLocation() throws IOExce
5869
List<NativeSessionFile> files = Arrays.asList(fileSession, byteSession);
5970
NativeSessionFileGzipper.processNativeSessions(gzipDir, files);
6071

72+
File[] gzipFiles = gzipDir.listFiles();
73+
assertNotNull(gzipFiles);
6174
assertEquals(
6275
Sets.newSet(
6376
new File(gzipDir, fileBackedSessionName), new File(gzipDir, byteBackedSessionName)),
64-
Sets.newSet(gzipDir.listFiles()));
77+
Sets.newSet(gzipFiles));
6578
}
6679

6780
@Test
@@ -75,7 +88,8 @@ public void testProcessNativeSessionsWhenDataIsNull_putsFilesInCorrectLocation()
7588
List<NativeSessionFile> files = Arrays.asList(fileSession, byteSession);
7689
NativeSessionFileGzipper.processNativeSessions(gzipDir, files);
7790

78-
assertEquals(
79-
Sets.newSet(new File(gzipDir, byteBackedSessionName)), Sets.newSet(gzipDir.listFiles()));
91+
File[] gzipFiles = gzipDir.listFiles();
92+
assertNotNull(gzipFiles);
93+
assertEquals(Sets.newSet(new File(gzipDir, byteBackedSessionName)), Sets.newSet(gzipFiles));
8094
}
8195
}

0 commit comments

Comments
 (0)