-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Raise non-fatal error if node called outside main thread #386
Open
LachlanMcKee
wants to merge
1
commit into
badoo:master
Choose a base branch
from
LachlanMcKee:raise-error-if-rib-called-off-main-thread
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -89,11 +89,13 @@ class NodeTest { | |
private fun createNode( | ||
buildParams: BuildParams<Nothing?> = testBuildParams(), | ||
viewFactory: TestViewFactory? = [email protected], | ||
isOnMainThread: Boolean = true, | ||
plugins: List<Plugin> = emptyList() | ||
): Node<TestView> = Node( | ||
buildParams = buildParams, | ||
viewFactory = viewFactory, | ||
plugins = plugins, | ||
isOnMainThreadFunc = { isOnMainThread }, | ||
retainedInstanceStore = retainedInstanceStore | ||
) | ||
|
||
|
@@ -334,7 +336,10 @@ class NodeTest { | |
directChild.attachChildNode(grandChild) | ||
node.attachChildNode(directChild) | ||
|
||
assertEquals(Lifecycle.State.CREATED, grandChild.lifecycleManager.externalLifecycle.currentState) | ||
assertEquals( | ||
Lifecycle.State.CREATED, | ||
grandChild.lifecycleManager.externalLifecycle.currentState | ||
) | ||
} | ||
|
||
@Test | ||
|
@@ -365,7 +370,10 @@ class NodeTest { | |
directChild.attachChildNode(grandChild) | ||
node.attachChildNode(directChild) | ||
|
||
assertEquals(Lifecycle.State.STARTED, grandChild.lifecycleManager.externalLifecycle.currentState) | ||
assertEquals( | ||
Lifecycle.State.STARTED, | ||
grandChild.lifecycleManager.externalLifecycle.currentState | ||
) | ||
} | ||
|
||
@Test | ||
|
@@ -399,7 +407,10 @@ class NodeTest { | |
directChild.attachChildNode(grandChild) | ||
node.attachChildNode(directChild) | ||
|
||
assertEquals(Lifecycle.State.RESUMED, grandChild.lifecycleManager.externalLifecycle.currentState) | ||
assertEquals( | ||
Lifecycle.State.RESUMED, | ||
grandChild.lifecycleManager.externalLifecycle.currentState | ||
) | ||
} | ||
|
||
@Ignore("This should be reworked to match new mechanism") | ||
|
@@ -604,4 +615,21 @@ class NodeTest { | |
|
||
verify(retainedInstanceStore, never()).removeAll(node.identifier) | ||
} | ||
|
||
@Test | ||
fun `WHEN node created outside main thread THEN error is raised`() { | ||
val errorHandler = mock<RIBs.ErrorHandler>() | ||
RIBs.clearErrorHandler() | ||
RIBs.errorHandler = errorHandler | ||
|
||
node = createNode(viewFactory = viewFactory, isOnMainThread = false) | ||
|
||
verify(errorHandler).handleNonFatalError( | ||
errorMessage = "Node interacted with outside main thread. " + | ||
"Node: com.badoo.ribs.core.Node, " + | ||
"method: init, " + | ||
"thread: SDK 32 Main Thread", | ||
throwable = null | ||
) | ||
} | ||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to make it overridable for every junit tested Node in our codebase, which does not seem achievable.
In general makes sense (we do not support any multi-threading anyway, comparing to Appyx which is guarded by coroutines context and/or atomic mutable states).
Let's take a default implementation from
RIBs
singleton and addRIBs.isOnMainThread
and try to override it somehow in tests, potentially in NodeTestHelper and InteractorTestHelper? But the problem there that we do not reset them. (Maybe it is ok just to give up and override always without reset).