aws-flow 2.3.1 → 2.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +8 -8
  2. data/aws-flow.gemspec +3 -2
  3. data/bin/aws-flow-ruby +1 -1
  4. data/bin/aws-flow-utils +5 -0
  5. data/lib/aws/decider.rb +7 -0
  6. data/lib/aws/decider/async_retrying_executor.rb +1 -1
  7. data/lib/aws/decider/data_converter.rb +161 -0
  8. data/lib/aws/decider/decider.rb +27 -14
  9. data/lib/aws/decider/flow_defaults.rb +28 -0
  10. data/lib/aws/decider/implementation.rb +0 -1
  11. data/lib/aws/decider/options.rb +2 -2
  12. data/lib/aws/decider/starter.rb +207 -0
  13. data/lib/aws/decider/task_poller.rb +4 -4
  14. data/lib/aws/decider/utilities.rb +38 -0
  15. data/lib/aws/decider/version.rb +1 -1
  16. data/lib/aws/decider/worker.rb +8 -7
  17. data/lib/aws/decider/workflow_definition_factory.rb +1 -1
  18. data/lib/aws/runner.rb +146 -65
  19. data/lib/aws/templates.rb +4 -0
  20. data/lib/aws/templates/activity.rb +69 -0
  21. data/lib/aws/templates/base.rb +87 -0
  22. data/lib/aws/templates/default.rb +146 -0
  23. data/lib/aws/templates/starter.rb +256 -0
  24. data/lib/aws/utils.rb +270 -0
  25. data/spec/aws/decider/integration/activity_spec.rb +7 -1
  26. data/spec/aws/decider/integration/data_converter_spec.rb +39 -0
  27. data/spec/aws/decider/integration/integration_spec.rb +12 -5
  28. data/spec/aws/decider/integration/options_spec.rb +23 -9
  29. data/spec/aws/decider/integration/starter_spec.rb +209 -0
  30. data/spec/aws/decider/unit/data_converter_spec.rb +276 -0
  31. data/spec/aws/decider/unit/decider_spec.rb +1360 -1386
  32. data/spec/aws/decider/unit/options_spec.rb +21 -22
  33. data/spec/aws/decider/unit/retry_spec.rb +8 -0
  34. data/spec/aws/decider/unit/starter_spec.rb +159 -0
  35. data/spec/aws/runner/integration/runner_integration_spec.rb +2 -3
  36. data/spec/aws/runner/unit/runner_unit_spec.rb +128 -38
  37. data/spec/aws/templates/unit/activity_spec.rb +89 -0
  38. data/spec/aws/templates/unit/base_spec.rb +72 -0
  39. data/spec/aws/templates/unit/default_spec.rb +141 -0
  40. data/spec/aws/templates/unit/starter_spec.rb +271 -0
  41. data/spec/spec_helper.rb +9 -11
  42. metadata +41 -4
@@ -47,11 +47,11 @@ describe AWS::Flow::ActivityRegistrationOptions do
47
47
  default_task_start_to_close_timeout: "NONE",
48
48
  default_task_priority: "0",
49
49
  default_task_list: "USE_WORKER_TASK_LIST",
50
- data_converter: FlowConstants.default_data_converter
50
+ data_converter: FlowConstants.data_converter
51
51
  }
52
52
  # We first compare and remove the following values because these objects have issues
53
53
  # when we sort the values array below
54
- full_options.delete(:data_converter) == expected.delete(:data_converter)
54
+ full_options.delete(:data_converter).should be_kind_of(expected.delete(:data_converter).class)
55
55
  full_options.keys.sort.should == expected.keys.sort
56
56
  full_options.values.sort.should == expected.values.sort
57
57
  end
@@ -82,11 +82,12 @@ describe AWS::Flow::ActivityRegistrationOptions do
82
82
  prefix_name: "FooActivity",
83
83
  manual_completion: true,
84
84
  heartbeat_timeout: "10",
85
- data_converter: FlowConstants.default_data_converter
85
+ data_converter: FlowConstants.data_converter
86
86
  }
87
87
  # We first compare and remove the following values because these objects have issues
88
88
  # when we sort the values array below
