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(wait-for-job): add catch block and emit error #749

Merged
merged 8 commits into from
Sep 16, 2021

Conversation

roggervalf
Copy link
Collaborator

@roggervalf roggervalf commented Sep 14, 2021

fixes #623, #36, #239

@@ -289,6 +292,11 @@ export class Worker<
this.keys.active,
opts.drainDelay,
);
} catch (error) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

don't really know how to make a test for this 🤔

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the only way to do it is by monkey patching client so that brpoplpush always throws an exception. So in the test overwrite this.blockingConnection.client with a stub. Sinon is the best for this, as we are already using it in other tests.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

so after adding the delay after if statement seems like in our test we are getting into that block, so I had to stub the delay method

@@ -289,6 +292,11 @@ export class Worker<
this.keys.active,
opts.drainDelay,
);
} catch (error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the only way to do it is by monkey patching client so that brpoplpush always throws an exception. So in the test overwrite this.blockingConnection.client with a stub. Sinon is the best for this, as we are already using it in other tests.

@@ -289,6 +292,11 @@ export class Worker<
this.keys.active,
opts.drainDelay,
);
} catch (error) {
if ((error as Error).message !== CONNECTION_CLOSED_ERROR_MSG) {
await delay(2000);
Copy link
Contributor

Choose a reason for hiding this comment

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

Just wondering, shouldn't we always delay? because otherwise if the error persists for a long time we will produce an endless loop here that may consume all CPU.
Also it would be great to refactor this magic number into a constant.

@@ -323,7 +325,7 @@ describe('repeat', function() {
});

it('should remove repeated job when using removeOnComplete', async function() {
this.timeout(200000);
this.timeout(20000);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

these changes are because we are adding a higher number but we could choose a lower one in those cases, even when these changes are going to fail because of a change, test should not get stopped for too much time

} finally {
this.waiting = false;
}
return jobId;
}

async delay(): Promise<void> {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I need to do this in order to stub this function

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, but we can keep it private.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

when it is prívate I cannot stub it :/

Copy link
Contributor

@manast manast Sep 15, 2021

Choose a reason for hiding this comment

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

aha, thats right. Then just a comment to explain why it is needed is enough.

@@ -150,7 +150,9 @@ export class RedisConnection extends EventEmitter {
await this._client.quit();
}
} catch (error) {
handleError(error);
if (isNotConnectionError(error)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice change. It is always better to have explicit functions instead of "handle" which can be anything. 👍

@roggervalf roggervalf merged commit b407f9a into master Sep 16, 2021
@roggervalf roggervalf deleted the fix/wait-for-job branch September 16, 2021 01:19
github-actions bot pushed a commit that referenced this pull request Sep 16, 2021
## [1.46.7](v1.46.6...v1.46.7) (2021-09-16)

### Bug Fixes

* **wait-for-job:** add catch block and emit error ([#749](#749)) ([b407f9a](b407f9a))
@github-actions
Copy link

🎉 This PR is included in version 1.46.7 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Promise rejection error in waitForJob
2 participants