sidekiq/testing - ability to run some configured server middleware chain on jobs recorded #5734
Replies: 3 comments 4 replies
-
Are you looking for https://github.com/mperham/sidekiq/blob/b12300fc137e43b11bd127ec83b94d95852d6f32/lib/sidekiq/testing.rb#L53-L57 ? |
Beta Was this translation helpful? Give feedback.
-
Sidekiq::Testing.server_middleware.use MyMiddleware
Sidekiq::Testing.inline! do
MyJob.perform_async
end |
Beta Was this translation helpful? Give feedback.
-
Not quite, as I want to assert jobs queued and their arguments, not run them. So I'm using If I have a client middleware that makes all strings uppercase and a server middleware that makes them all lower case again: MyJob.perform_later("cats", "dogs")
# test would fail
assert_equal MyJob.jobs.first["args"], ["cats", "dogs"]
# actual: ["CATS", "DOGS"] I would expect that to pass - I'm testing the arguments I'm creating the job with, not the arguments as they're stored in redis |
Beta Was this translation helpful? Give feedback.
-
When using a client/server set of middleware that modify arguments in some way (supporting extra serialization for example), the client middleware runs and modifies the arguments, but the jobs stored by
sidekiq/testing
to assert against don't seem to have a way of running the server middleware against them.This makes it awkward to test, because you're testing for the serialized args format, not what the Job would receive.
I'd be interested in implementing this somewhere in https://github.com/mperham/sidekiq/blob/main/lib/sidekiq/testing.rb
Would this be something you'd consider @mperham?
If so how would you suggest enabling this, as it would potentially be a breaking change in a test suite. Maybe
Sidekiq::Testing.fake!(server_middleware: true)
/Sidekiq::Testing.fake_options = { server_middleware: true }
or something along those lines?Beta Was this translation helpful? Give feedback.
All reactions