89
- [:data_converter, :manual_completion].each { |x| full_options.delete(x).should == expected.delete(x) }
89
+ full_options.delete(:data_converter).should be_kind_of(expected.delete(:data_converter).class)
90
+ full_options.delete(:manual_completion).should == expected.delete(:manual_completion)
90
91
  full_options.keys.sort.should == expected.keys.sort
91
92
  full_options.values.sort.should == expected.values.sort
92
93
  end
@@ -139,11 +140,12 @@ describe AWS::Flow::WorkflowRegistrationOptions do
139
140
  default_task_list: "USE_WORKER_TASK_LIST",
140
141
  default_task_priority: "0",
141
142
  tag_list: [],
142
- data_converter: FlowConstants.default_data_converter
143
+ data_converter: FlowConstants.data_converter
143
144
  }
144
145
  # We first compare and remove the following values because these objects have issues
145
146
  # when we sort the values array below
146
- [:data_converter, :tag_list].each { |x| full_options.delete(x).should == expected.delete(x) }
147
+ full_options.delete(:data_converter).should be_kind_of(expected.delete(:data_converter).class)
148
+ full_options.delete(:tag_list).should == expected.delete(:tag_list)
147
149
  full_options.keys.sort.should == expected.keys.sort
148
150
  full_options.values.sort.should == expected.values.sort
149
151
  end
@@ -167,12 +169,13 @@ describe AWS::Flow::WorkflowRegistrationOptions do
167
169
  default_task_priority: "0",
168
170
  version: "1.0",
169
171
  prefix_name: "FooActivity",
170
- data_converter: FlowConstants.default_data_converter,
172
+ data_converter: FlowConstants.data_converter,
171
173
  tag_list: ["tag1", "tag2"]
172
174
  }
173
175
  # We first compare and remove the following values because these objects have issues
174
176
  # when we sort the values array below
175
- [:data_converter, :tag_list].each { |x| full_options.delete(x).should == expected.delete(x) }
177
+ full_options.delete(:data_converter).should be_kind_of(expected.delete(:data_converter).class)
178
+ full_options.delete(:tag_list).should == expected.delete(:tag_list)
176
179
  full_options.keys.sort.should == expected.keys.sort
177
180
  full_options.values.sort.should == expected.values.sort
178
181
  end
@@ -188,12 +191,9 @@ describe AWS::Flow::ActivityOptions do
188
191
  it "should only contain the non registration options" do
189
192
  options = AWS::Flow::ActivityOptions.new
190
193
  full_options = options.get_full_options
191
- expected = {
192
- data_converter: FlowConstants.default_data_converter
193
- }
194
194
  # We first compare and remove the following values because these objects have issues
195
195
  # when we sort the values array below
196
- full_options.should == expected
196
+ full_options[:data_converter].should be_kind_of(FlowConstants.data_converter.class)
197
197
  end
198
198
 
199
199
  it "should return the values passed in" do
@@ -213,11 +213,12 @@ describe AWS::Flow::ActivityOptions do
213
213
  manual_completion: true,
214
214
  task_priority: "100",
215
215
  heartbeat_timeout: "10",
216
- data_converter: FlowConstants.default_data_converter,
216
+ data_converter: FlowConstants.data_converter,
217
217
  }
218
218
  # We first compare and remove the following values because these objects have issues
219
219
  # when we sort the values array below
220
- [:data_converter, :manual_completion].each { |x| full_options.delete(x).should == expected.delete(x) }
220
+ full_options.delete(:data_converter).should be_kind_of(expected.delete(:data_converter).class)
221
+ full_options.delete(:manual_completion).should == expected.delete(:manual_completion)
221
222
  full_options.keys.sort.should == expected.keys.sort
222
223
  full_options.values.sort.should == expected.values.sort
223
224
  end
@@ -232,12 +233,9 @@ describe AWS::Flow::WorkflowOptions do
232
233
  it "should not contain any registration options" do
233
234
  options = AWS::Flow::WorkflowOptions.new
234
235
  full_options = options.get_full_options
235
- expected = {
236
- data_converter: FlowConstants.default_data_converter
237
- }
238
236
  # We first compare and remove the following values because these objects have issues
239
237
  # when we sort the values array below
240
- full_options.should == expected
238
+ full_options[:data_converter].should be_kind_of(FlowConstants.data_converter.class)
241
239
  end
