Skip to content

feat: add warning if crud transactions are not completed #64

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

Merged
merged 10 commits into from
Oct 14, 2024

Conversation

DominicGBauer
Copy link
Contributor

@DominicGBauer DominicGBauer commented Oct 4, 2024

Description

This implements the same change from the JS SDK powersync-ja/powersync-js#254 where a warning is added to notify users that the crud transaction has not yet been completed.

Work Done

  • Added nextCrudItem function
  • Updated uploadAllCrud function to use nextCrudItem with a check for uncompleted crud transaction
  • Removed no longer used uploadCrudBatch
  • To make things more testable I needed to create interfaces to mock, as mocking classes requires the classes to be open which we do not want (https://mokkery.dev/docs/Guides/Mocking#final-classes).
  • In order to improve unit testing in Kotlin I have added the Mokkery library to handle mocking. The reason is that it appears to be one of two with mockative looking for maintainers.
  • I have also started to move away from using powerSyncQueries, which is defined in the persistence model, as it makes testing impossible and is not very intuitive for developers working on the project. It also doesn't really provide much of an advantage besides typing the queries which can be achieved differently as shown in the replacement code. Example of moving from this:
val firstEntry = internalDb.queries.getCrudFirstEntry().awaitAsOneOrNull()

            val first = CrudEntry.fromRow(
                CrudRow(
                    id = firstEntry.id.toString(),
                    data = firstEntry.data_!!,
                    txId = firstEntry.tx_id?.toInt()
                )
            )

to this:

        val crudItem = db.getOptional("SELECT id, tx_id, data FROM ${InternalTable.CRUD} ORDER BY id ASC LIMIT 1") { cursor ->
            CrudEntry.fromRow(
                CrudRow(
                    id = cursor.getString(0)!!,
                    txId = cursor.getString(1)?.toInt(),
                    data = cursor.getString(2)!!
                )
            )
        }

Testing

Added some unit tests, although they will need to be improved in future as they currently check for log output which is not ideal.

Unsure on how to reproduce this in the demo, however, the image below shows that the error would show (this happened when changing nextCrudItem.clientId == checkedCrudItem?.clientId to nextCrudItem.clientId != checkedCrudItem?.clientId). I have run the app and uploads are working as expected.

Nevermind this was due to a logic error:

This is currently happening in the demo and may be related to a bug I am busy diagnosing
image

@DominicGBauer DominicGBauer self-assigned this Oct 4, 2024
@DominicGBauer DominicGBauer marked this pull request as ready for review October 7, 2024 08:34
@DominicGBauer DominicGBauer changed the title WIP feat: add warning if crud transactions are not completed feat: add warning if crud transactions are not completed Oct 7, 2024
@DominicGBauer DominicGBauer requested a review from mugikhan October 9, 2024 15:51
Copy link
Contributor

@mugikhan mugikhan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work on adding some tests. Looks good to me.

@DominicGBauer DominicGBauer merged commit 726117e into main Oct 14, 2024
3 checks passed
@DominicGBauer DominicGBauer deleted the feat/add-warning-if-crud-tx-not-completed branch October 14, 2024 08:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants