dumbmatter / fakeIndexedDB

A pure JS in-memory implementation of the IndexedDB API
Apache License 2.0
562 stars 69 forks source link

[BUG] Invalid behavior for concurrent insertion data #78

Closed vitonsky closed 1 year ago

vitonsky commented 1 year ago

I have test

https://github.com/translate-tools/linguist/blob/4da90de9e406442ab78df591bad04d7e6b93cdf3/src/requests/backend/translations/data.test.ts#L22-L30

If you replace this code

    const identifiers: number[] = [];
    for (const translation of translations) {
        const id = await translationsStore.addEntry(translation);
        identifiers.push(id);
    }

to this

    const identifiers = await Promise.all(translations.map((translation) => translationsStore.addEntry(translation)));

test will fail, identifiers will not match.

I suppose cause in concurrent inserting data. This behavior are gross mismatch to standard.

Let's fix it, probably we can just use some semafor to insert items one by one and ensure unique id for each entry with considering a insert order.

dumbmatter commented 1 year ago

That is strange, there are already a ton of tests for basic functionality. For example https://github.com/dumbmatter/fakeIndexedDB/blob/c23a612181f267df499d46190875d6974b7589c4/src/test/web-platform-tests/IndexedDB/idbobjectstore_add6.htm

So possibly it is a more subtle bug than it seems? A minimal reproduction would be appreciated.