242
240
 
243
241
  it "should return the values passed in" do
@@ -253,11 +251,12 @@ describe AWS::Flow::WorkflowOptions do
253
251
  version: "1.0",
254
252
  prefix_name: "FooWorkflow",
255
253
  tag_list: ["tag1", "tag2"],
256
- data_converter: FlowConstants.default_data_converter,
254
+ data_converter: FlowConstants.data_converter,
257
255
  }
258
256
  # We first compare and remove the following values because these objects have issues
259
257
  # when we sort the values array below
260
- [:data_converter, :tag_list].each { |x| full_options.delete(x).should == expected.delete(x) }
258
+ full_options.delete(:data_converter).should be_kind_of(expected.delete(:data_converter).class)
259
+ full_options.delete(:tag_list).should == expected.delete(:tag_list)
261
260
  full_options.keys.sort.should == expected.keys.sort
262
261
  full_options.values.sort.should == expected.values.sort
263
262
  end
@@ -272,7 +271,7 @@ describe AWS::Flow::WorkflowRegistrationDefaults do
272
271
 
273
272
  it "should return the correct default values" do
274
273
  defaults = AWS::Flow::WorkflowRegistrationDefaults.new
275
- defaults.data_converter.should == AWS::Flow::FlowConstants.default_data_converter
274
+ defaults.data_converter.should be_kind_of(AWS::Flow::FlowConstants.data_converter.class)
276
275
  defaults.default_task_start_to_close_timeout.should == 30
277
276
  defaults.default_child_policy.should == "TERMINATE"
278
277
  defaults.tag_list.should == []
@@ -290,7 +289,7 @@ describe AWS::Flow::ActivityRegistrationDefaults do
290
289
 
291
290
  it "should return the correct default values" do
292
291
  defaults = AWS::Flow::ActivityRegistrationDefaults.new
293
- defaults.data_converter.should == AWS::Flow::FlowConstants.default_data_converter
292
+ defaults.data_converter.should be_kind_of(AWS::Flow::FlowConstants.data_converter.class)
294
293
  defaults.default_task_schedule_to_start_timeout.should == Float::INFINITY
295
294
  defaults.default_task_schedule_to_close_timeout.should == Float::INFINITY
296
295
  defaults.default_task_start_to_close_timeout.should == Float::INFINITY
@@ -19,6 +19,14 @@ end
19
19
 
20
20
  describe "ExponentialRetry" do
21
21
 
22
+ before(:all) do
23
+ @bucket = ENV['AWS_SWF_BUCKET_NAME']
24
+ ENV['AWS_SWF_BUCKET_NAME'] = nil
25
+ end
26
+ after(:all) do
27
+ ENV['AWS_SWF_BUCKET_NAME'] = @bucket
28
+ end
29
+
22
30
  context "ActivityRetry" do
23
31
  # The following tests for github issue # 57
24
32
  before(:all) do
