You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I just refactored our old (untested) code that used to consume Queue::createPayloadUsing() directly to start using Laravel's Log\Context (Still a bit frustrated it's written as part of the Log domain; I would have put it under the Queue domain myself, as now it feels as if it can only be used for logging whereas we use it to share context that we use in the async processes...)
Anyway. As I said, we didn't test the code before, and I wanted to fix that now, but I'm not sure how I can test the fact that (de)hydation works as by default, our queue driver is set to sync.
This is an attempt, but obviously doesn't work:
// Theme pushes context so it's shared in async job processing as wellTheme::set('blue');
// Simulating pushed a job to the queueQueue::push(newTestQueueableJob());
Theme::set('red');
expect(Theme::get())->toBe('red'); // Success// I would have hoped this could trigger the context hydrationQueue::pop();
expect(Theme::get())->toBe('blue'); // Fail: the value is still red
For your reference, in our service provider we are (de)hydrating the theme. It does work as expected (emails dispatched from an async processed job, gets the right theme applied for instance); I'm just really unsure how I can test this propertly.
Basically, what I'm trying to test is:
1/ we push something to the queue
2/ we change the theme
3/ we process the job, and this job should actually still use the theme that was active when we pushed the job to the queue.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi,
I just refactored our old (untested) code that used to consume
Queue::createPayloadUsing()
directly to start using Laravel'sLog\Context
(Still a bit frustrated it's written as part of the Log domain; I would have put it under the Queue domain myself, as now it feels as if it can only be used for logging whereas we use it to share context that we use in the async processes...)Anyway. As I said, we didn't test the code before, and I wanted to fix that now, but I'm not sure how I can test the fact that (de)hydation works as by default, our queue driver is set to sync.
This is an attempt, but obviously doesn't work:
For your reference, in our service provider we are (de)hydrating the theme. It does work as expected (emails dispatched from an async processed job, gets the right theme applied for instance); I'm just really unsure how I can test this propertly.
Basically, what I'm trying to test is:
1/ we push something to the queue
2/ we change the theme
3/ we process the job, and this job should actually still use the theme that was active when we pushed the job to the queue.
Beta Was this translation helpful? Give feedback.
All reactions