A platform for community discussion. Free, open, simple.
MT: Clarify ForkManager hook API names
Gerhard Schlager24b339581efb
diff --git a/migrations/converters/lib/migrations/converters/adapter/postgres.rb b/migrations/converters/lib/migrations/converters/adapter/postgres.rbindex 9b11d5015f2..7c3c81c7e0f 100644--- a/migrations/converters/lib/migrations/converters/adapter/postgres.rb+++ b/migrations/converters/lib/migrations/converters/adapter/postgres.rb@@ -55,7 +55,7 @@ module Migrations@connection = nilif @fork_hook- ForkManager.remove_after_fork_child_hook(@fork_hook)+ ForkManager.remove_after_fork_child(@fork_hook)@fork_hook = nilendenddiff --git a/migrations/converters/spec/lib/migrations/converters/adapter/postgres_spec.rb b/migrations/converters/spec/lib/migrations/converters/adapter/postgres_spec.rbindex fa2a7b099d1..79524debead 100644--- a/migrations/converters/spec/lib/migrations/converters/adapter/postgres_spec.rb+++ b/migrations/converters/spec/lib/migrations/converters/adapter/postgres_spec.rb@@ -28,12 +28,12 @@ RSpec.describe Migrations::Converters::Adapter::Postgres doendit "registers a fork hook on creation and removes it on `close`" do- expect(Migrations::ForkManager.size).to eq(0)+ expect(Migrations::ForkManager.hook_count).to eq(0)create_adapter do |adapter|- expect(Migrations::ForkManager.size).to eq(1)+ expect(Migrations::ForkManager.hook_count).to eq(1)adapter.close- expect(Migrations::ForkManager.size).to eq(0)+ expect(Migrations::ForkManager.hook_count).to eq(0)endend@@ -70,7 +70,7 @@ RSpec.describe Migrations::Converters::Adapter::Postgres doexpect { adapter.close }.to_not raise_errorexpect(connection).to_not have_received(:finish)- expect(Migrations::ForkManager.size).to eq(0)+ expect(Migrations::ForkManager.hook_count).to eq(0)endendenddiff --git a/migrations/core/lib/migrations/common/fork_manager.rb b/migrations/core/lib/migrations/common/fork_manager.rbindex 7f905d53b74..168bf27d382 100644--- a/migrations/core/lib/migrations/common/fork_manager.rb+++ b/migrations/core/lib/migrations/common/fork_manager.rb@@ -8,7 +8,7 @@ module Migrations@execute_parent_forks = trueclass << self- def batch_forks+ def with_batched_forks@execute_parent_forks = falserun_before_fork_hooks@@ -25,7 +25,7 @@ module Migrationsendend- def remove_before_fork_hook(block)+ def remove_before_fork(block)@before_fork_hooks.delete(block)end@@ -36,7 +36,7 @@ module Migrationsendend- def remove_after_fork_parent_hook(block)+ def remove_after_fork_parent(block)@after_fork_parent_hooks.delete(block)end@@ -47,7 +47,7 @@ module Migrationsendend- def remove_after_fork_child_hook(block)+ def remove_after_fork_child(block)@after_fork_child_hooks.delete(block)end@@ -65,7 +65,7 @@ module Migrationspidend- def size+ def hook_count@before_fork_hooks.size + @after_fork_parent_hooks.size + @after_fork_child_hooks.sizeenddiff --git a/migrations/core/lib/migrations/conversion/progress_step_executor.rb b/migrations/core/lib/migrations/conversion/progress_step_executor.rbindex 2e80187a3a8..dd9d709702e 100644--- a/migrations/core/lib/migrations/conversion/progress_step_executor.rb+++ b/migrations/core/lib/migrations/conversion/progress_step_executor.rb@@ -109,7 +109,7 @@ module MigrationsProcess.warmup- ForkManager.batch_forks do+ ForkManager.with_batched_forks doWORKER_COUNT.times do |index|job = ParallelJob.new(@step.create_processor)workers << Worker.new(index, work_queue, worker_output_queue, job).startdiff --git a/migrations/core/lib/migrations/database/connection.rb b/migrations/core/lib/migrations/database/connection.rbindex b46c56cc595..67362ddddec 100644--- a/migrations/core/lib/migrations/database/connection.rb+++ b/migrations/core/lib/migrations/database/connection.rb@@ -40,8 +40,8 @@ module Migrationsclose_connection(keep_path: false)before_hook, after_hook = @fork_hooks- ForkManager.remove_before_fork_hook(before_hook)- ForkManager.remove_after_fork_parent_hook(after_hook)+ ForkManager.remove_before_fork(before_hook)+ ForkManager.remove_after_fork_parent(after_hook)enddef closed?diff --git a/migrations/core/spec/lib/common/fork_manager_spec.rb b/migrations/core/spec/lib/common/fork_manager_spec.rbindex c02cfb37810..54969acc5cb 100644--- a/migrations/core/spec/lib/common/fork_manager_spec.rb+++ b/migrations/core/spec/lib/common/fork_manager_spec.rb@@ -16,11 +16,11 @@ RSpec.describe Migrations::ForkManager doread_io.closeend- it "runs hooks in every fork created by `batch_forks`" do+ it "runs hooks in every fork created by `with_batched_forks`" doread_io, write_io = IO.pipedescribed_class.after_fork_child { write_io.write("x") }- described_class.batch_forks { 2.times { Process.waitpid(described_class.fork {}) } }+ described_class.with_batched_forks { 2.times { Process.waitpid(described_class.fork {}) } }write_io.closeexpect(read_io.read).to eq("xx")@@ -29,24 +29,24 @@ RSpec.describe Migrations::ForkManager doit "returns the hook so it can be removed again" dohook = described_class.after_fork_child { raise "this hook should not run" }- expect(described_class.size).to eq(1)+ expect(described_class.hook_count).to eq(1)- described_class.remove_after_fork_child_hook(hook)- expect(described_class.size).to eq(0)+ described_class.remove_after_fork_child(hook)+ expect(described_class.hook_count).to eq(0)_, status = Process.waitpid2(described_class.fork {})expect(status).to be_successendend- describe ".remove_after_fork_child_hook" do+ describe ".remove_after_fork_child" doit "stops the removed hook from running while other hooks keep running" doread_io, write_io = IO.pipehook = described_class.after_fork_child { write_io.write("removed") }described_class.after_fork_child { write_io.write("kept") }- described_class.remove_after_fork_child_hook(hook)- expect(described_class.size).to eq(1)+ described_class.remove_after_fork_child(hook)+ expect(described_class.hook_count).to eq(1)Process.waitpid(described_class.fork {})write_io.closediff --git a/migrations/core/spec/lib/database/connection_spec.rb b/migrations/core/spec/lib/database/connection_spec.rbindex e66e46cef07..dc4dac629bc 100644--- a/migrations/core/spec/lib/database/connection_spec.rb+++ b/migrations/core/spec/lib/database/connection_spec.rb@@ -164,12 +164,12 @@ RSpec.describe Migrations::Database::Connection doendit "cleans up fork hooks when connection gets closed" do- expect(Migrations::ForkManager.size).to eq(0)+ expect(Migrations::ForkManager.hook_count).to eq(0)create_connection do |connection|- expect(Migrations::ForkManager.size).to eq(2)+ expect(Migrations::ForkManager.hook_count).to eq(2)connection.close- expect(Migrations::ForkManager.size).to eq(0)+ expect(Migrations::ForkManager.hook_count).to eq(0)endendend