-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix network requests sometimes returning
null
instead of either ret…
…urning success or failure
- Loading branch information
Christian Melchior
committed
Oct 11, 2023
1 parent
047708f
commit f559459
Showing
4 changed files
with
48 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
...brary/src/androidTestObjectServer/kotlin/io/realm/internal/network/NetworkRequestTests.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package io.realm.internal.network | ||
|
||
import androidx.test.platform.app.InstrumentationRegistry | ||
import io.realm.Realm | ||
import io.realm.mongodb.App | ||
import io.realm.mongodb.AppException | ||
import io.realm.mongodb.ErrorCode | ||
import junit.framework.TestCase.assertEquals | ||
import org.junit.Before | ||
import org.junit.Test | ||
import kotlin.test.assertFailsWith | ||
|
||
class NetworkRequestTests { | ||
|
||
private lateinit var app: App | ||
|
||
@Before | ||
fun setUp() { | ||
Realm.init(InstrumentationRegistry.getInstrumentation().targetContext) | ||
} | ||
|
||
// Test for https://github.com/realm/realm-java/issues/7847 | ||
@Test | ||
fun interruptedRequestReturnsError() { | ||
val request = object: NetworkRequest<Unit>() { | ||
override fun mapSuccess(result: Any?): Unit { | ||
Unit | ||
} | ||
|
||
override fun execute(callback: NetworkRequest<Unit>) { | ||
Thread.currentThread().interrupt() | ||
} | ||
} | ||
assertFailsWith<AppException> { | ||
request.resultOrThrow() | ||
}.also { | ||
assertEquals(it.errorCode, ErrorCode.NETWORK_INTERRUPTED) | ||
assertEquals(it.errorMessage, "Network request interrupted.") | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters