@@ -7,23 +7,23 @@ class ConfigurationTest < ActiveSupport::TestCase
7
7
end
8
8
9
9
assert_equal 2 , configuration . configured_processes . count
10
- assert_processes configuration , :worker , 1 , queues : [ "*" ]
10
+ assert_processes configuration , :worker , 1 , queues : "*"
11
11
assert_processes configuration , :dispatcher , 1 , batch_size : SolidQueue ::Configuration ::DISPATCHER_DEFAULTS [ :batch_size ]
12
12
end
13
13
14
14
test "default configuration when config given doesn't include any configuration" do
15
- configuration = SolidQueue ::Configuration . new ( load_from : { random_wrong_key : :random_value } )
15
+ configuration = SolidQueue ::Configuration . new ( random_wrong_key : :random_value )
16
16
17
17
assert_equal 2 , configuration . configured_processes . count
18
- assert_processes configuration , :worker , 1 , queues : [ "*" ]
18
+ assert_processes configuration , :worker , 1 , queues : "*"
19
19
assert_processes configuration , :dispatcher , 1 , batch_size : SolidQueue ::Configuration ::DISPATCHER_DEFAULTS [ :batch_size ]
20
20
end
21
21
22
22
test "default configuration when config given is empty" do
23
- configuration = SolidQueue ::Configuration . new ( load_from : { } )
23
+ configuration = SolidQueue ::Configuration . new ( config_file : Rails . root . join ( "config/empty_configuration.yml" ) )
24
24
25
25
assert_equal 2 , configuration . configured_processes . count
26
- assert_processes configuration , :worker , 1 , queues : [ "*" ]
26
+ assert_processes configuration , :worker , 1 , queues : "*"
27
27
assert_processes configuration , :dispatcher , 1 , batch_size : SolidQueue ::Configuration ::DISPATCHER_DEFAULTS [ :batch_size ]
28
28
end
29
29
@@ -34,17 +34,22 @@ class ConfigurationTest < ActiveSupport::TestCase
34
34
assert_processes configuration , :dispatcher , 1
35
35
end
36
36
37
+ test "read configuration from provided file" do
38
+ configuration = SolidQueue ::Configuration . new ( config_file : Rails . root . join ( "config/alternative_configuration.yml" ) )
39
+
40
+ assert 3 , configuration . configured_processes . count
41
+ assert_processes configuration , :worker , 3 , processes : 1 , polling_interval : 0.1 , queues : %w[ queue_1 queue_2 queue_3 ] , threads : [ 1 , 2 , 3 ]
42
+ end
43
+
37
44
test "provide configuration as a hash and fill defaults" do
38
45
background_worker = { queues : "background" , polling_interval : 10 }
39
46
dispatcher = { batch_size : 100 }
40
- config_as_hash = { workers : [ background_worker , background_worker ] , dispatchers : [ dispatcher ] }
41
- configuration = SolidQueue ::Configuration . new ( load_from : config_as_hash )
47
+ configuration = SolidQueue ::Configuration . new ( workers : [ background_worker , background_worker ] , dispatchers : [ dispatcher ] )
42
48
43
49
assert_processes configuration , :dispatcher , 1 , polling_interval : SolidQueue ::Configuration ::DISPATCHER_DEFAULTS [ :polling_interval ] , batch_size : 100
44
- assert_processes configuration , :worker , 2 , queues : [ "background" ] , polling_interval : 10
50
+ assert_processes configuration , :worker , 2 , queues : "background" , polling_interval : 10
45
51
46
- config_as_hash = { workers : [ background_worker , background_worker ] }
47
- configuration = SolidQueue ::Configuration . new ( load_from : config_as_hash )
52
+ configuration = SolidQueue ::Configuration . new ( workers : [ background_worker , background_worker ] )
48
53
49
54
assert_processes configuration , :dispatcher , 0
50
55
assert_processes configuration , :worker , 2
@@ -57,20 +62,24 @@ class ConfigurationTest < ActiveSupport::TestCase
57
62
58
63
test "mulitple workers with the same configuration" do
59
64
background_worker = { queues : "background" , polling_interval : 10 , processes : 3 }
60
- config_as_hash = { workers : [ background_worker ] }
61
- configuration = SolidQueue ::Configuration . new ( load_from : config_as_hash )
65
+ configuration = SolidQueue ::Configuration . new ( workers : [ background_worker ] )
62
66
63
67
assert_equal 3 , configuration . configured_processes . count
64
- assert_processes configuration , :worker , 3 , queues : [ "background" ] , polling_interval : 10
68
+ assert_processes configuration , :worker , 3 , queues : "background" , polling_interval : 10
65
69
end
66
70
67
71
private
68
72
def assert_processes ( configuration , kind , count , **attributes )
69
- processes = configuration . configured_processes . select { |p | p . kind == kind } . map ( & :instantiate )
73
+ processes = configuration . configured_processes . select { |p | p . kind == kind }
70
74
assert_equal count , processes . size
71
75
72
- attributes . each do |attr , value |
73
- assert_equal value , processes . map { |p | p . public_send ( attr ) } . first
76
+ attributes . each do |attr , expected_value |
77
+ value = processes . map { |p | p . attributes . fetch ( attr ) }
78
+ unless expected_value . is_a? ( Array )
79
+ value = value . first
80
+ end
81
+
82
+ assert_equal expected_value , value
74
83
end
75
84
end
76
85
end
0 commit comments