Class: Mutx::Results::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/mutx/results/result.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data_for_result) ⇒ Result

Returns a new instance of Result.



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/mutx/results/result.rb', line 41

def initialize data_for_result
  Mutx::Support::Log.debug "Result.new => data_for_result => #{data_for_result}" if Mutx::Support::Log
  if data_for_result["_id"]
    # It comes from mongo because there is a result id
    @id = data_for_result["_id"]
    load_values(data_for_result)

  else # It comes from a new execution request
    @id = Mutx::Database::MongoConnector.generate_id
    @task                     = data_for_result['task']
    @execution_name           = data_for_result["execution_name"] || ""
    @custom_params            = data_for_result["custom_params"]
    @git_log                  = data_for_result["git_log"]
    @started_message          = data_for_result["started_message"]
    @started_at               = now_in_seconds
    @finished_at              = nil
    @status = @summary        = "started"
    @timeout                  = nil
    @pid                      = nil
    @html_report              = ""
    @results_details          = {"duration" => 0, "passed"=>[], "failed" =>[], "undefined" => [], "unknown"=>[], "skipped" => [], "pending" => []}

    # Save task info
    task_data                 = Mutx::Database::MongoConnector.task_data_for(@task["id"])
    @command                  = data_for_result["command"]
    @task_name                = task_data["name"]
    @command                  = task_data["command"]
    @application              = task_data["application"]
    @regex                    = task_data["regex"] || nil
    @value_for_regex          = task_data["value_for_regex"]
    @result_value             = nil
    @console_output           = ""
    @last_check_time          = now_in_seconds
    @execution_data           = {}
    @configuration_values     = Mutx::Database::MongoConnector.configuration
    @notified                 = "no"
    @file_attached            = "no"
    create_output_dir
  end
end

Instance Attribute Details

#applicationObject

Returns the value of attribute application.



7
8
9
# File 'lib/mutx/results/result.rb', line 7

def application
  @application
end

#commandObject

Returns the value of attribute command.



7
8
9
# File 'lib/mutx/results/result.rb', line 7

def command
  @command
end

#configuration_valuesObject

Returns the value of attribute configuration_values.



7
8
9
# File 'lib/mutx/results/result.rb', line 7

def configuration_values
  @configuration_values
end

#console_outputObject

Returns the value of attribute console_output.



7
8
9
# File 'lib/mutx/results/result.rb', line 7

def console_output
  @console_output
end

#console_output_file_nameObject

Returns the value of attribute console_output_file_name.



7
8
9
# File 'lib/mutx/results/result.rb', line 7

def console_output_file_name
  @console_output_file_name
end

#custom_paramsObject

Returns the value of attribute custom_params.



7
8
9
# File 'lib/mutx/results/result.rb', line 7

def custom_params
  @custom_params
end

#execution_dataObject

Returns the value of attribute execution_data.



7
8
9
# File 'lib/mutx/results/result.rb', line 7

def execution_data
  @execution_data
end

#execution_nameObject

Returns the value of attribute execution_name.



7
8
9
# File 'lib/mutx/results/result.rb', line 7

def execution_name
  @execution_name
end

#file_attachedObject

Returns the value of attribute file_attached.



7
8
9
# File 'lib/mutx/results/result.rb', line 7

def file_attached
  @file_attached
end

#finished_atObject

Returns the value of attribute finished_at.



7
8
9
# File 'lib/mutx/results/result.rb', line 7

def finished_at
  @finished_at
end

#git_logObject

Returns the value of attribute git_log.



7
8
9
# File 'lib/mutx/results/result.rb', line 7

def git_log
  @git_log
end

#gui_taskObject

Returns the value of attribute gui_task.



7
8
9
# File 'lib/mutx/results/result.rb', line 7

def gui_task
  @gui_task
end

#html_reportObject

Returns the value of attribute html_report.



7
8
9
# File 'lib/mutx/results/result.rb', line 7

def html_report
  @html_report
end

#idObject

Returns the value of attribute id.



7
8
9
# File 'lib/mutx/results/result.rb', line 7

def id
  @id
end

#last_check_timeObject

Returns the value of attribute last_check_time.



7
8
9
# File 'lib/mutx/results/result.rb', line 7

def last_check_time
  @last_check_time
