liri 0.1.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +4 -2
  3. data/.simplecov +8 -0
  4. data/Gemfile +4 -1
  5. data/Gemfile.lock +27 -15
  6. data/bash_script_examples.sh +1 -0
  7. data/dummy-app/.gitignore +12 -0
  8. data/dummy-app/.rspec +3 -0
  9. data/dummy-app/.ruby-gemset +1 -0
  10. data/dummy-app/.ruby-version +1 -0
  11. data/dummy-app/CODE_OF_CONDUCT.md +84 -0
  12. data/dummy-app/Gemfile +10 -0
  13. data/dummy-app/Gemfile.lock +35 -0
  14. data/dummy-app/LICENSE.txt +21 -0
  15. data/dummy-app/README.md +43 -0
  16. data/dummy-app/Rakefile +8 -0
  17. data/dummy-app/bin/console +15 -0
  18. data/dummy-app/bin/setup +8 -0
  19. data/dummy-app/dummy-app.gemspec +39 -0
  20. data/dummy-app/lib/dummy/app/version.rb +7 -0
  21. data/dummy-app/lib/dummy/app.rb +10 -0
  22. data/dummy-app/spec/dummy/app_spec.rb +11 -0
  23. data/dummy-app/spec/dummy/dummy_spec.rb +11 -0
  24. data/dummy-app/spec/spec_helper.rb +15 -0
  25. data/exe/liri +9 -4
  26. data/lib/agent/agent.rb +91 -50
  27. data/lib/agent/runner.rb +1 -3
  28. data/lib/all_libraries.rb +4 -2
  29. data/lib/common/benchmarking.rb +5 -10
  30. data/lib/common/log.rb +12 -6
  31. data/lib/common/manager_data.rb +30 -0
  32. data/lib/common/progressbar.rb +29 -0
  33. data/lib/common/setup.rb +103 -0
  34. data/lib/common/source_code.rb +22 -12
  35. data/lib/common/tests_result.rb +115 -0
  36. data/lib/common/unit_test/rspec.rb +14 -35
  37. data/lib/liri.rb +26 -35
  38. data/lib/manager/manager.rb +167 -105
  39. data/lib/task.rb +2 -2
  40. data/liri.gemspec +8 -0
  41. data/spec_credentials.yml.example +4 -0
  42. data/template/liri-config.yml +5 -2
  43. metadata +55 -4
  44. data/lib/manager/setup.rb +0 -70
  45. data/lib/manager/test_result.rb +0 -38
@@ -0,0 +1,115 @@
1
+ # = tests_result.rb
2
+ #
3
+ # @author Rodrigo Fernández
4
+ #
5
+ # == Clase TestsResult
6
+
7
+ module Liri
8
+ module Common
9
+ # Esta clase se encarga de guardar y procesar el archivo de resultados
10
+ class TestsResult
11
+ def initialize(folder_path)
12
+ @folder_path = folder_path
13
+ @example_quantity = 0
14
+ @failure_quantity = 0
15
+ @passed_quantity = 0
16
+ @failures = ''
17
+ end
18
+
19
+ def save(file_name, raw_tests_result)
20
+ file_path = File.join(@folder_path, '/', file_name)
21
+ File.write(file_path, raw_tests_result)
22
+ file_path
23
+ end
24
+
25
+ def build_file_name(agent_ip_address, tests_batch_number)
26
+ "batch_#{tests_batch_number}_agent_#{agent_ip_address}_tests_results"
27
+ end
28
+
29
+ # Procesa el resultado crudo de las pruebas unitarias y lo devuelve en formato hash manejable
30
+ # Ejemplo del hash retornado:
31
+ # {example_quantity: 2, failure_quantity: 1}
32
+ def process(tests_result_file_name)
33
+ file_path = File.join(@folder_path, '/', tests_result_file_name)
34
+ result_hash = process_tests_result_file(file_path)
35
+ update_partial_result(result_hash)
36
+ #print_partial_result(result_hash)
37
+ result_hash
38
+ end
39
+
40
+ def print_summary
41
+ puts "\n#{@example_quantity} examples, #{@failure_quantity} failures\n"
42
+ end
43
+
44
+ def print_failures
45
+ puts "\nFailures: " if !@failures.empty?
46
+ puts @failures
47
+ end
48
+
49
+ private
50
+
51
+ # Recibe el resultado crudo de las pruebas unitarias
52
+ # Procesa el archivo con los resultados crudos y lo devuelve en formato hash manejable
53
+ # Ejemplo del hash retornado:
54
+ # {result: '.F', failures: '', example_quantity: 2, failure_quantity: 1, failed_examples: ''}
55
+ def process_tests_result_file(file_path)
56
+ result_hash = {failures: '', example_quantity: 0, failure_quantity: 0, passed_quantity: 0, failed_examples: ''}
57
+ flag = ''
58
+ File.foreach(file_path) do |line|
59
+ if flag == '' && line.strip.start_with?('Randomized')
60
+ flag = 'Randomized'
61
+ next
62
+ end
63
+
64
+ if ['Randomized', ''].include?(flag) && line.strip.start_with?('Failures')
65
+ flag = 'Failures'
66
+ next
67
+ end
68
+
69
+ if ['Randomized', 'Failures', ''].include?(flag) && line.strip.start_with?('Finished')
70
+ flag = 'Finished'
71
+ next
72
+ end
73
+
74
+ if ['Finished', ''].include?(flag) && line.strip.start_with?('Failed')
75
+ flag = 'Failed'
76
+ next
77
+ end
78
+
79
+ case flag
80
+ when 'Failures'
81
+ result_hash[:failures] << line
82
+ when 'Finished'
83
+ values = line.to_s.match(/([\d]+) example.?, ([\d]+) failure.?/)
84
+ result_hash[:example_quantity] = values[1].to_i
85
+ result_hash[:failure_quantity] = values[2].to_i
86
+ result_hash[:passed_quantity] = result_hash[:example_quantity] - result_hash[:failure_quantity]
87
+ flag = ''
88
+ when 'Failed'
89
+ result_hash[:failed_examples] << line
90
+ end
91
+ end
92
+
93
+ result_hash
94
+ end
95
+
96
+ def update_partial_result(hash_result)
97
+ @example_quantity += hash_result[:example_quantity]
98
+ @failure_quantity += hash_result[:failure_quantity]
99
+ @passed_quantity += hash_result[:passed_quantity]
100
+ @failures << hash_result[:failures]
101
+ end
102
+
103
+ def print_partial_result(result_hash)
104
+ result_hash[:passed_quantity].times do
105
+ print '.'
106
+ end
107
+
108
+ result_hash[:failure_quantity].times do
109
+ print 'F'
110
+ end
111
+ end
112
+
113
+ end
114
+ end
115
+ end
@@ -15,18 +15,8 @@ module Liri
15
15
  tests_count = 1