@@ -0,0 +1,159 @@
1
+ require_relative 'setup'
2
+
3
+ describe "AWS::Flow" do
4
+
5
+ context "#start" do
6
+
7
+ it "calls AWS::Flow::Templates#start" do
8
+ AWS::Flow::stub(:start_workflow)
9
+ expect(AWS::Flow::Templates).to receive(:start)
10
+ AWS::Flow::start("HelloWorld.hello", { foo: "foo" })
11
+ end
12
+
13
+ end
14
+
15
+ context "#start_workflow" do
16
+
17
+ it "raises error if options are not passed in correctly" do
18
+ expect{AWS::Flow::start_workflow(nil, "input", nil)}.to raise_error(ArgumentError)
19
+ expect{AWS::Flow::start_workflow(nil, "input", "")}.to raise_error(ArgumentError)
20
+ end
21
+
22
+ it "raises error if domain is not provided" do
23
+
24
+ options = { from_class: "FooWorkflow" }
25
+ expect{AWS::Flow::start_workflow(nil, "input", options)}.to raise_error(ArgumentError)
26
+
27
+ end
28
+
29
+ it "raises error if workflow type or from_class is not provided" do
30
+
31
+ domain = double
32
+ AWS::Flow::Utilities.stub(:register_domain).and_return(domain)
33
+
34
+ options = { domain: "foo", prefix_name: "FooWorkflow" }
35
+ expect{AWS::Flow::start_workflow(nil, "input", options)}.to raise_error(ArgumentError)
36
+ options.merge!(execution_method: "foo")
37
+ expect{AWS::Flow::start_workflow(nil, "input", options)}.to raise_error(ArgumentError)
38
+
39
+ wf_client = double
40
+ expect(wf_client).to receive(:start_execution)
41
+
42
+ expect(AWS::Flow).to receive(:workflow_client) do |client, domain, &block|
43
+ wf_client
44
+ end
45
+
46
+ options.merge!(version: "1.0")
47
+ expect{AWS::Flow::start_workflow(nil, "input", options)}.not_to raise_error
48
+
49
+ expect(wf_client).to receive(:start_execution)
50
+
51
+ expect(AWS::Flow).to receive(:workflow_client) do |client, domain, &block|
52
+ wf_client
53
+ end
54
+
55
+ options = { domain: "foo", from_class: "foo" }
56
+ expect{AWS::Flow::start_workflow(nil, "input", options)}.not_to raise_error
57
+
58
+ end
59
+
60
+ it "starts a workflow with overriden options" do
61
+
62
+ domain = double
63
+ AWS::Flow::Utilities.stub(:register_domain).and_return(domain)
64
+ wf_client = double
65
+ expect(wf_client).to receive(:start_execution)
66
+
67
+ expect(AWS::Flow).to receive(:workflow_client) do |client, domain, &block|
68
+ options = block.call
69
+ options.should include(
70
+ prefix_name: "HelloWorld",
71
+ execution_method: "hello",
72
+ version: "2.0",
73
+ execution_start_to_close_timeout: 120,
74
+ )
75
+ wf_client
76
+ end
77
+
78
+ options = {
79
+ domain: "FooDomain",
80
+ execution_start_to_close_timeout: 120,
81
+ version: "2.0",
82
+ }
83
+
84
+ AWS::Flow::start_workflow("HelloWorld.hello", "input", options)
85
+
86
+ end
87
+
88
+ it "starts a regular workflow execution with correct options" do
89
+
90
+ domain = double
91
+ AWS::Flow::Utilities.stub(:register_domain).and_return(domain)
92
+ wf_client = double
93
+ expect(wf_client).to receive(:start_execution)
94
+
95
+ expect(AWS::Flow).to receive(:workflow_client) do |client, domain, &block|
96
+ options = block.call
97
+
98
+ options.should include(
99
+ prefix_name: "StarterTestWorkflow",
100
+ execution_method: "start"
101
+ )
102
+ wf_client
103
+ end
104
+
105
+ AWS::Flow::start_workflow("StarterTestWorkflow", "input", {
106
+ domain: "test",
107
+ execution_method: "start",
108
+ version: "1.0"
109
+ })
110
+
111
+ end
112
+
113
+ it "starts a workflow execution with all options in options hash" do
114
+
115
+ domain = double
116
+ AWS::Flow::Utilities.stub(:register_domain).and_return(domain)
117
+ wf_client = double
118
+ expect(wf_client).to receive(:start_execution)
119
+
120
+ expect(AWS::Flow).to receive(:workflow_client) do |client, domain, &block|
121
+ options = block.call
122
+
123
+ options.should include(
124
+ prefix_name: "FooWorkflow",
125
+ execution_method: "start",
126
+ version: "1.0"
127
+ )
128
+ wf_client
129
+ end
130
+
131
+ options = { prefix_name: "FooWorkflow", domain: "Foo", version: "1.0", execution_method: "start" }
132
+ AWS::Flow::start_workflow(nil, "input", options)
133
+
134
+ end
135
+
136
+
137
+ it "starts workflow with from_options option correctly" do
138
+
139
+ domain = double
140
+ AWS::Flow::Utilities.stub(:register_domain).and_return(domain)
141
+ wf_client = double
142
+ expect(wf_client).to receive(:start_execution)
143
+
144
+ class FooWorkflow; extend AWS::Flow::Workflows; end
145
+
146
+ expect(AWS::Flow).to receive(:workflow_client) do |client, domain, &block|
147
+ options = block.call
148
+ options.should include(from_class: "FooWorkflow")
149
+ wf_client
150
+ end
151
+
152
+ options = { domain: "Foo", from_class: "FooWorkflow" }
153
+ AWS::Flow::start_workflow(nil, "input", options)
154
+
155
+ end
156
+
157
+ end
158
+
159
+ end
@@ -50,8 +50,7 @@ describe "Runner" do
50
50
 