end

#mutx_commandObject

Returns the value of attribute mutx_command.



7
8
9
# File 'lib/mutx/results/result.rb', line 7

def mutx_command
  @mutx_command
end

#mutx_report_file_nameObject

Returns the value of attribute mutx_report_file_name.



7
8
9
# File 'lib/mutx/results/result.rb', line 7

def mutx_report_file_name
  @mutx_report_file_name
end

#notifiedObject

Returns the value of attribute notified.



7
8
9
# File 'lib/mutx/results/result.rb', line 7

def notified
  @notified
end

#pidObject

Returns the value of attribute pid.



7
8
9
# File 'lib/mutx/results/result.rb', line 7

def pid
  @pid
end

#regexObject

Returns the value of attribute regex.



7
8
9
# File 'lib/mutx/results/result.rb', line 7

def regex
  @regex
end

#result_valueObject

Returns the value of attribute result_value.



7
8
9
# File 'lib/mutx/results/result.rb', line 7

def result_value
  @result_value
end

#results_detailsObject

Returns the value of attribute results_details.



7
8
9
# File 'lib/mutx/results/result.rb', line 7

def results_details
  @results_details
end

#sawObject

Returns the value of attribute saw.



7
8
9
# File 'lib/mutx/results/result.rb', line 7

def saw
  @saw
end

#started_atObject

Returns the value of attribute started_at.



7
8
9
# File 'lib/mutx/results/result.rb', line 7

def started_at
  @started_at
end

#started_messageObject

Returns the value of attribute started_message.



7
8
9
# File 'lib/mutx/results/result.rb', line 7

def started_message
  @started_message
end

#statusObject

Returns the value of attribute status.



7
8
9
# File 'lib/mutx/results/result.rb', line 7

def status
  @status
end

#summaryObject

Returns the value of attribute summary.



7
8
9
# File 'lib/mutx/results/result.rb', line 7

def summary
  @summary
end

#taskObject

Returns the value of attribute task.



7
8
9
# File 'lib/mutx/results/result.rb', line 7

def task
  @task
end

#task_nameObject

Returns the value of attribute task_name.



7
8
9
# File 'lib/mutx/results/result.rb', line 7

def task_name
  @task_name
end

#timeoutObject

Returns the value of attribute timeout.



7
8
9
# File 'lib/mutx/results/result.rb', line 7

def timeout
  @timeout
end

#value_for_regexObject

Returns the value of attribute value_for_regex.



7
8
9
# File 'lib/mutx/results/result.rb', line 7

def value_for_regex
  @value_for_regex
end

Class Method Details

.get(result_id) ⇒ Object



90
91
92
93
# File 'lib/mutx/results/result.rb', line 90

def self.get(result_id)
  result_data = Mutx::Database::MongoConnector.result_data_for_id(result_id)
  new(result_data) if result_data
end

Instance Method Details

#active?Boolean

Returns:

  • (Boolean)


319
320
321
# File 'lib/mutx/results/result.rb', line 319

def active?
  process_running? or !finished? or !stopped? or running? or started?
end

#add_execution_data!(key, value) ⇒ Object



179
180
181
182
# File 'lib/mutx/results/result.rb', line 179

def add_execution_data! key, value
  @execution_data.store(key, value)
  self.save!
end

#add_scenario_result(details) ⇒ Object



199
200
201
# File 'lib/mutx/results/result.rb', line 199

def add_scenario_result details
  self.add_test_result details
end

#add_test_result(details) ⇒ Object

details =

"name" => scenario.name,
"status" => self.get_status(scenario),
"location" => "#{scenario.location.file:#Mutx::Results::Result.scenarioscenario.locationscenario.location.line"}

Parameters:

  • details (Hash)


189
190
191
192
193
194
195
196
197
# File 'lib/mutx/results/result.rb', line 189

def add_test_result details
  return false unless @results_details.keys.include? details["status"]
  begin
    self.send("@results_details[#{details['status']}]<<#{details}") and self.save!
    true
  rescue
    false
  end
end

#api_responseObject



141
142
143
144
145
146
147
148
# File 'lib/mutx/results/result.rb', line 141

