Skip to content

Commit

Permalink
Relax async timing assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
rmosolgo committed Feb 6, 2025
1 parent 6b2b1fd commit a8d51db
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
6 changes: 3 additions & 3 deletions spec/graphql/dataloader/async_dataloader_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -170,17 +170,17 @@ def self.included(child_class)

assert_equal 0.2, v2
assert_equal 0.3, v3
assert_in_delta 0.0, started_at_2 - ended_at_2, 0.05, "Already-loaded values returned instantly"
assert_in_delta 0.0, started_at_2 - ended_at_2, 0.06, "Already-loaded values returned instantly"

assert_in_delta 0.3, ended_at - started_at, 0.05, "IO ran in parallel"
assert_in_delta 0.3, ended_at - started_at, 0.06, "IO ran in parallel"
end

it "works with GraphQL" do
started_at = Time.now
res = @schema.execute("{ s1: sleep(duration: 0.1) s2: sleep(duration: 0.2) s3: sleep(duration: 0.3) }")
ended_at = Time.now
assert_equal({"s1"=>0.1, "s2"=>0.2, "s3"=>0.3}, res["data"])
assert_in_delta 0.3, ended_at - started_at, 0.05, "IO ran in parallel"
assert_in_delta 0.3, ended_at - started_at, 0.06, "IO ran in parallel"
end

it "runs fields by depth" do
Expand Down
10 changes: 5 additions & 5 deletions spec/graphql/dataloader/nonblocking_dataloader_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def self.included(child_class)
ended_at = Time.now

assert_equal({ a: 1, b: 2, c: 3 }, results, "All the jobs ran")
assert_in_delta 0.3, ended_at - started_at, 0.05, "IO ran in parallel"
assert_in_delta 0.3, ended_at - started_at, 0.06, "IO ran in parallel"
end

it "works with sources" do
Expand All @@ -136,9 +136,9 @@ def self.included(child_class)

assert_equal 0.3, v2
assert_equal 0.3, v3
assert_in_delta 0.0, started_at_2 - ended_at_2, 0.05, "Already-loaded values returned instantly"
assert_in_delta 0.0, started_at_2 - ended_at_2, 0.06, "Already-loaded values returned instantly"

assert_in_delta 0.3, ended_at - started_at, 0.05, "IO ran in parallel"
assert_in_delta 0.3, ended_at - started_at, 0.06, "IO ran in parallel"
end

it "works with GraphQL" do
Expand All @@ -148,7 +148,7 @@ def self.included(child_class)
}
ended_at = Time.now
assert_equal({"s1"=>0.1, "s2"=>0.2, "s3"=>0.3}, res["data"])
assert_in_delta 0.3, ended_at - started_at, 0.05, "IO ran in parallel"
assert_in_delta 0.3, ended_at - started_at, 0.06, "IO ran in parallel"
end

it "nested fields don't wait for slower higher-level fields" do
Expand Down Expand Up @@ -183,7 +183,7 @@ def self.included(child_class)
"s3" => { "duration" => 0.3 }
}
assert_equal expected_data, res["data"]
assert_in_delta 0.3, ended_at - started_at, 0.05, "Fields ran without any waiting"
assert_in_delta 0.3, ended_at - started_at, 0.06, "Fields ran without any waiting"
end

it "runs dataloaders in parallel across branches" do
Expand Down
12 changes: 6 additions & 6 deletions spec/integration/rails/graphql/dataloader_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def things(first:)
result = RailsPromiseSchema.execute(query_str)
t2 = Time.now
assert_equal({ "s1" => 0.1, "s2" => 0.2, "s3" => 0.3}, result["data"])
assert_in_delta 0.3, t2 - t1, 0.05, "Sleeps were in parallel"
assert_in_delta 0.3, t2 - t1, 0.06, "Sleeps were in parallel"
end
end

Expand All @@ -103,15 +103,15 @@ def things(first:)
t2 = Time.now

load_async_1, load_async_2, load_async_3, load_1, load_2, load_3 = RailsPromiseSchema::LoadAsyncSource::LOG
assert_in_delta load_async_1, load_async_2, 0.05, "load_async happened first"
assert_in_delta load_async_1, load_async_3, 0.05, "the third load_async happened right after"
assert_in_delta load_async_1, load_async_2, 0.06, "load_async happened first"
assert_in_delta load_async_1, load_async_3, 0.06, "the third load_async happened right after"

assert_in_delta load_async_1, load_1, 0.35, "load came 0.3s after"
assert_in_delta load_1, load_2, 0.05, "the second load didn't have to wait because it was already done"
assert_in_delta load_1, load_3, 0.05, "the third load didn't have to wait because it was already done"
assert_in_delta load_1, load_2, 0.06, "the second load didn't have to wait because it was already done"
assert_in_delta load_1, load_3, 0.06, "the third load didn't have to wait because it was already done"

assert_equal({ "t1" => 1, "t2" => 1, "t3" => 1}, result["data"])
assert_in_delta 0.3, t2 - t1, 0.05, "Sleeps were in parallel"
assert_in_delta 0.3, t2 - t1, 0.06, "Sleeps were in parallel"
end
end
end
Expand Down

0 comments on commit a8d51db

Please sign in to comment.