51
51
  # This activity will say hello when invoked by the workflow
52
52
  def ping()
53
- puts "Pong from #{Socket.gethostbyname(Socket.gethostname).first}"
54
- "Pong from #{Socket.gethostbyname(Socket.gethostname).first}"
53
+ "Pong from #{Socket.gethostname}"
55
54
  end
56
55
  end
57
56
 
@@ -134,7 +133,7 @@ describe "Runner" do
134
133
  # mock the load_files method to avoid having to create default files
135
134
  AWS::Flow::Runner.stub(:load_files)
136
135
 
137
- workers = AWS::Flow::Runner.start_workers("", runner_config)
136
+ workers = AWS::Flow::Runner.start_workers(runner_config)
138
137
 
139
138
  sleep 2
140
139
  utils = PingUtils.new
@@ -64,6 +64,9 @@ describe "Runner" do
64
64
 
65
65
  # just in case so we don't start chid processes
66
66
  AWS::Flow::Runner.stub(:fork)
67
+ allow(AWS::Flow::Runner).to receive(:all_subclasses).and_return(nil)
68
+
69
+ AWS::Flow::Runner.stub(:setup_domain)
67
70
 
68
71
  # make sure the error is thrown
69
72
  expect {
@@ -86,6 +89,9 @@ describe "Runner" do
86
89
 
87
90
  # just in case so we don't start chid processes
88
91
  allow(AWS::Flow::Runner).to receive(:fork).and_return(42)
92
+ allow(AWS::Flow::Runner).to receive(:all_subclasses).and_return(nil)
93
+
94
+ AWS::Flow::Runner.stub(:setup_domain)
89
95
 
90
96
  # make sure the error is thrown
91
97
  expect {
@@ -109,6 +115,9 @@ describe "Runner" do
109
115
 
110
116
  # just in case so we don't start chid processes
111
117
  AWS::Flow::Runner.stub(:fork)
118
+ allow(AWS::Flow::Runner).to receive(:all_subclasses).and_return(nil)
119
+
120
+ AWS::Flow::Runner.stub(:setup_domain)
112
121
 
113
122
  # make sure the error is thrown
114
123
  expect {
@@ -131,6 +140,9 @@ describe "Runner" do
131
140
 
132
141
  # just in case so we don't start chid processes
133
142
  allow(AWS::Flow::Runner).to receive(:fork).and_return(42)
143
+ allow(AWS::Flow::Runner).to receive(:all_subclasses).and_return(nil)
144
+
145
+ AWS::Flow::Runner.stub(:setup_domain)
134
146
 
135
147
  # make sure the error is thrown
136
148
  expect {
@@ -143,34 +155,59 @@ describe "Runner" do
143
155
 
144
156
  describe "Starting workers" do
145
157
 
158
+ before(:all) do
159
+ class Foo; extend AWS::Flow::Workflows; end
160
+ class Bar; extend AWS::Flow::Workflows; end
161
+ class FooActivity; extend AWS::Flow::Activities; end
162
+ class BarActivity; extend AWS::Flow::Activities; end
163
+
164
+ end
165
+
146
166
  def workflow_js
147
- document = '{
167
+ JSON.parse('{
148
168
  "workflow_paths": [],
149
169
  "workflow_workers": [
150
170
  {
151
171
  "task_list": "bar",
152
- "workflow_classes": [ "Object", "String" ],
172
+ "workflow_classes": [ "Foo", "Bar" ],
153
173
  "number_of_workers": 3
154
174
  }
155
175
  ]
156
- }'
157
- JSON.parse(document)
176
+ }')
158
177
  end
159
178
 
160
179
  def activity_js
161
- document = '{
180
+ JSON.parse('{
162
181
  "activity_paths": [],
163
182
  "activity_workers": [
164
183
  {
165
184
  "task_list": "bar",
166
- "activity_classes": [ "Object", "String" ],
185
+ "activity_classes": [ "FooActivity", "BarActivity" ],
167
186
  "number_of_workers": 3
168
187
  }
169
188
  ]
170
- }'
171
- JSON.parse(document)
189
+ }')
190
+ end
191
+
192
+ def default_js
193
+ JSON.parse('{
194
+ "default_workers":
195
+ {
196
+ "number_of_workers": 3
197
+ }
198
+ }')
172
199
  end
173
200
 
201
+ def default_js_0
202
+ JSON.parse('{
203
+ "default_workers":
204
+ {
205
+ "number_of_workers": 0
206
+ }
207
+ }')
208
+ end
209
+
210
+
174
211
  it "makes sure the number of workflow workers is correct" do
175
212
  # mock out a few methods to focus on the fact that the workers were created
176
213
  allow_any_instance_of(AWS::Flow::WorkflowWorker).to receive(:add_implementation).and_return(nil)
@@ -182,7 +219,7 @@ describe "Runner" do
182
219
  # what we are testing:
183
220
  expect(AWS::Flow::Runner).to receive(:fork).exactly(3).times
184
221
 
185
- # start the workers
222
+ # start the workers
186
223
  workers = AWS::Flow::Runner.start_workflow_workers(AWS::SimpleWorkflow.new, "", workflow_js)
187
224
  end
188
225
 
@@ -194,11 +231,12 @@ describe "Runner" do
194
231
  allow_any_instance_of(AWS::Flow::ActivityWorker).to receive(:start).and_return(nil)
195
232
  AWS::Flow::Runner.stub(:setup_domain)
196
233
  AWS::Flow::Runner.stub(:load_files)
234
+ AWS::Flow::Runner.stub(:start_default_workers)
197
235
 
198
236
  # what we are testing:
199
237
  expect(AWS::Flow::Runner).to receive(:fork).exactly(3).times
200
238
 
201
- # start the workers
239
+ # start the workers
202
240
  workers = AWS::Flow::Runner.start_activity_workers(AWS::SimpleWorkflow.new, "",activity_js)
203
241
  end
204
242
 
@@ -215,11 +253,11 @@ describe "Runner" do
215
253
  implems << arg
216
254
  end
217
255
 
218
- # start the workers
256
+ # start the workers
219
257
  workers = AWS::Flow::Runner.start_workflow_workers(AWS::SimpleWorkflow.new, "",workflow_js)
220
258
 
221
259
  # validate
222
- expect(implems).to include(Object.const_get("Object"), Object.const_get("String"))
260
+ expect(implems).to include(Object.const_get("Foo"), Object.const_get("Bar"))
223
261
  end
224
262
 
225
263
  it "makes sure the activity implementation classes are added" do
@@ -228,6 +266,8 @@ describe "Runner" do
228
266
  AWS::Flow::Runner.stub(:fork)
229
267
  AWS::Flow::Runner.stub(:load_files)
230
268
  AWS::Flow::Runner.stub(:setup_domain)
269
+ AWS::Flow::Templates.stub(:make_activity_class).and_return{ |x| x }
270
+ AWS::Flow::Runner.stub(:start_default_workers)
231
271
 
232
272
  # stub that we can query later
233
273
  implems = []
@@ -235,11 +275,11 @@ describe "Runner" do
235
275
  implems << arg
236
276
  end
237
277
 
238
- # start the workers
278
+ # start the workers
239
279
  workers = AWS::Flow::Runner.start_activity_workers(AWS::SimpleWorkflow.new, "",activity_js)
240
280
 
241
281
  # validate
242
- expect(implems).to include(Object.const_get("Object"), Object.const_get("String"))
282
+ expect(implems).to include(Object.const_get("FooActivity"), Object.const_get("BarActivity"))
243
283
  end
244
284
 
245
285
  it "makes sure the workflow worker is started" do
@@ -255,7 +295,7 @@ describe "Runner" do
255
295
  starts += 1
256
296
  end
257
297
 
258
- # start the workers
298
+ # start the workers
259
299
  workers = AWS::Flow::Runner.start_workflow_workers(AWS::SimpleWorkflow.new, "",workflow_js)
260
300
 
261
301
  # validate
@@ -268,6 +308,7 @@ describe "Runner" do
268
308
  AWS::Flow::Runner.stub(:fork).and_yield
269
309
  AWS::Flow::Runner.stub(:load_files)
270
310
  AWS::Flow::Runner.stub(:setup_domain)
311
+ AWS::Flow::Runner.stub(:start_default_workers)
271
312
 
272
313
  # stub that we can query later
273
314
  starts = 0
@@ -275,13 +316,73 @@ describe "Runner" do
275
316
  starts += 1
276
317
  end
277
318
 
278
- # start the workers
319
+ # start the workers
279
320
  workers = AWS::Flow::Runner.start_activity_workers(AWS::SimpleWorkflow.new, "",activity_js)
280
321
 
281
322
  # validate
282
323
  expect(starts).to equal(3)
283
324
  end
284
325
 
326
+ it "makes sure the number of default workers is correct when stated explicitly" do
327
+ # mock out a few methods to focus on the fact that the workers were created
328
+ allow_any_instance_of(AWS::Flow::WorkflowWorker).to receive(:add_implementation) do |klass|
329
+ klass.should be(AWS::Flow::Templates.default_workflow)
330
+ nil
331
+ end
332
+
333
+ allow_any_instance_of(AWS::Flow::WorkflowWorker).to receive(:start).and_return(nil)
334
+ AWS::Flow::Runner.stub(:setup_domain)
335
+ AWS::Flow::Runner.stub(:load_files)
336
+ AWS::Flow::Templates.stub(:register_default_result_activity)
337
+
338
+ # what we are testing:
339
+ expect(AWS::Flow::Runner).to receive(:fork).exactly(3).times
340
+
341
+ # start the workers
342
+ workers = AWS::Flow::Runner.start_default_workers(AWS::SimpleWorkflow.new, "", default_js)
343
+ end
344
+
345
+ it "makes sure the number of default workers is 0 when stated so explicitly" do
346
+ # mock out a few methods to focus on the fact that the workers were created
347
+ allow_any_instance_of(AWS::Flow::WorkflowWorker).to receive(:add_implementation) do |klass|
348
+ klass.should be(AWS::Flow::Templates.default_workflow)
349
+ nil
350
+ end
351
+
352
+ allow_any_instance_of(AWS::Flow::WorkflowWorker).to receive(:start).and_return(nil)
353
+ AWS::Flow::Runner.stub(:setup_domain)
354
+ AWS::Flow::Runner.stub(:load_files)
355
+ AWS::Flow::Templates.stub(:register_default_result_activity)
356
+
357
+ # what we are testing:
358
+ expect(AWS::Flow::Runner).to receive(:fork).exactly(0).times
359
+
360
+ # start the workers
361
+ workers = AWS::Flow::Runner.start_default_workers(AWS::SimpleWorkflow.new, "", default_js_0)
362
+ end
363
+
364
+ it "makes sure the number of default workers is correct when stated implicitly" do
365
+ # mock out a few methods to focus on the fact that the workers were created
366
+ allow_any_instance_of(AWS::Flow::ActivityWorker).to receive(:add_implementation).and_return(nil)
367
+ allow_any_instance_of(AWS::Flow::ActivityWorker).to receive(:start).and_return(nil)
368
+
369
+ allow_any_instance_of(AWS::Flow::WorkflowWorker).to receive(:add_implementation) do |klass|
370
+ klass.should be(AWS::Flow::Templates.default_workflow)
371
+ nil
372
+ end
373
+
374
+ AWS::Flow::Runner.stub(:setup_domain)
375
+ AWS::Flow::Runner.stub(:load_files)
376
+ AWS::Flow::Templates.stub(:register_default_result_activity)
377
+
378
+ # what we are testing:
379
+ expect(AWS::Flow::Runner).to receive(:fork).exactly(6).times
380
+
381
+ # start the workers
382
+ workers = AWS::Flow::Runner.start_activity_workers(AWS::SimpleWorkflow.new, "",activity_js)
383
+
384
+ end
385
+
285
386
  end
286
387
 
287
388
 
@@ -321,33 +422,20 @@ describe "Runner" do
321
422
  default_file: relative})