def api_response
  data = result_data_structure
  data["has_report"] = self.has_report?
  data["elapsed_time"] = self.elapsed_time
  # List of fields to omit in api response
  ["html_report","console_output_file_name","mutx_command","mutx_report_file_name","pid","last_check_time","console_output","git_log"].each{|field| data.delete(field)}
  data
end

#append_output!(output) ⇒ Object



508
509
510
511
512
# File 'lib/mutx/results/result.rb', line 508

def append_output! output
  @console_output += output
  mark_last_check_time
  self.save!
end

#check_if_finished!Object



323
324
325
326
327
328
329
330
331
332
333
# File 'lib/mutx/results/result.rb', line 323

def check_if_finished!
  if is_running?
    if reached_timeout?
      finished_by_timeout!
    elsif is_process_dead?
      finish!
    end
  else
    ensure_finished!
  end
end

#console_output_contentObject



466
467
468
469
470
471
472
473
474
475
# File 'lib/mutx/results/result.rb', line 466

def console_output_content
  begin
    FileUtils.cp("#{Dir.pwd}/mutx/temp/#{console_output_file_name}", "#{Dir.pwd}/mutx/temp/#{console_output_file_name}~")
    file_content = File.open "#{Dir.pwd}/mutx/temp/#{console_output_file_name}~", "r"
    File.delete("#{Dir.pwd}/mutx/temp/#{console_output_file_name}~")
  rescue Errno::ENOENT
    false
  end
  file_content
end

#console_output_file_textObject



454
455
456
457
458
459
460
# File 'lib/mutx/results/result.rb', line 454

def console_output_file_text
  text = ""
  console_output_content.each_line do |line|
    text += line + "\n"
  end
  text
end

#create_output_dirObject



315
316
317
# File 'lib/mutx/results/result.rb', line 315

def create_output_dir
  Dir.mkdir "#{Dir.pwd}/mutx/out/#{@id}"
end

#custom_params_valuesString

Returns the string of custom params values

Returns:

  • (String)

    foo=bar john=doe



152
153
154
155
156
157
158
159
160
161
162
# File 'lib/mutx/results/result.rb', line 152

def custom_params_values
  unless @custom_params.empty?
    line = ""
    validated = validate_params(@custom_params)
    validated.each_pair do |param_name,value|
      line += "#{param_name}=#{value} "
    end
    line
  end 
  # "mutx_custom_params='#{validate_params(@custom_params).to_json}'".gsub(',', ', ') unless @custom_params.empty?
end

#delete_asociated_files!Object



603
604
605
606
607
# File 'lib/mutx/results/result.rb', line 603

def delete_asociated_files!
  delete_console_output_file!
  delete_mutx_report_file!
  delete_copy_mutx_report_file!
end

#delete_console_output_file!Object



574
575
576
577
578
579
580
581
582
# File 'lib/mutx/results/result.rb', line 574

def delete_console_output_file!
  begin
    File.delete("#{Dir.pwd}/mutx/temp/#{console_output_file_name}")
    Mutx::Support::Log.debug "[#{@id}] Console output files deleted" if Mutx::Support::Log
    true
  rescue => e
    false
  end
end

#delete_copy_mutx_report_file!Object



594
595
596
597
598
599
600
601
# File 'lib/mutx/results/result.rb', line 594

def delete_copy_mutx_report_file!
  begin
    #File.delete("#{Dir.pwd}/mutx/temp/#{mutx_report_file_name}~") #No delete to attach via email
    true
  rescue => e
    false
  end
end

#delete_mutx_report_file!Object



584
585
586
587
588
589
590
591
592
# File 'lib/mutx/results/result.rb', line 584

def delete_mutx_report_file!
  begin
    #File.delete("#{Dir.pwd}/mutx/temp/#{mutx_report_file_name}")
    Mutx::Support::Log.debug "[#{@id}] Report files deleted" if Mutx::Support::Log
    true
  rescue => e
    false
  end
end

#elapsed_timeObject



619
620
621
# File 'lib/mutx/results/result.rb', line 619

def elapsed_time
  (finished_at || now_in_seconds) - started_at
end

#ensure_complete_console_output(output) ⇒ Object



501
502
503
504
505
506
# File 'lib/mutx/results/result.rb', line 501

def ensure_complete_console_output output
  if output.size > @console_output.size
    @console_output = output
    self.save!
  end
