inferno_core 0.1.0 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -140,6 +140,10 @@ module Inferno
140
140
  update(result_id, result: 'pass', result_message: message)
141
141
  end
142
142
 
143
+ def cancel_waiting_result(result_id, message = nil)
144
+ update(result_id, result: 'cancel', result_message: message)
145
+ end
146
+
143
147
  def json_serializer_options
144
148
  {
145
149
  include: {
@@ -54,7 +54,7 @@ module Inferno
54
54
  return nil if params[:value].blank?
55
55
 
56
56
  case params[:type]&.to_s
57
- when 'text', 'textarea'
57
+ when 'text', 'textarea', 'radio'
58
58
  params[:value].to_s
59
59
  when 'oauth_credentials'
60
60
  credentials =
@@ -65,6 +65,10 @@ module Inferno
65
65
  build_entity(test_run_hash)
66
66
  end
67
67
 
68
+ def status_for_test_run(id)
69
+ self.class::Model.where(id: id).get(:status)
70
+ end
71
+
68
72
  def mark_as_running(test_run_id)
69
73
  update(test_run_id, status: 'running')
70
74
  end
@@ -91,6 +95,10 @@ module Inferno
91
95
  )
92
96
  end
93
97
 
98
+ def mark_as_cancelling(test_run_id)
99
+ update(test_run_id, status: 'cancelling')
100
+ end
101
+
94
102
  class Model < Sequel::Model(db)
95
103
  include ValidateRunnableReference
96
104
 
@@ -0,0 +1,40 @@
1
+ module Inferno
2
+ # @private
3
+ # This class takes an array of results and determines the overall result. This
4
+ # is used to determine the result of a TestGroup/TestSuite based on the
5
+ # results of it's children.
6
+ class ResultSummarizer
7
+ attr_reader :results
8
+
9
+ def initialize(results)
10
+ @results = results
11
+ end
12
+
13
+ def summarize
14
+ prioritized_result_strings.find { |result_string| unique_result_strings.include? result_string }
15
+ end
16
+
17
+ private
18
+
19
+ def prioritized_result_strings
20
+ Entities::Result::RESULT_OPTIONS
21
+ end
22
+
23
+ def required_results
24
+ @required_results ||= results.select(&:required?)
25
+ end
26
+
27
+ def all_optional_results?
28
+ required_results.blank?
29
+ end
30
+
31
+ def results_for_summary
32
+ all_optional_results? ? results : required_results
33
+ end
34
+
35
+ def unique_result_strings
36
+ @unique_result_strings ||=
37
+ results_for_summary.map(&:result).uniq
38
+ end
39
+ end
40
+ end
@@ -1,3 +1,4 @@
1
+ require_relative './result_summarizer'
1
2
  require_relative './utils/markdown_formatter'
2
3
 
3
4
  module Inferno
@@ -28,8 +29,13 @@ module Inferno
28
29
  @session_data_repo ||= Repositories::SessionData.new
29
30
  end
30
31
 
32
+ def test_run_is_cancelling
33
+ # forces db refetch of the test run status in case it is being cancelled
34
+ test_runs_repo.status_for_test_run(test_run.id) == 'cancelling'
35
+ end
36
+
31
37
  def start
32
- test_runs_repo.mark_as_running(test_run.id)
38
+ test_runs_repo.mark_as_running(test_run.id) unless test_run.status == 'cancelling'
33
39
 
34
40
  run(test_run.runnable)
35
41
 
@@ -59,6 +65,8 @@ module Inferno
59
65
  test_instance = test.new(inputs: inputs, test_session_id: test_session.id, scratch: scratch)
60
66
 
61
67
  result = begin
68
+ raise Exceptions::CancelException, 'Test cancelled by user' if test_run_is_cancelling
69
+
62
70
  test_instance.load_named_requests
63
71
  test_instance.instance_eval(&test.block)
64
72
  'pass'
@@ -120,7 +128,9 @@ module Inferno
120
128
 
121
129
  children = parent.children
122
130
  child_results = results_repo.current_results_for_test_session_and_runnables(test_session.id, children)
123
- return if children.length != child_results.length
131
+ required_children = children.select(&:required?)
132
+ required_results = child_results.select(&:required?)
133
+ return if required_children.length != required_results.length
124
134
 
125
135
  old_result = results_repo.current_result_for_test_session(test_session.id, parent.reference_hash)&.result
126
136
  new_result = roll_up_result(child_results)
@@ -170,11 +180,7 @@ module Inferno
170
180
  end
171
181
 
172
182
  def roll_up_result(results)
173
- result_priority = Entities::Result::RESULT_OPTIONS
174
- unique_results = results.map(&:result).uniq
175
- result_priority.find do |result|
176
- unique_results.include? result
177
- end
183
+ ResultSummarizer.new(results).summarize
178
184
  end
179
185
  end
180
186
  end
@@ -1,3 +1,3 @@
1
1
  module Inferno
2
- VERSION = '0.1.0'.freeze
2
+ VERSION = '0.1.2'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inferno_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephen MacVicar
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2022-01-10 00:00:00.000000000 Z
13
+ date: 2022-02-01 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
@@ -242,14 +242,14 @@ dependencies:
242
242
  requirements:
243
243
  - - "~>"
244
244
  - !ruby/object:Gem::Version
245
- version: 6.2.1
245
+ version: 6.4.0
246
246
  type: :runtime
247
247
  prerelease: false
248
248
  version_requirements: !ruby/object:Gem::Requirement
249
249
  requirements:
250
250
  - - "~>"
251
251
  - !ruby/object:Gem::Version
252
- version: 6.2.1
252
+ version: 6.4.0
253
253
  - !ruby/object:Gem::Dependency
254
254
  name: sqlite3
255
255
  requirement: !ruby/object:Gem::Requirement
@@ -466,6 +466,7 @@ files:
466
466
  - lib/inferno/apps/web/controllers/controller.rb
467
467
  - lib/inferno/apps/web/controllers/requests/show.rb
468
468
  - lib/inferno/apps/web/controllers/test_runs/create.rb
469
+ - lib/inferno/apps/web/controllers/test_runs/destroy.rb
469
470
  - lib/inferno/apps/web/controllers/test_runs/results/index.rb
470
471
  - lib/inferno/apps/web/controllers/test_runs/show.rb
471
472
  - lib/inferno/apps/web/controllers/test_sessions/create.rb
@@ -520,6 +521,7 @@ files:
520
521
  - lib/inferno/entities.rb
521
522
  - lib/inferno/entities/attributes.rb
522
523
  - lib/inferno/entities/entity.rb
524
+ - lib/inferno/entities/has_runnable.rb
523
525
  - lib/inferno/entities/header.rb
524
526
  - lib/inferno/entities/message.rb
525
527
  - lib/inferno/entities/request.rb
@@ -557,6 +559,7 @@ files:
557
559
  - lib/inferno/repositories/test_suites.rb
558
560
  - lib/inferno/repositories/tests.rb
559
561
  - lib/inferno/repositories/validate_runnable_reference.rb
562
+ - lib/inferno/result_summarizer.rb
560
563
  - lib/inferno/spec_support.rb
561
564
  - lib/inferno/test_runner.rb
562
565
  - lib/inferno/utils/markdown_formatter.rb