322
423
  end
323
424
 
324
- it "loads the \"flow/activities.rb\" by default for activity worker" do
425
+ it "loads the \"flow/activities.rb\" and \"flow/workflows.rb\" by default for activity and workflow worker respectively" do
325
426
  def activity_js
326
427
  document = '{
327
428
  "activity_workers": [
328
429
  {
329
430
  "task_list": "bar",
330
- "activity_classes": [ "Object", "String" ],
431
+ "activity_classes": [ "FooActivity", "BarActivity" ],
331
432
  "number_of_workers": 3
332
433
  }
333
- ]
334
- }'
335
- JSON.parse(document)
336
- end
337
-
338
- AWS::Flow::Runner.stub(:setup_domain)
339
- expect(AWS::Flow::Runner).to receive(:require).with(File.join(".", "flow", "activities.rb"))
340
-
341
- AWS::Flow::Runner.start_activity_workers(AWS::SimpleWorkflow.new, ".", activity_js)
342
- end
343
-
344
- it "loads the \"flow/workflows.rb\" by default for workflow worker" do
345
- def workflow_js
346
- document = '{
434
+ ],
347
435
  "workflow_workers": [
348
436
  {
349
437
  "task_list": "bar",
350
- "workflow_classes": [ "Object", "String" ],
438
+ "workflow_classes": [ "Foo", "Bar" ],
351
439
  "number_of_workers": 3
352
440
  }
353
441
  ]
