Skip to content

Commit

Permalink
use MFile.open in schema spec
Browse files Browse the repository at this point in the history
So that the files are closed after each spec
  • Loading branch information
carlhoerberg committed Jan 2, 2025
1 parent db97d43 commit 6c2ad12
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions spec/schema_version_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,30 @@ describe LavinMQ::SchemaVersion do
it "Empty file should raise IO::EOFError" do
with_datadir do |data_dir|
path = File.join(data_dir, "test_schema_version")
file = MFile.new(path, 12)
expect_raises(IO::EOFError) do
LavinMQ::SchemaVersion.verify(file, :message)
MFile.open(path, 12) do |file|
expect_raises(IO::EOFError) do
LavinMQ::SchemaVersion.verify(file, :message)
end
end
end
end

it "Should verify schema version" do
with_datadir do |data_dir|
path = File.join(data_dir, "test_schema_version")
file = MFile.new(path, 12)
file.write_bytes LavinMQ::Schema::VERSION
LavinMQ::SchemaVersion.verify(file, :message).should eq LavinMQ::SchemaVersion::VERSIONS[:message]
MFile.open(path, 12) do |file|
file.write_bytes LavinMQ::Schema::VERSION
LavinMQ::SchemaVersion.verify(file, :message).should eq LavinMQ::SchemaVersion::VERSIONS[:message]
end
end
end

it "Deletes empty file and creates a new when it is the first file" do
with_datadir do |data_dir|
path = File.join(data_dir, "msgs.0000000001")
file = MFile.new(path, LavinMQ::Config.instance.segment_size)
file.resize(LavinMQ::Config.instance.segment_size)
MFile.open(path, LavinMQ::Config.instance.segment_size) do |file|
file.resize(LavinMQ::Config.instance.segment_size)
end
# init new message store
msg_store = LavinMQ::Queue::MessageStore.new(data_dir, nil)
msg_store.@segments.first_value.size.should eq 4
Expand All @@ -39,8 +42,9 @@ describe LavinMQ::SchemaVersion do
v.declare_queue("q", true, false)
data_dir = s.vhosts["/"].queues["q"].as(LavinMQ::AMQP::Queue).@msg_store.@queue_data_dir
path = File.join(data_dir, "msgs.0000000002")
file = MFile.new(path, LavinMQ::Config.instance.segment_size)
file.resize(LavinMQ::Config.instance.segment_size)
MFile.open(path, LavinMQ::Config.instance.segment_size) do |file|
file.resize(LavinMQ::Config.instance.segment_size)
end
# init new message store
msg_store = LavinMQ::Queue::MessageStore.new(data_dir, nil)
msg_store.@segments.size.should eq 1
Expand Down

0 comments on commit 6c2ad12

Please sign in to comment.