Skip to content

Commit

Permalink
WIP: try something else
Browse files Browse the repository at this point in the history
  • Loading branch information
Flink committed May 16, 2023
1 parent dc6309e commit e92e4f7
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 18 deletions.
1 change: 0 additions & 1 deletion .rspec
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
--color
--require spec_helper
--order random
3 changes: 0 additions & 3 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,3 @@ stop_dummy_rails_server:

teardown_dummy_rails_server:
@cd spec/support/dummy_app && (! (bundle check > /dev/null 2>&1) || BUNDLE_GEMFILE=Gemfile DISABLE_DATABASE_ENVIRONMENT_CHECK=1 RAILS_ENV=production $(BUNDLER_BIN) exec rails db:drop)

db_seed_dummy_rails_server:
@cd spec/support/dummy_app && BUNDLE_GEMFILE=Gemfile RAILS_ENV=production $(BUNDLER_BIN) exec rails db:seed
24 changes: 14 additions & 10 deletions spec/integration/active_record_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ def stop_dummy_rails_server

def restart_dummy_rails_server
stop_dummy_rails_server
system("make db_seed_dummy_rails_server")
start_dummy_rails_server
end

Expand Down Expand Up @@ -97,17 +96,22 @@ def restart_dummy_rails_server
expect(response.body).to include("writing")
end

it "should failover if PG exception is raised before ActionDispatch::DebugExceptions" do
flood_get("/trigger-middleware-pg-exception", times: 10) do |response|
expect(response.code.to_i).to eq(500)
context "when PG exception is raised before ActionDispatch::DebugExceptions" do
let(:path) do
Pathname.new("#{__dir__}/../support/dummy_app/triggered_from_pg_exception.writing")
end

sleep 5
response = get("/posts")
after { FileUtils.rm_f(path) }

expect(response.code.to_i).to eq(200)
expect(response.body).to include("triggered_from_pg_exception:writing")
ensure
restart_dummy_rails_server
it "fails over" do
flood_get("/trigger-middleware-pg-exception", times: 10) do |response|
expect(response.code.to_i).to eq(500)
end

sleep 0.5
response = get("/posts")
expect(response.code.to_i).to eq(200)
expect(path.exist?).to be true
end
end
end
1 change: 0 additions & 1 deletion spec/support/dummy_app/app/controllers/posts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ class PostsController < ApplicationController
def index
@posts_count = Post.count
@role = request.env["rails_failover.role"]
@last_post_body = Post.last.body
end

def trigger_pg_server_error
Expand Down
1 change: 0 additions & 1 deletion spec/support/dummy_app/app/views/posts/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
<%= @role %>
<%= @posts_count %>
<%= @last_post_body %>
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def initialize(app)
def call(env)
if env["REQUEST_PATH"] == "/trigger-middleware-pg-exception"
RailsFailover::ActiveRecord.on_failover do |role|
Post.create!(body: "triggered_from_pg_exception:#{role}")
FileUtils.touch("#{Rails.root}/triggered_from_pg_exception.#{role}")
end
raise ::PG::UnableToSend
else
Expand Down
1 change: 0 additions & 1 deletion spec/support/dummy_app/db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@
# movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }])
# Character.create(name: 'Luke', movie: movies.first)

Post.delete_all
100.times { |i| Post.create!(body: "a" * i) }

0 comments on commit e92e4f7

Please sign in to comment.