Closed alghe-global closed 2 months ago
Please note, the tests should be multiple testing different sort of queries on the test database using the same event - normally, the setUp and tearDown should take care of having a clean database for each test, however, this is not what's observed.
Nevermind, ran once again and the file is created (appended *
to the search terms for egrep
) - it seems sleep 1
was too much (the tests ran too quickly). The error still persists, though seems unrelated to this issue. I tried without coroutines and two of the three tests that store events and operate queries still fail.
Closing as Won't fix
.
Just a note, I tried with TEST_DIRECTORY.delete()
instead of BoxStore.deleteAllFiles(TEST_DIRECTORY)
and the tests that were failing before now succeeded, though the tests that tested for empty data failed (as there was data populated).
Close as Won't fix
.
Running tests one by one is successful so there's something definitely running the tests all together that fails.
Ran out of solutions, this is clearly an issue with setUp()
and tearDown
() - reopening in hopes of an investigation from @greenrobot-team .
Team, I've uploaded run.log - this log demonstrates that the directory (TEST_DIRECTORY
) exists and that the database is created, however, the database is not cleaned up in between tests. What I think is going on:
You can tell by searching for the keyword "db" in run.log
file. You'll see before that no database exists, then for a period of time the database persists, then the database is deleted. What we should have observed is that the database gets created and deleted multiple times (for the setUp()
and tearDown()
executions) - however, this doesn't seem to be the case.
I couldn't reproduce this with objectbox-examples.
java.lang.IllegalArgumentException: ID is higher or equal to internal ID sequence: 1 (vs. 1). Use ID 0 (zero) to insert new entities.
This error means that one of your tests is inserting an entity with an ID set. My best guess is that the entity list that is used in your tests is not re-generated between tests. Note that on put()
ObjectBox will update an entity with the ID it was assigned.
Or put differently, try to make this a function that builds the list each time, not a variable that keeps the entities between tests:
val entities = MyEntitiesMockDataSource.entityList
Let me know if that works for you.
Indeed, using a function to generate the mock data works and tests pass successful. Thanks for your help!
A question before we close here so I can learn more about ObjectBox internals: it seems that ObjectBox is tracking state irrespective of entering data into the database (by the instantiation of Entities) - is this true? Otherwise, why would the put()
method fail if the database was destroyed and recreated for each of the test? Wouldn't the database start from scratch and simply accept the same IDs previously generated for the other tests too?
Wouldn't the database start from scratch and simply accept the same IDs previously generated for the other tests too?
By default, new entities must be put with ID 0. If an entity with an ID > 0 is put, the database assumes it exists and tries to update it. See https://docs.objectbox.io/getting-started#object-ids for more details.
So closing this then!
Is there an existing issue?
[x] I have searched existing issues
https://stackoverflow.com/questions/78168060/coroutine-tests-break-automatically-assigned-id-for-objectbox-entity-in-kotlin-j - opened by me
Build info
Steps to reproduce
id
contains
orequal
)setUp()
andtearDown()
as per documentation for a custom test db (locally)Expected behavior
All tests should pass due to database being setup and teared down from scratch for each test.
Actual behavior
Database is persisted across tests thus failing due to clashing entities.
PLEASE NOTE: I DO NOT want to enable
assignable = true
onid
.Debugging steps
I've ran the following command to see whether the test db is created and noticed only the directory is created (not the file) which means there is a single db used instead of a new created (after the previous is destroyed) for each test:
How to use
Code
This is sample code and may not necessarily represent the code with which the error was triggered.
Code
```kotlin @Entity data class Image( @Id var id: Long = 0, @Index var timestamp: Long? = null, var location: String? = null, var owner: String? = null, ) { @Backlink(to = "image") lateinit var users: ToManyLogs, stack traces
Logs
```console java.lang.IllegalArgumentException: ID is higher or equal to internal ID sequence: 1 (vs. 1). Use ID 0 (zero) to insert new entities. ```