end

#ensure_finished!Object



340
341
342
# File 'lib/mutx/results/result.rb', line 340

def ensure_finished!
  finish! unless stopped?
end

#eval_regex!Object



262
263
264
265
266
267
268
269
270
271
272
273
274
# File 'lib/mutx/results/result.rb', line 262

def eval_regex!
  Mutx::Support::Log.debug "result_value => #{@result_value} = value_for_regex #{@value_for_regex}" if Mutx::Support::Log
  if @regex
     @result_value = if @console_output.scan("#{@regex}").flatten.last
      @value_for_regex 
    else
      oposite_value_for_regex
    end
  else # no regex
    "not defined"
  end
  self.save!
end

#finish!Object



235
236
237
238
239
240
241
242
243
244
245
246
247
248
# File 'lib/mutx/results/result.rb', line 235

def finish!
  Mutx::Support::Log.debug "Finshing execution when got status '#{@status}'" if Mutx::Support::Log
  if running? or started?
    @finished_at = now_in_seconds
    @status = "finished" 
    set_result_value!
    save_report
    delete_asociated_files!
    self.save!
    kill_process_pid!
    Mutx::Support::Log.debug "[#{@id}] Executuion finished" if Mutx::Support::Log
    true
  end
end

#finished?Boolean

Returns:

  • (Boolean)


523
524
525
# File 'lib/mutx/results/result.rb', line 523

def finished?
  @status =~ /(finished|stopped)/i
end

#finished_at_formattedString

Returns the finished at time attribute in a format way (configured on mutx info)

Returns:

  • (String)


637
638
639
# File 'lib/mutx/results/result.rb', line 637

def finished_at_formatted
  Mutx::Support::TimeHelper.formatted_time_for @finished_at
end

#finished_by_timeout!Object



303
304
305
306
307
308
309
310
311
312
313
# File 'lib/mutx/results/result.rb', line 303

def finished_by_timeout!

  @timeout = "#{Mutx::Support::Configuration.execution_time_to_live}"
  reset!("timed out '#{@timeout}'")
  @status = "stopped by timeout"
  save_report
  save_report_summary_and_status!
  Mutx::Support::Log.debug "[#{@id}] Finished by timeout (#{Mutx::Support::Configuration.execution_time_to_live} sec)" if Mutx::Support::Log
  Mutx::Workers::EmailSender.perform_async(self.id)
  true
end

#generate_cucumber_report?Boolean

Returns:

  • (Boolean)


223
224
225
# File 'lib/mutx/results/result.rb', line 223

def generate_cucumber_report?
  @task["cucumber_report"]
end

#get_result_from_summary!Object



287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
# File 'lib/mutx/results/result.rb', line 287

def get_result_from_summary!
  get_summary!
  return nil if @result_value or stopped?
  @result_value = if @summary.include? "failed"
    "failed"
  elsif @summary.include? "undefined"
    "undefined"
  elsif @summary.include? "pending"
    "pending"
  elsif @summary.include? "passed"
    "passed"
  elsif @summary.include? "stopped"
    "stopped"
  end
end

#get_started_message!Object



134
135
136
137
138
139
# File 'lib/mutx/results/result.rb', line 134

def get_started_message!
  text = self.started_message
  @started_message = nil
  self.save!
  text
end

#get_status!Object

tries to get status



441
442
443
444
445
446
447
448
# File 'lib/mutx/results/result.rb', line 441

def get_status!
  if is_cucumber?

    value = Mutx::View::Parser.get_status(read_report) if is_there_a_report_file?

    @status = value if value
  end
end

#get_summary!Object



386
387
388
389
390
391
392
393
394
395
396
397
398
# File 'lib/mutx/results/result.rb', line 386

def get_summary!
  if is_cucumber?
    report = if is_there_a_report_file?
      read_report
    else
      @html_report
    end
    @summary = Mutx::View::Parser.extract_summary(report) unless summary?
    self.save!
  else
    # it's a task
  end
end

#gui_task?Boolean

Returns:

  • (Boolean)


227
228
229
# File 'lib/mutx/results/result.rb', line 227

def gui_task?
  @task["aplication"] == "GUI"
end

#has_regex?Boolean

Returns:

  • (Boolean)


