TestStore expects shared state to be nil when state was set to nil in an independent test showing the same destination #3554
Replies: 6 comments
-
Hello @dominikmayer, Why it is not working as test suit because you store mock in memory (static let) which has reference What I would suggest you not to store mocks. You will see problem will be solved if you change your mock as below
|
Beta Was this translation helpful? Give feedback.
-
Hi @OguzYuuksel. Thanks for looking into that. Yeah, the first test initiating the shared journal with the default value is probably what's happening here. I just think this is a bug. The Regarding your suggestion. Isn't it almost the same as my definition of
I changed to a |
Beta Was this translation helpful? Give feedback.
-
@dominikmayer |
Beta Was this translation helpful? Give feedback.
-
Ah, right. Missed that. This does solve the issue. Thank you. |
Beta Was this translation helpful? Give feedback.
-
I've been thinking about this more. So I agree that it was probably not smart to use a static constant as it will not be reset during tests. But still: The tests are running serially not in parallel. And the shared variable was set in a test that should be running independent of the other test. So even if the other test initiates the shared variable, shouldn't the explicit setting in the brittle test change that? |
Beta Was this translation helpful? Give feedback.
-
Hi @dominikmayer, the failure you are experiencing is expected as @OguzYuuksel described. And it doesn't matter if the tests are being run serially/in parallel because there is only one single process that runs the full test suite. So the first test runs, touches This kind of failure would happen without TCA or the sharing library since Swift Testing runs all tests in the a single process. This is in contrast to XCTest, which spins up a new process for each test. In that kind of set up you would not have experienced this failure. Since this isn't an issue with the library I am going to convert it to a discussion. Please feel free to continue the conversation over there! |
Beta Was this translation helpful? Give feedback.
-
Description
I have the following struct, which is shared in memory:
I then have a feature that can show two other features, one of which contains the shared journal:
And the feature that shows them:
Now when trying to test this setup then the test passes when run on its own but fails when run together with another, independent test, that
a) shows the same destination as will be set in the brittle test and
b) sets the shared journal to
nil
.This happens even when the test are run in
.serialized
mode.Checklist
main
branch of this package.Expected behavior
The test yields the same result whether run independently or as part of a suite.
Actual behavior
Test passes when run independently but not when run as part of a test suite.
Reproducing project
https://github.com/dominikmayer/TCA-Shared-Test-Issue/
The Composable Architecture version information
1.15.2
Destination operating system
macOS 15.0
Xcode version information
Version 16.0 (16A242d)
Swift Compiler version information
Beta Was this translation helpful? Give feedback.
All reactions