@@ -356,9 +444,10 @@ describe "Runner" do
356
444
  end
357
445
 
358
446
  AWS::Flow::Runner.stub(:setup_domain)
447
+ expect(AWS::Flow::Runner).to receive(:require).with(File.join(".", "flow", "activities.rb"))
359
448
  expect(AWS::Flow::Runner).to receive(:require).with(File.join(".", "flow", "workflows.rb"))
360
449
 
361
- AWS::Flow::Runner.start_workflow_workers(AWS::SimpleWorkflow.new, ".", workflow_js)
450
+ AWS::Flow::Runner.load_classes(".", activity_js)
362
451
  end
363
452
 
364
453
  it "takes activity_paths as override to \"flow/activities.rb\"" do
@@ -368,7 +457,7 @@ describe "Runner" do
368
457
  "activity_workers": [
369
458
  {
370
459
  "task_list": "bar",
371
- "activity_classes": [ "Object", "String" ],
460
+ "activity_classes": [ "FooActivity", "BarActivity" ],
372
461
  "number_of_workers": 3
373
462
  }
374
463
  ]
@@ -381,7 +470,7 @@ describe "Runner" do
381
470
  expect(AWS::Flow::Runner).to receive(:require).with(File.join("foo"))
382
471
  expect(AWS::Flow::Runner).to receive(:require).with(File.join("bar"))
