Betriebssicherheit: Sperre gegen parallele Läufe, Upsert, Batch-Schreiben für Postgres, Zeichensatz für CSV
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
require_relative '../test_helper'
|
||||
|
||||
class LockTest < PipelineTest
|
||||
def test_second_lock_on_the_same_file_fails
|
||||
with_tmpdir do |dir|
|
||||
first = DataPipeline::Lock.new("#{dir}/sub/.lock").acquire
|
||||
assert first.locked?
|
||||
error = assert_raises(DataPipeline::LockError) { DataPipeline::Lock.new("#{dir}/sub/.lock").acquire }
|
||||
assert_includes error.message, "pid #{Process.pid}"
|
||||
first.release
|
||||
DataPipeline::Lock.new("#{dir}/sub/.lock").synchronize { assert true }
|
||||
end
|
||||
end
|
||||
|
||||
def test_pipeline_holds_the_lock_during_run_and_releases_it
|
||||
with_tmpdir do |dir|
|
||||
file = "#{dir}/.lock"
|
||||
inside = nil
|
||||
run_pipeline([{ 'a' => 1 }]) do
|
||||
lock file
|
||||
map { |row| inside = (DataPipeline::Lock.new(file).acquire rescue $!); row }
|
||||
end
|
||||
assert_kind_of DataPipeline::LockError, inside
|
||||
DataPipeline::Lock.new(file).synchronize { assert true } # released after run
|
||||
end
|
||||
end
|
||||
|
||||
def test_locked_pipeline_aborts_with_lock_error_and_writes_nothing
|
||||
with_tmpdir do |dir|
|
||||
holder = DataPipeline::Lock.new("#{dir}/.lock").acquire
|
||||
target = MemoryStorage.new
|
||||
finished = nil
|
||||
assert_raises(DataPipeline::LockError) do
|
||||
DataPipeline.new do
|
||||
logger PipelineHelper::QUIET
|
||||
lock "#{dir}/.lock"
|
||||
read MemoryStorage.new(rows: [{ 'a' => 1 }])
|
||||
write target
|
||||
on_finish { |stats| finished = stats }
|
||||
end.run
|
||||
end
|
||||
assert_nil target.written
|
||||
assert_kind_of DataPipeline::LockError, finished.error
|
||||
holder.release
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user