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

API to simulate QuotaExceededError #51

Open
nolanlawson opened this issue Jul 2, 2020 · 7 comments
Open

API to simulate QuotaExceededError #51

nolanlawson opened this issue Jul 2, 2020 · 7 comments

Comments

@nolanlawson
Copy link
Contributor

Similar to #50, it would be awesome for fakeindexeddb to have a way to simulate the storage device running out of space and throwing a QuotaExceededError.

Currently this is really hard to repro, even in a browser (it's recommended to create a separate volume and start Chrome with that volume). Having it in fakeindexeddb would be extremely convenient.

Something like:

indexedDB.__simulateQuotaExceeded = true // false by default
@GuilleW
Copy link

GuilleW commented Jul 4, 2020

With extension, a way to test all error when opening database, open transaction, etc ... will be useful too.

@GuilleW
Copy link

GuilleW commented Jul 4, 2020

Something like :

indexedDB.__simulate = QUOTA_EXCEEDED_ERROR
// unit test ...

indexedDB.__simulate = CLOSE_EVENT
// unit test ...

Not API breaker and help unit testing.

@Quelklef
Copy link

Quelklef commented Jul 4, 2020

Is the idea with __simulateQuotaExceeded = true to have fakeindexeddb throw an exception on the real-world quota amount?

Seems to me like it would be more useful to set the quota amount for testing (indexedDB.__quota = 50; // mb, default Infinity) or to have some way to manually throw the error (indexedDB.__throwQuotaExceeded()).

@nolanlawson
Copy link
Contributor Author

@Quelklef This would require fakeindexeddb to actually calculate how much "storage" it's using, which would be computationally expensive and inaccurate since it's all in-memory.

The problem with throwQuotaExceeded() as a function is that, to truly simulate what a browser does, the error should be thrown during a readwrite transaction (if the quota is exceeded after opening) or in the indexedDB.open request (if the quota is already exceeded before even opening the database).

@Quelklef
Copy link

Quelklef commented Jul 5, 2020

@nolanlawson Okay, that all makes sense. What is the intended behaviour of indexedDB.__simulateQuotaExceeded = true;, then? To throw on the next open request?

@nolanlawson
Copy link
Contributor Author

That's what I was thinking – that way, you could test throwing both on open() and on a readwrite transaction, by just setting that flag right before you do the transaction.

@Quelklef
Copy link

Quelklef commented Jul 5, 2020

Got it. IMO, it reads a little like setting a config option rather than setting up for imminent behaviour. Compare it to something like .__prepareExceedQuota() or another name of the likes.

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

No branches or pull requests

3 participants