Skip to content

Commit

Permalink
Reduce sleep overhead in tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Jan 10, 2025
1 parent 83c00a8 commit d1c61e1
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion test/async/container/.dots.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def setup(container)
instance.ready!

# This is to avoid race conditions in the controller in test conditions.
sleep 0.1
sleep 0.001

$stdout.write "."

Expand Down
4 changes: 2 additions & 2 deletions test/async/container/.graceful.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def setup(container)
instance.ready!

# This is to avoid race conditions in the controller in test conditions.
sleep 0.1
sleep 0.001

clock = Async::Clock.start

Expand All @@ -34,7 +34,7 @@ def setup(container)
end
end

controller = Graceful.new(graceful_stop: 1)
controller = Graceful.new(graceful_stop: 0.01)

begin
controller.run
Expand Down
10 changes: 5 additions & 5 deletions test/async/container/controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@ def controller.setup(container)
container.spawn(key: "test") do |instance|
instance.ready!

sleep(0.2)
sleep(0.02)

@output.write(".")
@output.flush

sleep(0.4)
sleep(0.04)
end

container.spawn do |instance|
instance.ready!

sleep(0.3)
sleep(0.03)

@output.write(",")
@output.flush
Expand Down Expand Up @@ -64,7 +64,7 @@ def controller.setup(container)
it "can spawn a reactor" do
def controller.setup(container)
container.async do |task|
task.sleep 1
task.sleep 0.001
end
end

Expand Down Expand Up @@ -123,7 +123,7 @@ def after(error = nil)
expect(input.gets).to be == "Exiting...\n"
exit_time = input.gets.to_f

expect(exit_time - graceful_shutdown_time).to be >= 1.0
expect(exit_time - graceful_shutdown_time).to be >= 0.01
end
end

Expand Down
4 changes: 2 additions & 2 deletions test/async/container/notify/.notify.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
class MyController < Async::Container::Controller
def setup(container)
container.run(restart: false) do |instance|
sleep(rand)
sleep(0.001)

instance.ready!

sleep(rand)
sleep(0.001)
end
end
end
Expand Down

0 comments on commit d1c61e1

Please sign in to comment.