231
232
233
# File 'lib/mutx/results/result.rb', line 231

def has_regex?
  @regex and true
end

#has_report?Boolean

Returns:

  • (Boolean)


382
383
384
# File 'lib/mutx/results/result.rb', line 382

def has_report?
  !@html_report.empty?
end

#has_scenario_executed?Boolean

Returns:

  • (Boolean)


564
565
566
# File 'lib/mutx/results/result.rb', line 564

def has_scenario_executed?
  Mutx::View::Parser.has_scenarios_executed? @html_report
end

#has_started_message?Boolean

Returns:

  • (Boolean)


130
131
132
# File 'lib/mutx/results/result.rb', line 130

def has_started_message?
  !@started_message.nil?
end

#has_summary?Boolean

Returns:

  • (Boolean)


556
557
558
# File 'lib/mutx/results/result.rb', line 556

def has_summary?
  report_has_summary?
end

#is_cucumber?Boolean

Returns:

  • (Boolean)


215
216
217
# File 'lib/mutx/results/result.rb', line 215

def is_cucumber?
  @task["cucumber"]
end

#is_finished?Boolean

Returns:

  • (Boolean)


535
# File 'lib/mutx/results/result.rb', line 535

def is_finished?; self.finished?; end

#is_process_dead?Boolean

Returns:

  • (Boolean)


348
349
350
# File 'lib/mutx/results/result.rb', line 348

def is_process_dead?
  !Mutx::Support::Processes.process_running? @pid
end

#is_ruby_platform?Boolean

Returns:

  • (Boolean)


219
220
221
# File 'lib/mutx/results/result.rb', line 219

def is_ruby_platform?
  @task["platform"]
end

#is_running?Boolean

Returns:

  • (Boolean)


514
515
516
# File 'lib/mutx/results/result.rb', line 514

def is_running?
  @status =~ /running|started/i
end

#is_there_a_report_file?Boolean

Returns:

  • (Boolean)


374
375
376
377
378
379
380
# File 'lib/mutx/results/result.rb', line 374

def is_there_a_report_file?
  begin
    !open_report_file.nil?
  rescue
    false
  end
end

#is_there_console_output_file?Boolean

Returns:

  • (Boolean)


462
463
464
# File 'lib/mutx/results/result.rb', line 462

def is_there_console_output_file?
  File.exist? "#{Dir.pwd}/mutx/temp/#{console_output_file_name}"
end

#is_there_new_lines_to_save?(text) ⇒ Boolean

Returns:

  • (Boolean)


450
451
452
# File 'lib/mutx/results/result.rb', line 450

def is_there_new_lines_to_save? text
  text.size > @console_output.size
end

#kill_process_pid!Object



250
251
252
# File 'lib/mutx/results/result.rb', line 250

def kill_process_pid!
  Support::Processes.kill_p(@pid) if @pid
end

#load_values(data) ⇒ Object



82
83
84
85
86
87
88
# File 'lib/mutx/results/result.rb', line 82

def load_values data
  data.each_pair do |var, value|
    begin
      send("#{var}=",value) if send("#{var}").nil?
    rescue; end
  end
end

#mark_as_saw!Object



568
569
570
571
572
# File 'lib/mutx/results/result.rb', line 568

def mark_as_saw!
  @saw = true
  Mutx::Support::Log.debug "[#{@id}] Marked as saw" if Mutx::Support::Log
  self.save!
end

#mark_last_check_timeObject



487
488
489
# File 'lib/mutx/results/result.rb', line 487

def mark_last_check_time
  @last_check_time = now_in_seconds
end

#nowTime

Returns actal timestamp

Returns:

  • (Time)


625
626
627
# File 'lib/mutx/results/result.rb', line 625

def now
  Time.now.localtime
end

#now_in_secondsObject

Returns the timestamp in seconds

Parameters:

  • timestamp (Fixnum)


643
644
645
# File 'lib/mutx/results/result.rb', line 643

def now_in_seconds
  now.to_i
end

#open_report_fileObject



417
418
419
420
421
422
423
424
425
426
427
428
# File 'lib/mutx/results/result.rb', line 417

