File tree Expand file tree Collapse file tree 3 files changed +15
-2
lines changed
firebase-common/src/jsMain/kotlin/dev/gitlive/firebase/externals/database
commonTest/kotlin/dev.gitlive.firebase.database
jsTest/kotlin/dev.gitlive.firebase.database Expand file tree Collapse file tree 3 files changed +15
-2
lines changed Original file line number Diff line number Diff line change @@ -39,6 +39,10 @@ external fun limitToLast(limit: Int): QueryConstraint
39
39
40
40
external fun off (query : Query , eventType : String? , callback : Any? )
41
41
42
+ external fun goOffline (db : Database )
43
+
44
+ external fun goOnline (db : Database )
45
+
42
46
external fun onChildAdded (
43
47
query : Query ,
44
48
callback : ChangeSnapshotCallback ,
Original file line number Diff line number Diff line change @@ -6,8 +6,10 @@ package dev.gitlive.firebase.database
6
6
7
7
import dev.gitlive.firebase.*
8
8
import kotlinx.coroutines.flow.first
9
+ import kotlinx.coroutines.withTimeout
9
10
import kotlinx.serialization.*
10
11
import kotlin.test.*
12
+ import kotlin.time.Duration.Companion.seconds
11
13
12
14
expect val emulatorHost: String
13
15
expect val context: Any
@@ -71,7 +73,9 @@ class FirebaseDatabaseTest {
71
73
72
74
private suspend fun awaitDatabaseConnection () {
73
75
// workaround to avoid "Database not connected" exception with Firebase emulator
74
- Firebase .database.reference(" .info/connected" ).valueEvents.first { it.value() }
76
+ withTimeout(5 .seconds) {
77
+ Firebase .database.reference(" .info/connected" ).valueEvents.first { it.value() }
78
+ }
75
79
}
76
80
77
81
private suspend fun setupRealtimeData () {
Original file line number Diff line number Diff line change 4
4
5
5
package dev.gitlive.firebase.database
6
6
7
+ import dev.gitlive.firebase.externals.database.getDatabase
8
+ import dev.gitlive.firebase.externals.database.goOffline
9
+ import dev.gitlive.firebase.externals.database.goOnline
7
10
import kotlinx.coroutines.GlobalScope
8
11
import kotlinx.coroutines.promise
9
12
@@ -14,7 +17,10 @@ actual val context: Any = Unit
14
17
actual fun runTest (test : suspend () -> Unit ) = GlobalScope
15
18
.promise {
16
19
try {
20
+ val db = getDatabase()
21
+ goOnline(db)
17
22
test()
23
+ goOffline(db) // infinitely running test task workaround
18
24
} catch (e: Throwable ) {
19
25
e.log()
20
26
throw e
@@ -28,4 +34,3 @@ internal fun Throwable.log() {
28
34
it.log()
29
35
}
30
36
}
31
-
You can’t perform that action at this time.
0 commit comments