33class MultishardingTest < ActiveSupport ::TestCase
44 test "jobs are enqueued in the right shard" do
55 assert_difference -> { SolidQueue ::Job . count } , 1 do
6- assert_difference -> do
7- ActiveRecord ::Base . connected_to (
8- shard : :queue_shard_two
9- ) { SolidQueue ::Job . count }
10- end ,
11- 1 do
6+ assert_difference -> { connected_to_shard_two { SolidQueue ::Job . count } } , 1 do
127 AddToBufferJob . perform_later "hey!"
138 ShardTwoJob . perform_later "coucou!"
149 end
1510 end
1611 end
1712
13+ test "jobs are enqueued in the right shard no matter the primary shard" do
14+ assert_difference -> { SolidQueue ::Job . count } , 1 do
15+ change_active_shard_to ( :queue_shard_two ) { AddToBufferJob . perform_later "hey!" }
16+ end
17+ end
18+
1819 test "jobs are enqueued for later in the right shard" do
1920 assert_difference -> { SolidQueue ::ScheduledExecution . count } , 1 do
20- assert_difference -> do
21- ActiveRecord ::Base . connected_to (
22- shard : :queue_shard_two
23- ) { SolidQueue ::ScheduledExecution . count }
24- end ,
25- 1 do
21+ assert_difference -> { connected_to_shard_two { SolidQueue ::ScheduledExecution . count } } , 1 do
2622 AddToBufferJob . set ( wait : 1 ) . perform_later "hey!"
2723 ShardTwoJob . set ( wait : 1 ) . perform_later "coucou!"
2824 end
@@ -38,12 +34,7 @@ class MultishardingTest < ActiveSupport::TestCase
3834 ]
3935
4036 assert_difference -> { SolidQueue ::Job . count } , 2 do
41- assert_difference -> do
42- ActiveRecord ::Base . connected_to (
43- shard : :queue_shard_two
44- ) { SolidQueue ::Job . count }
45- end ,
46- 2 do
37+ assert_difference -> { connected_to_shard_two { SolidQueue ::Job . count } } , 2 do
4738 ActiveJob . perform_all_later ( active_jobs )
4839 end
4940 end
0 commit comments