Skip to content

Commit

Permalink
Fix weak children not notified of lock change
Browse files Browse the repository at this point in the history
  • Loading branch information
NichtStudioCode committed Nov 6, 2024
1 parent ef3e938 commit 1e63383
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,8 @@ abstract class AbstractProvider<T>(

activeChildren?.forEach { it.changeLock(lock) }
inactiveChildren?.forEach { it.changeLock(lock) }
weakActiveChildren?.forEach { it.changeLock(lock) }
weakInactiveChildren?.forEach { it.changeLock(lock) }
activeParents?.forEach { it.parent.changeLock(lock) }
inactiveParents?.forEach { it.changeLock(lock) }
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package xyz.xenondevs.commons.provider

import org.junit.jupiter.api.Test
import kotlin.test.assertContentEquals
import kotlin.test.assertEquals

class ProviderTest {
Expand Down Expand Up @@ -182,6 +183,25 @@ class ProviderTest {
provider.set(1)
}

@OptIn(UnstableProviderApi::class)
@Test
fun testLockChangedPropagate() {
val a = provider("a") as AbstractProvider<String>
val b = provider("b") as AbstractProvider<String>
val c = provider("c") as AbstractProvider<String>

val combinedAB = combinedProvider(a, b) { a, b -> a + b } as AbstractProvider<String>
val combinedBC = combinedProvider(b, c) { b, c -> b + c } as AbstractProvider<String>

assertContentEquals(
Array(5) { a.lock },
arrayOf(
a.lock, b.lock, c.lock,
combinedAB.lock, combinedBC.lock
)
)
}

@Test
fun testProviderObserver() {
var invoked = false
Expand Down

0 comments on commit 1e63383

Please sign in to comment.