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

fix(kv): throw error if already closed #21459

Merged
merged 14 commits into from
Dec 5, 2023

Conversation

raashidanwar
Copy link
Contributor

Description

If KV is closed and tries to listen queue should throw an error.

Issue


queueTest("throw error if already closed", async (db) => {
db.close();
await assertThrows(
Copy link
Member

Choose a reason for hiding this comment

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

Use assertRejects here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Previously, I used assertRejects only, but it got failed 😅.

I don't know, test cases are running fine on my system but failed here.

await assertRejects(
async () => {
await db.listenQueue(() => {
resolve();
Copy link
Member

Choose a reason for hiding this comment

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

This resolve is not needed, since you don't destructure promise from Promise.withResolvers() it's useless in this context. I think you can give it an empty callback.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

First, I did the same, but it failed.

Did it again.

Copy link
Contributor

@igorzi igorzi left a comment

Choose a reason for hiding this comment

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

Accepted too quickly, the test is failing

db.close();
await assertRejects(
async () => {
await db.listenQueue(() => {});
Copy link
Contributor

Choose a reason for hiding this comment

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

normally listenQueue is called without await. can we test here that it throws without await?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Locally, it's failing without await. listenQueue return promise.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed, I handled using try-catch :).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My test cases are passing, but something else is failing @igorzi can you please check?

Comment on lines 8 to 11
await db.listenQueue(() => {});
} catch (e) {
assertEquals(e.message, "already closed");
}
Copy link
Contributor

Choose a reason for hiding this comment

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

What if it doesn't throw? Right now the test will pass if it doesn't throw.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice catch :).
Added assertFalse(false) after line 9 so if doesn't throw it will fail.

@igorzi igorzi merged commit cac1726 into denoland:main Dec 5, 2023
14 checks passed
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.

None yet

3 participants