Skip to content

Commit

Permalink
Merge pull request #134 from tdeo/test_forgotten_line
Browse files Browse the repository at this point in the history
Add test to check no line is forgotten when copying 5 lines with stride 2
  • Loading branch information
grobie authored Aug 21, 2018
2 parents 0871939 + 4f479d0 commit 74a1382
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions spec/unit/chunker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,56 @@ def @throttler.stride
@connection.verify
end

it 'correctly copies single record tables when start is not 1' do
@chunker = Lhm::Chunker.new(@migration, @connection, :throttler => @throttler,
:start => 2,
:limit => 2)

@connection.expect(:update, 1) do |stmt|
stmt = stmt.first if stmt.is_a?(Array)
stmt =~ /between 2 and 2/
end

@chunker.run
@connection.verify
end

it 'correctly copies every record tables when difference is a multiple of stride plus one' do
def @throttler.stride
2
end
@chunker = Lhm::Chunker.new(@migration, @connection, :throttler => @throttler,
:start => 1,
:limit => 5)

@connection.expect(:update, 2) do |stmt|
stmt = stmt.first if stmt.is_a?(Array)
stmt =~ /between 1 and 2/
end
@connection.expect(:update, 2) do |stmt|
stmt = stmt.first if stmt.is_a?(Array)
stmt =~ /between 3 and 4/
end
@connection.expect(:update, 1) do |stmt|
stmt = stmt.first if stmt.is_a?(Array)
stmt =~ /between 5 and 5/
end

@chunker.run
@connection.verify
end

it 'separates filter conditions from chunking conditions' do
def @throttler.stride
2
end
@chunker = Lhm::Chunker.new(@migration, @connection, :throttler => @throttler,
:start => 1,
:limit => 2)
@connection.expect(:update, 1) do |stmt|
stmt = stmt.first if stmt.is_a?(Array)
stmt =~ /where \(foo.created_at > '2013-07-10' or foo.baz = 'quux'\) and `foo`/
stmt =~ /between 1 and 2/
end

def @migration.conditions
Expand All @@ -125,12 +168,16 @@ def @migration.conditions
end

it "doesn't mess with inner join filters" do
def @throttler.stride
2
end
@chunker = Lhm::Chunker.new(@migration, @connection, :throttler => @throttler,
:start => 1,
:limit => 2)
@connection.expect(:update, 1) do |stmt|
stmt = stmt.first if stmt.is_a?(Array)
stmt =~ /inner join bar on foo.id = bar.foo_id and/
stmt =~ /between 1 and 2/
end

def @migration.conditions
Expand Down

0 comments on commit 74a1382

Please sign in to comment.