Skip to content
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

[BUG] State Flow From launchPagingStore Does Not Reflect Latest Writes in Mutable Store #602

Open
matt-ramotar opened this issue Jan 28, 2024 · 0 comments · May be fixed by #630
Open

[BUG] State Flow From launchPagingStore Does Not Reflect Latest Writes in Mutable Store #602

matt-ramotar opened this issue Jan 28, 2024 · 0 comments · May be fixed by #630
Assignees
Labels
bug Something isn't working

Comments

@matt-ramotar
Copy link
Collaborator

Summary

Updates made through write operations to mutable store are not being accurately reflected in the StateFlow returned by launchPagingStore.

Description

Expected behavior is any write operation to a mutable store should be observed in the StateFlow emitted by launchPagingStore. However, it appears that after performing a write operation, the state flow still reflects the state of the store prior to the write.

Steps To Reproduce

  1. Create and initialize a mutable store.
  2. Invoke launchPagingStore on the mutable store.
  3. Perform read operations on the mutable store and observe correct behavior.
  4. Perform a write operation on the mutable store.
  5. Observe the state flow from launchPagingStore does not reflect the changes made by the write operation.
  6. Read directly from the mutable store and observe correct value.

Failing Test

  @Test
   fun multipleKeysWithReadsAndWrites() = testScope.runTest {
        val api = FakePostApi()
        val db = FakePostDatabase(userId)
        val factory = PostStoreFactory(api = api, db = db)
        val mutableStore = factory.create()

        val key1 = PostKey.Cursor("1", 10)
        val key2 = PostKey.Cursor("11", 10)
        val keys = flowOf(key1, key2)

        val stateFlow = mutableStore.launchPagingStore(this, keys)
        stateFlow.test {
            val initialState = awaitItem()
            assertIs<StoreReadResponse.Initial>(initialState)
            val loadingState = awaitItem()
            assertIs<StoreReadResponse.Loading>(loadingState)
            val loadedState1 = awaitItem()
            assertIs<StoreReadResponse.Data<PostData.Feed>>(loadedState1)
            val data1 = loadedState1.value
            assertEquals(10, data1.posts.size)
            val loadedState2 = awaitItem()
            assertIs<StoreReadResponse.Data<PostData.Feed>>(loadedState2)
            val data2 = loadedState2.value
            assertEquals(20, data2.posts.size)
        }
        mutableStore.write(StoreWriteRequest.of(PostKey.Single("2"), PostData.Post("2", "2-modified")))
        stateFlow.test {
            val loadedState3 = awaitItem()
            assertIs<StoreReadResponse.Data<PostData.Feed>>(loadedState3)
            val data3 = loadedState3.value
            assertEquals(20, data3.posts.size)
            assertEquals("2-modified", data3.posts[1].title) // Actual is "2"
        }

Investigation So Far

  • First thought was stream from mutable store is not correctly observing updates. However, I verified stream is correctly observing updates.
  • Reading from store appears to be working correctly.
  • Suspect root cause is how we are handling streams for successive keys. Will dig in later this week.
@matt-ramotar matt-ramotar added the bug Something isn't working label Jan 28, 2024
@matt-ramotar matt-ramotar self-assigned this Jan 28, 2024
@matt-ramotar matt-ramotar mentioned this issue Feb 14, 2024
8 tasks
This was referenced Mar 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: 👀 In review
1 participant