CBL C SDK - Kotlin Multiplatform - Feedback/Questions

I just finished adding support for Linux and Windows to my Kotlin Multiplatform Couchbase Lite bindings, utilizing the CBL C SDK. (Previously I’ve completed support for Android, JVM, iOS, and macOS via the Java and ObjC SDKs.) All platforms are running the same common tests, based on the Java SDK public API tests. There are just a few tests that are failing, a couple edge cases for blobs, and one other I’d like to clarify if it’s a bug.

The test is DatabaseTest.testDeleteAlreadyDeletedDoc(), which fails here, where doc1b.sequence equals 3 after deletion, instead of the expected 2.

Here's the C code that fails the test (ported from Kotlin, so there may be typos, as I haven't run it directly in C):
CBLDocument* doc = CBLDocument_CreateWithID(FLSTR("doc1"));
FLMutableDict props = CBLDocument_MutableProperties(doc);
FLMutableDict_SetString(props, FLSTR("firstName"), FLSTR("Daniel"));
FLMutableDict_SetString(props, FLSTR("lastName"), FLSTR("Tiger"));

CBLDatabase* db = CBLDatabase_Open(FLSTR("test"), CBLDatabaseConfiguration_Default(), null);
CBLDatabase_SaveDocument(db, doc, null);

// Get two doc1 document objects (doc1a and doc1b):
CBLDocument* doc1a = CBLDatabase_GetDocument(db, FLSTR("doc1"), null);
CBLDocument* doc1b = CBLDocument_MutableCopy(CBLDatabase_GetDocument(db, FLSTR("doc1"), null));

// doc1a.sequence = 1
// doc1b.sequence = 1

// Delete doc1a:
CBLDatabase_DeleteDocument(db, doc1a, null);
assert(2 == CBLDocument_Sequence(doc1a));
assert(null == CBLDatabase_GetDocument(db, CBLDocument_ID(doc), null));

// doc1a.sequence = 2
// doc1b.sequence = 1

// Delete doc1b:
CBLDatabase_DeleteDocument(db, doc1b, null);
//!! fails here, doc1b.sequence = 3
assert(2 == CBLDocument_Sequence(doc1b));
assert(null == CBLDatabase_GetDocument(db, CBLDocument_ID(doc), null));

This seems like a bug. It won’t have disastrous consequences but it should be fixed nonetheless.

Under what circumstances is that test failing?

All of those tests are run after every build, on all of the platforms (Android, Linux, MacOS, Windows). There are, most definitely, some flaky tests: I track them. I don’t see testDeleteAlreadyDeletedDoc in the list…

It’s the CBL C SDK where the test fails on both Linux and Windows. It works as expected with the Java and ObjC SDKs.

Interesting, I found the equivalently named test in the C SDK and it is actually checking for sequence = 3, rather than sequence = 2, as the other SDKs are (Java, ObjC, Swift). It’s using the same doc reference to delete twice though, rather than a mutable copy as the other SDKs and my C code above do.

The test actually looks more like the test testDeleteSameDocTwice() in ObjC and Swift (doesn’t exist in Java). So it does seem correct for the same document reference’s sequence to increment again if deleted a second time. But a mutable copy is expected to only increment by one, not two (or maybe the expectation is for the sequence to be the same as the first deletion, not clear which is the case).

Got it. Thanks @jeff.lockhart . Will fix the test.

Filed CBL-3749

This turns out not a test issue. When looking closely, the test in C and Android are bit different. On Android, the test is using another instance of the doc to delete which is actually causing a conflict internally. As the delete mode is last-write-win, the code optimize that by detecting the conflict and loading the current rev (deleted) instead of doing another revision (deleted) save.

I’m taking my comment back. CBL-C doesn’t implement the same optimization so basically it does save another deleted rev.