3
3
class MultishardingTest < ActiveSupport ::TestCase
4
4
test "jobs are enqueued in the right shard" do
5
5
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
12
7
AddToBufferJob . perform_later "hey!"
13
8
ShardTwoJob . perform_later "coucou!"
14
9
end
15
10
end
16
11
end
17
12
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
+
18
19
test "jobs are enqueued for later in the right shard" do
19
20
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
26
22
AddToBufferJob . set ( wait : 1 ) . perform_later "hey!"
27
23
ShardTwoJob . set ( wait : 1 ) . perform_later "coucou!"
28
24
end
@@ -38,12 +34,7 @@ class MultishardingTest < ActiveSupport::TestCase
38
34
]
39
35
40
36
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
47
38
ActiveJob . perform_all_later ( active_jobs )
48
39
end
49
40
end
0 commit comments