Skip to content

Commit

Permalink
Fix issues with specs again (#2514)
Browse files Browse the repository at this point in the history
* Fix flaky trap context spec

* We really cannot use eager_load in tests

This makes code loading so unstable that it makes no sense.
  • Loading branch information
solnic authored Jan 21, 2025
1 parent d9c279b commit cceaa6a
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 42 deletions.
14 changes: 14 additions & 0 deletions sentry-ruby/spec/isolated/init.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

require_relative "../spec_helper"

Sentry.init do |config|
config.dsn = Sentry::TestHelper::DUMMY_DSN
end

trap('HUP') do
hub = Sentry.get_main_hub
puts hub.class
end

Process.kill('HUP', Process.pid)
15 changes: 15 additions & 0 deletions sentry-ruby/spec/isolated/init_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

require_relative "../spec_helper"

SimpleCov.command_name "RSpecIsolated"

RSpec.describe Sentry do
context "works within a trap context", when: { ruby_engine?: "ruby" } do
it "doesn't raise error when accessing main hub in trap context" do
out = `ruby spec/isolated/init.rb`

expect(out).to include("Sentry::Hub")
end
end
end
39 changes: 0 additions & 39 deletions sentry-ruby/spec/sentry_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,45 +70,6 @@
end
end
end

context "works within a trap context", when: { ruby_engine?: "ruby", ruby_version?: [:>=, "3.4"] } do
it "doesn't raise error when accessing main hub in trap context" do
read_pipe, write_pipe = IO.pipe

pid = fork do
described_class.init do |config|
config.dsn = Sentry::TestHelper::DUMMY_DSN
end

trap('HUP') do
hub = described_class.get_main_hub

write_pipe.write(hub.class.to_s)
write_pipe.close
end

Process.kill('HUP', Process.pid)
end

write_pipe.close

result = nil
retries = 0

while retries < 10
break if Process.wait(pid)

sleep 0.01

retries += 1
end

result = read_pipe.read
read_pipe.close

expect(result).to eq("Sentry::Hub")
end
end
end

describe "#clone_hub_to_current_thread" do
Expand Down
4 changes: 2 additions & 2 deletions sentry-ruby/spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
require "sentry-ruby"
require "sentry/test_helper"

require "support/profiler"
require "support/stacktrace_test_fixture"
require_relative "support/profiler"
require_relative "support/stacktrace_test_fixture"

RSpec.configure do |config|
# Enable flags like --only-failures and --next-failure
Expand Down
2 changes: 1 addition & 1 deletion sentry-sidekiq/spec/sentry/rails_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def self.name

app.config.hosts = nil
app.config.secret_key_base = "test"
app.config.eager_load = true
app.config.eager_load = false
app.initializer :configure_sentry do
Sentry.init do |config|
config.release = 'beta'
Expand Down

0 comments on commit cceaa6a

Please sign in to comment.