From 3a973559a8e001647d8d5eb859bc5f065947a055 Mon Sep 17 00:00:00 2001 From: Samuel Williams Date: Wed, 6 Nov 2024 19:56:36 +1300 Subject: [PATCH] Dealing with test race conditions while traces are emitted. --- test/async/reactor.rb | 7 ++++--- test/async/task.rb | 6 +++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/test/async/reactor.rb b/test/async/reactor.rb index 70516f8..abac8f5 100644 --- a/test/async/reactor.rb +++ b/test/async/reactor.rb @@ -5,6 +5,7 @@ # Copyright, 2017, by Devin Christensen. require "async" +require "async/variable" require "sus/fixtures/async" require "benchmark/ips" @@ -229,14 +230,14 @@ start_time = Time.now subject.run do |task| - condition = Async::Condition.new + variable = Async::Variable.new task.with_timeout(duration) do task.async do - condition.wait + variable.wait end - condition.signal + variable.resolve task.yield diff --git a/test/async/task.rb b/test/async/task.rb index 4e2e32f..3a3ebe9 100644 --- a/test/async/task.rb +++ b/test/async/task.rb @@ -50,18 +50,18 @@ it "can yield back to scheduler" do state = nil - reactor.async do |task| + reactor.run do |task| child = task.async do state = :yielding Async::Task.yield state = :yielded end + # Async::Task. + Fiber.scheduler.resume(child.fiber) end - reactor.run - expect(state).to be == :yielded end end