[GH-ISSUE #446] [FEATURE REQUEST] Expose asynq context to facilitate client testing #203

Open
opened 2026-03-02 05:19:35 +03:00 by kerem · 2 comments
Owner

Originally created by @strobus on GitHub (May 1, 2022).
Original GitHub issue: https://github.com/hibiken/asynq/issues/446

Originally assigned to: @hibiken on GitHub.

Is your feature request related to a problem? Please describe.
I'm writing a system where I need careful tracking of tasks and their corresponding business objects, with the ability to query them. So I'm putting the task ID and other data in a database. My code naturally uses the asynq.GetTaskID(ctx) function to get the task ID. The issue I'm having is trying to write tests for this code. I have no way of creating a context that asynq.GetTaskID(ctx) will accept without some ugly hacks.

Describe the solution you'd like
I need the context package in the internal directory to be exposed externally. Alternatively we need to create a separate package with some simple functions to create a mock context.

Describe alternatives you've considered
Hacking using module introspection and reflection, which is very time consuming for what should be a simple exercise.

Additional context
I would be happy to work on a fix to this issue.

Originally created by @strobus on GitHub (May 1, 2022). Original GitHub issue: https://github.com/hibiken/asynq/issues/446 Originally assigned to: @hibiken on GitHub. **Is your feature request related to a problem? Please describe.** I'm writing a system where I need careful tracking of tasks and their corresponding business objects, with the ability to query them. So I'm putting the task ID and other data in a database. My code naturally uses the `asynq.GetTaskID(ctx)` function to get the task ID. The issue I'm having is trying to write tests for this code. I have no way of creating a context that `asynq.GetTaskID(ctx)` will accept without some ugly hacks. **Describe the solution you'd like** I need the `context` package in the `internal` directory to be exposed externally. Alternatively we need to create a separate package with some simple functions to create a mock context. **Describe alternatives you've considered** Hacking using module introspection and reflection, which is very time consuming for what should be a simple exercise. **Additional context** I would be happy to work on a fix to this issue.
Author
Owner

@hibiken commented on GitHub (May 2, 2022):

@strobus Thanks for opening this issue!
I think it makes sense to create a test utility package under /x/asynqtest.
PR is welcome!

<!-- gh-comment-id:1114898676 --> @hibiken commented on GitHub (May 2, 2022): @strobus Thanks for opening this issue! I think it makes sense to create a test utility package under `/x/asynqtest`. PR is welcome!
Author
Owner

@kayandra commented on GitHub (Nov 22, 2023):

hello @hibiken I'm also interested in having an asynqtest module exposed so it making testing easier. I couldn't figure out how @strobus made hacks for testing processors, I believe we should have a mocked client/worker that we can use to test tasks.

<!-- gh-comment-id:1823574831 --> @kayandra commented on GitHub (Nov 22, 2023): hello @hibiken I'm also interested in having an asynqtest module exposed so it making testing easier. I couldn't figure out how @strobus made hacks for testing processors, I believe we should have a mocked client/worker that we can use to test tasks.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/asynq#203
No description provided.