Skip to content

Commit

Permalink
Add specs for Follower#lag
Browse files Browse the repository at this point in the history
  • Loading branch information
spuun committed Apr 4, 2024
1 parent e91532e commit 04d7cda
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions spec/replication/follower_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,28 @@ module FollowerSpec
file_list.should eq file_index.@files_with_hash
end
end

describe "#lag" do
it "should count bytes added to action queue" do
follower_socket, _client_socket = FakeSocket.pair
file_index = FakeFileIndex.new
follower = LavinMQ::Replication::Follower.new(follower_socket, file_index)
filename = "#{LavinMQ::Config.instance.data_dir}/file1"
size = follower.append filename, Bytes.new(10)
follower.lag.should eq size
end

it "should subtract acked bytes from lag" do
follower_socket, client_socket = FakeSocket.pair
file_index = FakeFileIndex.new
follower = LavinMQ::Replication::Follower.new(follower_socket, file_index)
filename = "#{LavinMQ::Config.instance.data_dir}/file1"
size = follower.append filename, Bytes.new(10)
size2 = follower.append filename, Bytes.new(20)
# send ack for first message
client_socket.write_bytes size.to_i64, IO::ByteFormat::LittleEndian
follower.read_ack
follower.lag.should eq size2
end
end
end

0 comments on commit 04d7cda

Please sign in to comment.