383
472
 
384
- AWS::Flow::Runner.start_activity_workers(AWS::SimpleWorkflow.new, ".", activity_js)
473
+ AWS::Flow::Runner.load_classes(".", activity_js)
385
474
  end
386
475
 
387
476
  it "takes workflow_paths as override to \"flow/workflows.rb\"" do
@@ -391,7 +480,7 @@ describe "Runner" do
391
480
  "workflow_workers": [
392
481
  {
393
482
  "task_list": "bar",
394
- "workflow_classes": [ "Object", "String" ],
483
+ "workflow_classes": [ "Foo", "Bar" ],
395
484
  "number_of_workers": 3
396
485
  }
397
486
  ]
@@ -404,7 +493,7 @@ describe "Runner" do
404
493
  expect(AWS::Flow::Runner).to receive(:require).with(File.join("foo"))
405
494
  expect(AWS::Flow::Runner).to receive(:require).with(File.join("bar"))
406
495
 
407
- AWS::Flow::Runner.start_workflow_workers(AWS::SimpleWorkflow.new, ".", workflow_js)
496
+ AWS::Flow::Runner.load_classes(".", workflow_js)
408
497
  end
409
498
 
410
499
  end
@@ -480,6 +569,7 @@ describe "Runner" do
480
569
  AWS::Flow::ActivityWorker.any_instance.stub(:add_implementation) do |impl|
481
570
  impls << impl
482
571
  end
572
+ AWS::Flow::Runner.stub(:start_default_workers)
483
573
 
484
574
  AWS::Flow::Runner.start_activity_workers(AWS::SimpleWorkflow.new, ".", activity_js)
485
575