def open_report_file
  begin
    FileUtils.cp("#{Dir.pwd}/mutx/temp/#{mutx_report_file_name}", "#{Dir.pwd}/mutx/temp/#{mutx_report_file_name}~")
    file_content = File.open "#{Dir.pwd}/mutx/temp/#{mutx_report_file_name}~", "r"

    #File.delete("#{Dir.pwd}/mutx/temp/#{mutx_report_file_name}~")

  rescue
    false
  end
  file_content
end

#oposite_value_for_regexObject



276
277
278
279
280
281
282
283
284
285
# File 'lib/mutx/results/result.rb', line 276

def oposite_value_for_regex
  case @value_for_regex
  when "passed"
    "failed"
  when "failed" 
    "passed"
  else
    nil
  end
end

#process_finished?Boolean

Returns:

  • (Boolean)


527
528
529
# File 'lib/mutx/results/result.rb', line 527

def process_finished?
  ! process_running?
end

#process_running?Boolean

Returns:

  • (Boolean)


531
532
533
# File 'lib/mutx/results/result.rb', line 531

def process_running?
  Mutx::Support::Processes.process_running? pid
end

#reached_timeout?Boolean

Returns:

  • (Boolean)


344
345
346
# File 'lib/mutx/results/result.rb', line 344

def reached_timeout?
  self.seconds_without_changes > Mutx::Support::Configuration.execution_time_to_live
end

#read_reportString

Returns the html report file created by MuTX

Parameters:

  • html (String)

    report file name

Returns:

  • (String)

    html code read from report



407
408
409
410
411
412
413
414
415
# File 'lib/mutx/results/result.rb', line 407

def read_report
  begin
    content = ''
    open_report_file.each_line do |line|
      content+= line
    end
  rescue; end
  content
end

#report_has_summary?Boolean

Returns:

  • (Boolean)


560
561
562
# File 'lib/mutx/results/result.rb', line 560

def report_has_summary?
  @summary.include? "scenario"
end

#report_says_finished?Boolean

Returns:

  • (Boolean)


537
538
539
# File 'lib/mutx/results/result.rb', line 537

def report_says_finished?
  Mutx::View::Parser.finished_statement? @html_report
end

#reset!(reason = nil) ⇒ Object



545
546
547
548
549
550
551
552
553
554
# File 'lib/mutx/results/result.rb', line 545

def reset! reason=nil
  Mutx::Support::Log.debug "[#{@id}] Execution stoppped (reset)"
  @status = "stopped"
  @finished_at = now_in_seconds
  save_report
  delete_asociated_files!
  self.save!
  kill_process_pid!
  true
end

#reseted?Boolean

Returns:

  • (Boolean)


336
337
338
# File 'lib/mutx/results/result.rb', line 336

def reseted?
  @status == "stopped"
end

#result_data_structureObject



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/mutx/results/result.rb', line 96

def result_data_structure
  {
    "_id"                       => id,
    "task"                      => @task,
    "execution_name"            => execution_name,
    "command"                   => command,
    "application"               => application,
    "custom_params"             => custom_params,
    "mutx_command"              => mutx_command,
    "started_message"           => started_message,
    "mutx_report_file_name"     => mutx_report_file_name,
    "html_report"               => html_report,
    "started_at"                => started_at,
    "finished_at"               => finished_at,
    "status"                    => status,
    "timeout"                   => timeout,
    "summary"                   => summary,
    "results_details"           => results_details,
    "console_output_file_name"  => console_output_file_name,
    "console_output"            => console_output,
    "git_log"                   => git_log,
    "saw"                       => saw,
    "pid"                       => pid,
    "last_check_time"           => last_check_time,
    "execution_data"            => execution_data,
    "configuration_values"      => configuration_values,
    "regex"                     => regex,
    "value_for_regex"           => value_for_regex,
    "result_value"              => result_value,
    "notified"                  => notified,
    "file_attached"             => file_attached
  }
end

#running!Object



430
431
432
433
434
# File 'lib/mutx/results/result.rb', line 430

def running!
  @status = "running"
  Mutx::Support::Log.debug "[#{@id}] Setted as running" if Mutx::Support::Log
  self.save!
end

#running?Boolean

Returns:

  • (Boolean)


436
437
438
# File 'lib/mutx/results/result.rb', line 436

def running?
  @status == "running"
end

#save!Boolean

Persists the status of the object on mongo. If result exist update it, else creates it