16
16
  tests_hash = {}
17
17
  test_files.each do |test_file|
18
- File.open(test_file) do |file|
19
- file.each_with_index do |line, index|
20
- if line.strip.start_with?('it')
21
- absolute_file_path = file.to_path
22
- relative_file_path = absolute_file_path.sub(@source_code_folder_path + '/', '')
23
-
24
- test_line = relative_file_path + ":#{index + 1}"
25
- tests_hash[tests_count] = test_line
26
- tests_count += 1
27
- end
28
- end
29
- end
18
+ tests_hash[tests_count] = test_file.sub(@source_code_folder_path + '/', '')
19
+ tests_count += 1
30
20
  end
31
21
  tests_hash
32
22
  end
@@ -50,40 +40,29 @@ module Liri
50
40
  raw_tests_result = %x|bash -lc 'rvm use #{Liri.current_folder_ruby_and_gemset}; rspec #{tests.join(' ')} --format progress'|
51
41
  end
52
42
 
53
- hash_tests_result = process_tests_result(raw_tests_result)
54
- hash_tests_result
43
+ return raw_tests_result
55
44
  end
56
45
  end
57
46
 
58
47
  private
48
+
59
49
  def test_files
60
50
  Dir[@tests_folder_path + "/**/*spec.rb"]
61
51
  end
62
52
 
63
- # Recibe el resultado crudo de las pruebas unitarias
64
- # Procesa el resultado y lo devuelve en formato hash manejable
65
- # Ejemplo del hash retornado:
66
- # {example_quantity: 2, failure_quantity: 1}
67
- def process_tests_result(raw_test_results)
68
- result_hash = {example_quantity: 0, failure_quantity: 0}
69
- flag = ''
70
- raw_test_results.each_line do |line|
71
- if line.strip.start_with?('Finished')
72
- flag = 'Finished'
73
- next
74
- end
53
+ # Revisa si la línea se encuentra dentro de un bloque comentado
54
+ def line_inside_comment_block(line)
55
+ if line.strip.start_with?('=begin')
56
+ @inside_comment = true
57
+ return true
58
+ end
75
59
 
76
- if flag == 'Finished'
77
- puts ''
78
- Liri.logger.info(line)
79
- values = line.to_s.match(/([\d]+) example.?, ([\d]+) failure.?/)
80
- result_hash[:example_quantity] = values[1].to_i
81
- result_hash[:failure_quantity] = values[2].to_i
82
- flag = ''
83
- end
60
+ if line.strip.start_with?('=end')
61
+ @inside_comment = false
62
+ return false
84
63
  end
85
64
 
86
- result_hash
65
+ return true if @inside_comment
87
66
  end
88
67
  end
89
68
  end
data/lib/liri.rb CHANGED
@@ -3,20 +3,16 @@
3
3
  # Este modulo contiene datos del programa que son reutilizados en otras partes de la aplicacion
4
4
  module Liri
5
5
  NAME = 'liri' # El gemspec requiere que el nombre este en minusculas
