oyencov 0.0.9 → 0.0.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 284aeba7dff7bdcad7911b65bf24a3cf2126730ab050e1468e35d68c42241e01
4
- data.tar.gz: e88b831a197f736e59f6912d9083d6885b5adb811d80a092bd143f36dcee92f8
3
+ metadata.gz: 6002d91269a3df5ab927906b23aa43d19491319ea03946ac3e4fe17b71580b1f
4
+ data.tar.gz: 146126aecfb5d2e642d598a1552e7a1964bf025d284218ced8492542ed1b164a
5
5
  SHA512:
6
- metadata.gz: fc0857d3ba42f0fcbb5dcc1806ed19e19577cbafef96f814baaed18e4a8da4fcce0b9d2a75a1408410407e0e55534140b3ed1aeac7ed0fc574b8cfb397daaabd
7
- data.tar.gz: d4e63b3c9f0837996ef371509b8935e1ed20b72fd7d7bffd2892e1e276f19241af18763985db8186a8ddbcdec9697e9eee63e1d0449df31af4118570c567d144
6
+ metadata.gz: c4f91c7983f7291de4d6666cd8ac821960f6511eb75097620528678ef8a285676a0124f95e6b82c5105157ce2173faf733864be16ed061998a8236fb4e26fbcd
7
+ data.tar.gz: 14deea365dc87c6dbba325ae707c0100bec1f0df7e7b937088e20a6483fb5980c9433b03d613a70129202ef484baf1758279f23ebc5811e870d53a3ae216bce5
@@ -27,7 +27,7 @@ module OyenCov
27
27
  begin
28
28
  response = get("/v1/data_submission_clearance")
29
29
 
30
- if Hash === response.body && response.body["status"] == "ok"
30
+ if Hash === response.body # && response.body["status"] == "ok"
31
31
  response.body
32
32
  else
33
33
  false
@@ -17,14 +17,24 @@ require_relative "logger"
17
17
  #
18
18
  module OyenCov
19
19
  class Background
20
+ # Added to be more fork-aware. Ruby/Puma can fork a process copy-on-write,
21
+ # but it won't start the threads that are running in the parent process.
22
+ #
23
+ # If the PID > 0 but also not the current process_id, make the thread run.
24
+ @@running_pid = 0
25
+
20
26
  @loop_interval = 60 # seconds, can be set from server
21
- @semaphore = Mutex.new
22
27
  @thread = nil
23
28
  @reporter = nil
24
29
  @api_conn = OyenCov::APIConnection.instance
25
30
  @config = OyenCov.config
26
31
 
27
32
  def self.start
33
+ if @@running_pid == $$
34
+ OyenCov::Logger.log("OyenCov Background thread is already running.")
35
+ return false
36
+ end
37
+
28
38
  OyenCov::Logger.log(<<~TXT)
29
39
  Env: #{@config.mode}
30
40
  program_name: #{$PROGRAM_NAME || "nil"}
@@ -45,7 +55,7 @@ module OyenCov
45
55
  clearance = @api_conn.get_data_submission_clearance
46
56
 
47
57
  unless clearance && clearance["status"] == "ok"
48
- OyenCov::Logger.log "Unable to obtain oyencov submission clearance. Stopping OyenCov background thread."
58
+ OyenCov::Logger.log "Unable to obtain oyencov submission clearance. Stopping OyenCov background thread. #{clearance.inspect}"
49
59
  Thread.stop
50
60
  end
51
61
 
@@ -79,6 +89,7 @@ module OyenCov
79
89
  OyenCov::Logger.log "POST runtime_report ok."
80
90
  else
81
91
  OyenCov::Logger.log "POST runtime_report failed. Stopping background thread."
92
+ @@running_pid = 0
82
93
  Thread.stop
83
94
  end
84
95
 
@@ -87,6 +98,8 @@ module OyenCov
87
98
  }
88
99
 
89
100
  @thread.run
101
+ OyenCov::Logger.log("OyenCov Background thread starts.")
102
+ @@running_pid = $$
90
103
 
91
104
  nil
92
105
  end
@@ -95,6 +108,7 @@ module OyenCov
95
108
  # For `test`, persist controller report.
96
109
  def self.stop
97
110
  @thread.stop
111
+ @@running_pid = 0
98
112
  end
99
113
 
100
114
  private_class_method
data/lib/oyencov/cli.rb CHANGED
@@ -82,11 +82,9 @@ module OyenCov
82
82
  "git_commit_sha" => options[:git_commit_sha]
83
83
  })
84
84
 
85
- # puts JSON.pretty_generate(collated_report)
86
-
87
- # Add metadaata
88
-
89
- ENV["OYENCOV_API_KEY"] ||= options[:token]
85
+ if options[:token]
86
+ ENV["OYENCOV_API_KEY"] = options[:token]
87
+ end
90
88
  unless ENV["OYENCOV_API_KEY"]