Returns:

  • (Boolean)

    operation result



650
651
652
653
654
655
656
657
# File 'lib/mutx/results/result.rb', line 650

def save!
  if Mutx::Database::MongoConnector.result_data_for_id(id)          
    Mutx::Database::MongoConnector.update_result(result_data_structure)
  else
    Mutx::Database::MongoConnector.insert_result(result_data_structure)
  end
  # Mutx::Support::Log.debug "[#{@id}] Result saved" if Mutx::Support::Log
end

#save_reportObject

Reads, copy html report from cucumber output file and saves it on a instance variable Persists changes on mongo and then deletes the html reporte file



364
365
366
367
368
369
370
371
372
# File 'lib/mutx/results/result.rb', line 364

def save_report
  if is_cucumber? and is_there_a_report_file?
    new_content = Mutx::View::Parser.adapt_to_mutx(read_report, self)
    if new_content.size > @html_report.size
      @html_report = new_content
      Mutx::Support::Log.debug "[#{@id}] Report saved"
    end
  end
end

#save_report_summary_and_status!Object



353
354
355
356
357
358
359
# File 'lib/mutx/results/result.rb', line 353

def save_report_summary_and_status!
  if is_cucumber?
    self.save_report
    self.get_summary!
    self.get_status!
  end
end

#seconds_without_changesObject

Returns the seconds that there is no console output changes only if it is not finished, else returns 0 This is aimed to help to detect if execution is freezed (or has a debugger statement)



611
612
613
# File 'lib/mutx/results/result.rb', line 611

def seconds_without_changes
  (self.finished? or self.stopped?) ? 0 : (now_in_seconds - @last_check_time)
end

#set_result_value!Object



254
255
256
257
258
259
260
# File 'lib/mutx/results/result.rb', line 254

def set_result_value!
  if is_cucumber?
    get_result_from_summary!
  else 
    eval_regex!
  end
end

#started?Boolean

Returns:

  • (Boolean)


519
520
521
# File 'lib/mutx/results/result.rb', line 519

def started?
  @status == "started"
end

#started_at_formattedString

Returns the started at time attribute in a format way (configured on mutx info)

Returns:

  • (String)


631
632
633
# File 'lib/mutx/results/result.rb', line 631

def started_at_formatted
  Mutx::Support::TimeHelper.formatted_time_for @started_at
end

#stopped?Boolean

Returns:

  • (Boolean)


541
542
543
# File 'lib/mutx/results/result.rb', line 541

def stopped?
  @status =~ /(reset|stopped)/i
end

#summary?Boolean

Returns:

  • (Boolean)


400
401
402
# File 'lib/mutx/results/result.rb', line 400

def summary?
  !(["Not available yet", "running", "started"].include? @summary)
end

#task_idObject



203
204
205
# File 'lib/mutx/results/result.rb', line 203

def task_id
  @task["id"]
end

#task_typeObject



211
212
213
# File 'lib/mutx/results/result.rb', line 211

def task_type
  @task["type"]
end

#time_to_live_reached?Boolean

Returns:

  • (Boolean)


615
616
617
# File 'lib/mutx/results/result.rb', line 615

def time_to_live_reached?
  self.seconds_without_changes > Mutx::Support::Configuration.execution_time_to_live
end

#update_console_output(output) ⇒ Object



491
492
493
494
495
496
497
498
499
# File 'lib/mutx/results/result.rb', line 491

def update_console_output output
  if output.size > @console_output.size
    @console_output = output
    mark_last_check_time
    self.save!
  else
    raise ExecutionTimeoutError.new("Execution Timeout reached") if (now_in_seconds - @last_check_time) > Mutx::Support::Configuration.execution_time_to_live
  end
end

#validate_params(custom_params = {}) ⇒ hash

Returns a hash with valid parameters. This is to prevent command line command with could cause problems

Parameters:

  • custom (hash)

    params

Returns:

  • (hash)

    validated custom params



168
169
170
171
172
173
174
175
176
177
# File 'lib/mutx/results/result.rb', line 168

def validate_params custom_params={}
  unless custom_params.nil?
    validated = custom_params.select do |key, value|
      unless value.nil?
        Mutx::Support::Risk.secure? value
      end
    end
  end
  validated || {}
end