Skip to content

Commit 2e5fd40

Browse files
Add more tests and update comment.
1 parent 2776833 commit 2e5fd40

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

firebase-config/src/main/java/com/google/firebase/remoteconfig/internal/ConfigAutoFetch.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public void listenForNotifications() {
119119
handleNotifications(inputStream);
120120
} catch (IOException ex) {
121121
// If the real-time connection is at an unexpected lifecycle state when the app is
122-
// backgrounded, it's expected closing the InputStream will throw an exception.
122+
// backgrounded, it's expected closing the httpURLConnection will throw an exception.
123123
if (!isInBackground) {
124124
// Otherwise, the real-time server connection was closed due to a transient issue.
125125
Log.d(TAG, "Real-time connection was closed due to an exception.", ex);

firebase-config/src/test/java/com/google/firebase/remoteconfig/FirebaseRemoteConfigTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1566,6 +1566,18 @@ public void realtime_stream_listen_get_inputstream_fail() throws Exception {
15661566
verify(inputStream).close();
15671567
}
15681568

1569+
@Test
1570+
public void realtime_stream_listen_get_inputstream_exception_handling() throws Exception {
1571+
ConfigAutoFetch configAutoFetchSpy = spy(configAutoFetch);
1572+
InputStream inputStream = mock(InputStream.class);
1573+
when(mockHttpURLConnection.getResponseCode()).thenReturn(200);
1574+
when(mockHttpURLConnection.getInputStream()).thenThrow(IOException.class);
1575+
configAutoFetchSpy.listenForNotifications();
1576+
1577+
verify(mockHttpURLConnection, times(1)).getInputStream();
1578+
verify(inputStream, never()).close();
1579+
}
1580+
15691581
@Test
15701582
public void realtime_stream_autofetch_success() throws Exception {
15711583
// Setup activated configs with keys "string_param", "long_param"

0 commit comments

Comments
 (0)