91
89
  warn "API token not set. Unable to submit."
92
90
  exit(1)
@@ -42,7 +42,7 @@ module OyenCov
42
42
 
43
43
  # Lots of ideas came from sentry-ruby, thanks to nate berkopec.
44
44
  def suggest_release
45
- release = `git rev-parse HEAD ||:`.strip
45
+ release = `git rev-parse HEAD 2>/dev/null || true`.strip
46
46
 
47
47
  if release == "" || release.nil?
48
48
  [".source_version", "REVISION"].each do |version_clue|
@@ -52,8 +52,8 @@ module OyenCov
52
52
  filtered.each_pair do |fpath, line_hits|
53
53
  MethodRangeParser[fpath]&.each_pair do |method_name, line_num|
54
54
  # puts [method_name, line_num, line_hits[line_num]]
55
- next if line_num.nil? || line_hits[line_num].nil?
56
- current_method_hits[method_name] = line_hits[line_num]
55
+ next if line_num.nil? || line_hits[line_num - 1].nil?
56
+ current_method_hits[method_name] = line_hits[line_num - 1]
57
57
  end
58
58
  end
59
59
 
@@ -12,7 +12,7 @@ module OyenCov
12
12
  if Exception === msg
13
13
  msg = msg.inspect
14
14
  end
15
- formatted_msg = msg.split("\n").map { |m| "#{ORANGE_TEXT}[OyenCov] #{m}#{RESET_COLOR}" }.join("\n")
15
+ formatted_msg = msg.split("\n").map { |m| "#{ORANGE_TEXT}[OyenCov] PID##{$$} #{m}#{RESET_COLOR}" }.join("\n")
16
16
 
17
17
  if level == 2
18
18
  warn formatted_msg
@@ -5,6 +5,8 @@ require_relative "logger"
5
5
 
6
6
  module OyenCov
7
7
  class Railtie < Rails::Railtie
8
+ @@controller_tracker_notification = nil
9
+
8
10
  # This is only useful when `rails s` is run in lieu of webserver command first.
9
11
  def install_puma_hooks
10
12
  return unless defined?(Puma)
@@ -26,12 +28,14 @@ module OyenCov
26
28
  initializer "oyencov.configure" do
27
29
  OyenCov::Background.start
28
30
  install_puma_hooks
29
- end
30
31
 
31
- config.after_initialize do
32
- OyenCov::Logger.log("lib/oyencov/railtie.rb config.after_initialize")
32
+ if @@controller_tracker_notification.nil?
33
+ OyenCov::Logger.log "@@controller_tracker_notification is nil"
34
+ else
35
+ OyenCov::Logger.log "@@controller_tracker_notification is already set, Railtie init rerun."
36
+ end
33
37
 
34
- ActiveSupport::Notifications.subscribe("start_processing.action_controller") do |name, start, finish, id, payload|
38
+ @@controller_tracker_notification ||= ActiveSupport::Notifications.subscribe("start_processing.action_controller") do |name, start, finish, id, payload|
35
39
  ControllerTracking.bump("#{payload[:controller]}##{payload[:action]}")
36
40
  OyenCov::Logger.log "ControllerTracking.bump(#{payload[:controller]}##{payload[:action]})"
37
41
  end
@@ -1,3 +1,3 @@
1
1
  module OyenCov
2
- VERSION = "0.0.9".freeze
2
+ VERSION = "0.0.11".freeze
3
3
  end
data/lib/oyencov.rb CHANGED
@@ -11,14 +11,20 @@ module OyenCov
11
11
 
12
12
  # Sometimes oyencov cant start on their own, maybe when oyencov is loaded
13
13
  # before Rails did.
14
- #
14
+ #
15
15
  # For Rails, put `OyenCov.start!` in `config/initializers/oyencov.rb`.
16
16
  def self.start!
17
17
  require_relative "oyencov/railtie"
18
18
  end
19
19
 
20
20
  OyenCov::Logger.log("Hello! Booting from #{__FILE__}")
21
- OyenCov::Logger.log("Checking Rails existence")
21
+ OyenCov::Logger.log("Checking/Forcing Rails existence")
22
+
23
+ begin
24
+ require "rails"
25
+ rescue LoadError
26
+ # do nothing
27
+ end
22
28
 
23
29
  if defined?(Rails::Railtie) # && ENV["OYENCOV_API_KEY"]
24
30
  OyenCov::Logger.log("Rails::Railtie already present, starting oyencov/railtie")
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oyencov
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anonoz Chong
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-05-08 00:00:00.000000000 Z
11
+ date: 2024-06-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday