Skip to content

Commit

Permalink
fix replicator spec
Browse files Browse the repository at this point in the history
  • Loading branch information
carlhoerberg committed May 18, 2023
1 parent 340add6 commit 1201586
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
4 changes: 2 additions & 2 deletions spec/replication_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ require "../src/lavinmq/replication/client"

describe LavinMQ::Replication::Client do
it "can synchronize" do
data_dir = "/tmp/lavinmq-follower"
msgs_path = ""
with_channel do |ch|
q = ch.queue("repli")
q.publish_confirm "hello world"
queue = Server.vhosts["/"].queues["repli"].as(LavinMQ::DurableQueue)
msgs_path = queue.@msg_store.@segments.last_value.path
end
data_dir = "/tmp/lavinmq-follower"
FileUtils.rm_rf data_dir
Dir.mkdir_p data_dir
File.copy "#{Server.data_dir}/.replication_secret", "#{data_dir}/.replication_secret"
File.write "#{data_dir}/.replication_secret", Server.@replicator.@password, 0o400
repli = LavinMQ::Replication::Client.new(data_dir)
repli.sync("127.0.0.1", LavinMQ::Config.instance.replication_port)
repli.close
Expand Down
6 changes: 5 additions & 1 deletion src/lavinmq/replication/server.cr
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ module LavinMQ
@files = Set(String).new
@mfiles = Hash(String, MFile).new

def clear
@files.clear
@mfiles.clear
end

def add_file(path : String)
@files << path
each_follower &.add(path, nil)
Expand Down Expand Up @@ -96,7 +101,6 @@ module LavinMQ
password = File.read(path).chomp
rescue File::NotFoundError
password = Random::Secure.base64(32)
Dir.mkdir_p Config.instance.data_dir
File.open(path, "w") do |f|
f.chmod(0o400)
f.print password
Expand Down
1 change: 1 addition & 0 deletions src/lavinmq/server.cr
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ module LavinMQ
def restart
stop
Dir.mkdir_p @data_dir
@replicator.clear
@users = UserStore.new(@data_dir, @replicator)
@vhosts = VHostStore.new(@data_dir, @users, @replicator)
@parameters = ParameterStore(Parameter).new(@data_dir, "parameters.json", @replicator, @log)
Expand Down

0 comments on commit 1201586

Please sign in to comment.