Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass Time::Span to sleep (to please upcoming deprecation) #784

Merged
merged 2 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion spec/api/connections_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ describe LavinMQ::HTTP::ConnectionsController do
with_channel(s, user: "arnold", password: "pw") do
response = http.delete("/api/connections/username/arnold", headers: hdrs)
response.status_code.should eq 204
sleep 0.1
sleep 0.1.seconds
response = http.get("/api/connections/username/arnold", headers: hdrs)
body = JSON.parse(response.body)
body.as_a.empty?.should be_true
Expand Down
10 changes: 5 additions & 5 deletions spec/api/consumers_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe LavinMQ::HTTP::ConsumersController do
with_channel(s) do |ch|
q = ch.queue("")
q.subscribe { }
sleep 0.01
sleep 10.milliseconds
response = http.get("/api/consumers/%2f")
response.status_code.should eq 200
body = JSON.parse(response.body)
Expand All @@ -59,7 +59,7 @@ describe LavinMQ::HTTP::ConsumersController do
with_channel(s) do |ch|
q = ch.queue("")
consumer = q.subscribe { }
sleep 0.01
sleep 10.milliseconds
conn = s.connections.to_a.last.name
response = http.delete("/api/consumers/%2f/#{URI.encode_path(conn)}/#{ch.id}/#{consumer}")
response.status_code.should eq 204
Expand All @@ -74,7 +74,7 @@ describe LavinMQ::HTTP::ConsumersController do
with_channel(s) do |ch|
q = ch.queue("")
consumer = q.subscribe { }
sleep 0.01
sleep 10.milliseconds
response = http.delete("/api/consumers/%2f/#{URI.encode_path("abc")}/#{ch.id}/#{consumer}")
response.status_code.should eq 404
end
Expand All @@ -87,7 +87,7 @@ describe LavinMQ::HTTP::ConsumersController do
conn = s.connections.first.name
q = ch.queue("")
consumer = q.subscribe { }
sleep 0.01
sleep 10.milliseconds
response = http.delete("/api/consumers/%2f/#{URI.encode_path(conn)}/123/#{consumer}")
response.status_code.should eq 404
end
Expand All @@ -100,7 +100,7 @@ describe LavinMQ::HTTP::ConsumersController do
conn = s.connections.first.name
q = ch.queue("")
q.subscribe { }
sleep 0.01
sleep 10.milliseconds
response = http.delete("/api/consumers/%2f/#{URI.encode_path(conn)}/#{ch.id}/test")
response.status_code.should eq 404
end
Expand Down
2 changes: 1 addition & 1 deletion spec/api/definitions_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ describe LavinMQ::HTTP::Server do
response.status_code.should eq 200
# Because we run shovels in a new Fiber we have to make sure the shovel is not started
# after this spec has finished
sleep 0.1 # Start the shovel
sleep 0.1.seconds # Start the shovel
wait_for do
shovels = s.vhosts["/"].shovels.not_nil!
shovels.each_value.all? &.running?
Expand Down
8 changes: 4 additions & 4 deletions spec/api/queues_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ describe LavinMQ::HTTP::QueuesController do
with_channel(s) do |ch|
q = ch.queue("q3", auto_delete: false, durable: true, exclusive: false)
q.publish "m1"
sleep 0.05
sleep 0.05.milliseconds
body = %({
"count": 1,
"ack_mode": "reject_requeue_true",
Expand Down Expand Up @@ -380,7 +380,7 @@ describe LavinMQ::HTTP::QueuesController do
with_channel(s) do |ch|
q = ch.queue("q5", auto_delete: false, durable: true, exclusive: false)
q.publish "m1"
sleep 0.05
sleep 0.05.milliseconds
body = %({
"count": 2,
"ack_mode": "get",
Expand Down Expand Up @@ -414,7 +414,7 @@ describe LavinMQ::HTTP::QueuesController do
with_channel(s) do |ch|
q = ch.queue("q7")
q.publish "m1"
sleep 0.05
sleep 0.05.milliseconds
body = %({
"count": 1,
"ack_mode": "get",
Expand All @@ -433,7 +433,7 @@ describe LavinMQ::HTTP::QueuesController do
with_channel(s) do |ch|
q = ch.queue("q8")
q.publish "m1"
sleep 0.05
sleep 0.05.milliseconds
body = %({
"count": 1,
"ack_mode": "get",
Expand Down
10 changes: 5 additions & 5 deletions spec/clustering_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe LavinMQ::Clustering::Client do
client = HTTP::Client.new("127.0.0.1", 2379)
i = 0
loop do
sleep 0.02
sleep 0.02.seconds
response = client.get("/version")
if response.status.ok?
next if response.body.includes? "not_decided"
Expand Down Expand Up @@ -99,25 +99,25 @@ describe LavinMQ::Clustering::Client do
rescue LavinMQ::Etcd::Error
# expect this when etcd nodes are terminated
end
sleep 0.5
sleep 0.5.seconds
spawn(name: "failover1") do
controller1.run
end
spawn(name: "failover2") do
controller2.run
end
sleep 0.1
sleep 0.1.seconds
leader = listen.receive
case leader
when /1$/
controller1.stop
listen.receive.should match /2$/
sleep 0.1
sleep 0.1.seconds
controller2.stop
when /2$/
controller2.stop
listen.receive.should match /1$/
sleep 0.1
sleep 0.1.seconds
controller1.stop
else fail("no leader elected")
end
Expand Down
4 changes: 2 additions & 2 deletions spec/etcd_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe LavinMQ::Etcd do
# expect this when etcd nodes are terminated
end
w.receive # sync
sleep 0.05
sleep 50.milliseconds
etcd.put "foo", "bar"
w.receive.should eq "bar"
etcd.put "foo", "rab"
Expand Down Expand Up @@ -162,7 +162,7 @@ class EtcdCluster
i = 0
client = HTTP::Client.new("127.0.0.1", 23000 + port)
loop do
sleep 0.02
sleep 0.02.seconds
response = client.get("/version")
if response.status.ok?
next if response.body.includes? "not_decided"
Expand Down
2 changes: 1 addition & 1 deletion spec/flow_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe "Flow" do
ch.flow(false)
msgs.pop.ack
q.publish "msg"
sleep 0.05 # wait little so a new message could be delivered
sleep 50.milliseconds # wait little so a new message could be delivered
msgs.size.should eq 0
ch.flow(true)
wait_for { msgs.size == 1 }
Expand Down
34 changes: 17 additions & 17 deletions spec/policies_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ describe LavinMQ::VHost do
PoliciesSpec.with_vhost do |vhost|
vhost.queues["test1"] = LavinMQ::Queue.new(vhost, "test")
vhost.add_policy("test", "^.*$", "all", definitions, -10_i8)
sleep 0.01
sleep 10.milliseconds
vhost.queues["test1"].policy.try(&.name).should eq "test"
vhost.delete_policy("test")
sleep 0.01
sleep 10.milliseconds
vhost.queues["test1"].policy.should be_nil
end
end
Expand Down Expand Up @@ -59,7 +59,7 @@ describe LavinMQ::VHost do
defs = {"max-length" => JSON::Any.new(1_i64)} of String => JSON::Any
vhost.queues["test"] = LavinMQ::Queue.new(vhost, "test")
vhost.add_policy("ml", "^.*$", "queues", defs, 11_i8)
sleep 0.01
sleep 10.milliseconds
vhost.queues["test"].policy.not_nil!.name.should eq "ml"
end
end
Expand All @@ -70,7 +70,7 @@ describe LavinMQ::VHost do
vhost.queues["test2"] = LavinMQ::Queue.new(vhost, "test")
vhost.add_policy("ml2", "^.*$", "queues", defs, 1_i8)
vhost.add_policy("ml1", "^.*$", "queues", defs, 0_i8)
sleep 0.01
sleep 10.milliseconds
vhost.queues["test2"].policy.not_nil!.name.should eq "ml2"
end
end
Expand Down Expand Up @@ -102,7 +102,7 @@ describe LavinMQ::VHost do
end
ch.queue_declare("policy-ttl", passive: true)[:message_count].should eq 10
s.vhosts["/"].add_policy("ttl", "^.*$", "all", defs, 12_i8)
sleep 0.01
sleep 10.milliseconds
ch.queue_declare("policy-ttl", passive: true)[:message_count].should eq 0
s.vhosts["/"].delete_policy("ttl")
end
Expand All @@ -116,7 +116,7 @@ describe LavinMQ::VHost do
q = ch.queue("qttl")
q.publish_confirm ""
s.vhosts["/"].add_policy("qttl", "^.*$", "all", defs, 12_i8)
sleep 0.01
sleep 10.milliseconds
expect_raises(AMQP::Client::Channel::ClosedException) do
ch.queue_declare("qttl", passive: true)
end
Expand All @@ -131,9 +131,9 @@ describe LavinMQ::VHost do
ch.queue("qttl")
queue = s.vhosts["/"].queues["qttl"]
first = queue.last_get_time
sleep 0.1
sleep 0.1.seconds
s.vhosts["/"].add_policy("qttl", "^.*$", "all", defs, 12_i8)
sleep 0.1
sleep 0.1.seconds
last = queue.last_get_time
last.should be > first
end
Expand All @@ -149,9 +149,9 @@ describe LavinMQ::VHost do
q.publish_confirm "short2"
q.publish_confirm "long"
ch.queue_declare("max-length-bytes", passive: true)[:message_count].should eq 3
sleep 0.02
sleep 0.02.seconds
s.vhosts["/"].add_policy("max-length-bytes", "^.*$", "all", defs, 12_i8)
sleep 0.01
sleep 10.milliseconds
ch.queue_declare("max-length-bytes", passive: true)[:message_count].should eq 2
q.get(no_ack: true).try(&.body_io.to_s).should eq("short2")
q.get(no_ack: true).try(&.body_io.to_s).should eq("long")
Expand All @@ -166,7 +166,7 @@ describe LavinMQ::VHost do
with_channel(s) do |ch|
q = ch.queue("max-length-bytes", exclusive: true)
s.vhosts["/"].add_policy("max-length-bytes", "^.*$", "all", defs, 12_i8)
sleep 0.01
sleep 10.milliseconds
q.publish_confirm "short1"
q.publish_confirm "short2"
q.publish_confirm "long"
Expand All @@ -185,7 +185,7 @@ describe LavinMQ::VHost do
with_channel(s) do |ch|
q = ch.queue("max-length-bytes", exclusive: true)
s.vhosts["/"].add_policy("max-length-bytes", "^.*$", "all", defs, 12_i8)
sleep 0.01
sleep 10.milliseconds
q.publish_confirm "short1"
q.publish_confirm "short2"
q.publish_confirm "long"
Expand Down Expand Up @@ -256,7 +256,7 @@ describe LavinMQ::VHost do
"delayed-message"}
vhost.queues["test"] = LavinMQ::Queue.new(vhost, "test")
vhost.add_policy("test", "^.*$", "all", definitions, -10_i8)
sleep 0.01
sleep 10.milliseconds
vhost.queues["test"].details_tuple[:effective_policy_definition].as(Hash(String, JSON::Any)).each_key do |k|
supported_policies.includes?(k).should be_true
end
Expand All @@ -272,11 +272,11 @@ describe LavinMQ::VHost do
vhost.exchanges["x-with-ae"] = LavinMQ::DirectExchange.new(vhost, "x-with-ae",
arguments: AMQ::Protocol::Table.new({"x-alternate-exchange": "ae2"}))
vhost.add_policy("test", ".*", "all", definitions, 100_i8)
sleep 0.01
sleep 10.milliseconds
vhost.exchanges["no-ae"].@alternate_exchange.should eq "dead-letters"
vhost.exchanges["x-with-ae"].@alternate_exchange.should eq "ae2"
vhost.delete_policy("test")
sleep 0.01
sleep 10.milliseconds
vhost.exchanges["no-ae"].@alternate_exchange.should be_nil
vhost.exchanges["x-with-ae"].@alternate_exchange.should eq "ae2"
end
Expand All @@ -287,11 +287,11 @@ describe LavinMQ::VHost do
vhost.queues["test1"] = LavinMQ::Queue.new(vhost, "test1", arguments: LavinMQ::AMQP::Table.new({"x-max-length" => 1_i64}))
vhost.queues["test2"] = LavinMQ::Queue.new(vhost, "test2", arguments: LavinMQ::AMQP::Table.new({"x-max-length" => 11_i64}))
vhost.add_policy("test", ".*", "all", definitions, 100_i8)
sleep 0.01
sleep 10.milliseconds
vhost.queues["test1"].@max_length.should eq 1
vhost.queues["test2"].@max_length.should eq 10
vhost.delete_policy("test")
sleep 0.01
sleep 10.milliseconds
vhost.queues["test1"].@max_length.should eq 1
vhost.queues["test2"].@max_length.should eq 11
end
Expand Down
6 changes: 3 additions & 3 deletions spec/queue_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ describe LavinMQ::Queue do
sq = s.vhosts["/"].queues[q.name]
sq.unacked_count.should eq 1
msg.not_nil!.ack
sleep 0.01
sleep 10.milliseconds
sq.unacked_count.should eq 0
end
end
Expand All @@ -296,7 +296,7 @@ describe LavinMQ::Queue do
sq = s.vhosts["/"].queues[q.name]
sq.unacked_count.should eq 1
msg.ack
sleep 0.01
sleep 10.milliseconds
sq.unacked_count.should eq 0
end
end
Expand Down Expand Up @@ -342,7 +342,7 @@ describe LavinMQ::Queue do
sub = q.subscribe(no_ack: true) { |_| }
Dir.exists?(data_dir).should be_true
q.unsubscribe(sub)
sleep 0.1
sleep 0.1.seconds
Dir.exists?(data_dir).should be_false
end
end
Expand Down
Loading
Loading