6
- VERSION = '0.1.0'
7
- SETUP_FOLDER_NAME = 'liri'
8
- SETUP_FOLDER_PATH = File.join(Dir.pwd, '/', SETUP_FOLDER_NAME)
9
- LOGS_FOLDER_NAME = 'logs'
10
- MANAGER_LOGS_FOLDER_PATH = File.join(SETUP_FOLDER_PATH, '/', LOGS_FOLDER_NAME)
11
- AGENT_LOGS_FOLDER_PATH = MANAGER_LOGS_FOLDER_PATH
12
- AGENT_FOLDER_NAME = 'agent'
13
- AGENT_FOLDER_PATH = File.join(SETUP_FOLDER_PATH, '/', AGENT_FOLDER_NAME)
14
- MANAGER_FOLDER_NAME = 'manager'
15
- MANAGER_FOLDER_PATH = File.join(SETUP_FOLDER_PATH, '/', MANAGER_FOLDER_NAME)
6
+ VERSION = '0.3.0'
16
7
 
17
8
  class << self
9
+ def set_setup(destination_folder_path)
10
+ load_setup_manager(destination_folder_path)
11
+ end
12
+
13
+ # Carga las configuraciones en memoria desde un archivo de configuracion
18
14
  def setup
19
- @setup ||= load_setup
15
+ @setup
20
16
  end
21
17
 
22
18
  def logger
@@ -36,30 +32,16 @@ module Liri
36
32
  end
37
33
  end
38
34
 
39
- def create_folders(program)
40
- Dir.mkdir(SETUP_FOLDER_PATH) unless Dir.exist?(SETUP_FOLDER_PATH)
41
-
42
- case program
43
- when 'manager'
44
- Dir.mkdir(MANAGER_LOGS_FOLDER_PATH) unless Dir.exist?(MANAGER_LOGS_FOLDER_PATH)
45
- Dir.mkdir(MANAGER_FOLDER_PATH) unless Dir.exist?(MANAGER_FOLDER_PATH)
46
- when 'agent'
47
- Dir.mkdir(AGENT_FOLDER_PATH) unless Dir.exist?(AGENT_FOLDER_PATH)
48
- Dir.mkdir(AGENT_LOGS_FOLDER_PATH) unless Dir.exist?(AGENT_LOGS_FOLDER_PATH)
49
- end
50
- end
51
-
52
- def clean_folder(folder_path)
35
+ def clean_folder_content(folder_path)
53
36
  FileUtils.rm_rf(Dir.glob(folder_path + '/*')) if Dir.exist?(folder_path)
54
37
  end
55
38
 
56
39
  def reload_setup
57
- @setup = load_setup
40
+ @setup = (@setup_manager ? @setup_manager.load : nil)
58
41
  end
59
42
 
60
43
  def delete_setup
61
- liri_setup = Liri::Manager::Setup.new(SETUP_FOLDER_PATH)
62
- liri_setup.delete
44
+ @setup_manager ? @setup_manager.delete_setup_folder : false
63
45
  end
64
46
 
65
47
  def init_exit(stop, threads, program)
@@ -75,7 +57,7 @@ module Liri
75
57
  end
76
58
 
77
59
  def kill(threads)
78
- threads.each{|thread| Thread.kill(thread)}
60
+ threads.each{ |thread| Thread.kill(thread) }
79
61
  end
80
62
 
81
63
  def current_host_ip_address
@@ -99,22 +81,31 @@ module Liri
99
81
  setup.ports.tcp
100
82
  end
101
83
 
84
+ def print_failures
85
+ setup.print_failures
86
+ end
87
+
88
+ def udp_request_delay
89
+ setup.udp_request_delay
90
+ end
91
+
102
92
  def current_folder_ruby_and_gemset
103
93
  "#{File.read('.ruby-version').strip}@#{File.read('.ruby-gemset').strip}"
104
94
  end
105
95
 
106
96
  private
107
97
 
108
- # Carga las configuraciones en memoria desde un archivo de configuracion
109
- def load_setup
110
- liri_setup = Liri::Manager::Setup.new(SETUP_FOLDER_PATH)
111
- liri_setup.create unless File.exist?(liri_setup.path)
112
- liri_setup.load
98
+ # Inicializa el objeto que gestiona las configuraciones
99
+ def load_setup_manager(destination_folder_path)
100
+ @setup_manager = Liri::Common::Setup.new(destination_folder_path)
101
+ @setup_manager.init
102
+ @setup = @setup_manager.load
103
+ @setup_manager
113
104
  end
114
105
 
115
106
  # Inicializa y configura la librería encargada de loguear
116
107
  def load_logger(folder_path = nil, file_name = nil)
117
- log = Liri::Common::Log.new('daily', folder_path: folder_path, file_name: file_name, stdout: Liri.setup.log.stdout.show)
108
+ log = Liri::Common::Log.new('daily', folder_path: folder_path, file_name: file_name, stdout: setup.log.stdout.show)
118
109
  log
119
110
  end
120
111
  end