From 04d7cdaa4070d8ed61277510ca02a4bd67a105c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jon=20B=C3=B6rjesson?= Date: Thu, 4 Apr 2024 08:33:25 +0200 Subject: [PATCH] Add specs for Follower#lag --- spec/replication/follower_spec.cr | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/spec/replication/follower_spec.cr b/spec/replication/follower_spec.cr index 881ba5ab7a..be6df9b7f6 100644 --- a/spec/replication/follower_spec.cr +++ b/spec/replication/follower_spec.cr @@ -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