From 0d97ccd6bbb0d08553911a32aad57164ceedf0f8 Mon Sep 17 00:00:00 2001 From: Martyn Loughran Date: Thu, 2 Jan 2025 13:02:19 +0000 Subject: [PATCH 1/2] Fix deprecated usage of sleep in specs and docs Fixes deprecation warnings of the form: ``` In spec/sql/select/lock_spec.cr:22:7 22 | sleep(0.05) # Give hand to the other fiber. Now it should be not locked anymore? ^---- Warning: Deprecated ::sleep. Use `::sleep(Time::Span)` instead ``` --- .../model/transactions-and-save-points/connection-pool.md | 6 +++--- spec/sql/connection_pool_spec.cr | 6 +++--- spec/sql/select/lock_spec.cr | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/manual/model/transactions-and-save-points/connection-pool.md b/manual/model/transactions-and-save-points/connection-pool.md index 1b1e32045..af7093336 100644 --- a/manual/model/transactions-and-save-points/connection-pool.md +++ b/manual/model/transactions-and-save-points/connection-pool.md @@ -12,7 +12,7 @@ begin # Clear automatically create a connection nº1 Clear::SQL.transaction do Clear::SQL.insert("tests", {id: 1}).execute - sleep 0.2 #< Wait and do not commit the transaction for now + sleep 0.2.seconds # Wait and do not commit the transaction for now end end @@ -20,12 +20,12 @@ begin # Spawn a new fiber spawn do - sleep 0.1 #Wait a bit, to ensure than the first connection is inside a transaction + sleep 0.1.seconds # Wait a bit, to ensure than the first connection is inside a transaction # execute in connection nº2 @@count = Clear::SQL.select.from("tests").count end - sleep 0.3 # Let the 2 fiber time to finish... + sleep 0.3.seconds # Let the 2 fiber time to finish... # The count is zero, because: it has been setup by the second fiber, which # called AFTER the insert but BEFORE the commit on the connection nº1 diff --git a/spec/sql/connection_pool_spec.cr b/spec/sql/connection_pool_spec.cr index 0d501944f..9af1b5ce6 100644 --- a/spec/sql/connection_pool_spec.cr +++ b/spec/sql/connection_pool_spec.cr @@ -19,7 +19,7 @@ module ConnectionPoolSpec spawn do Clear::SQL.transaction do Clear::SQL.insert("tests", {id: 1}).execute - sleep 0.2 # < The transaction is not yet commited + sleep 0.2.seconds # < The transaction is not yet commited end end @@ -27,11 +27,11 @@ module ConnectionPoolSpec spawn do # Not inside the transaction so count must be zero since the transaction is not finished: - sleep 0.1 + sleep 0.1.seconds @@count = Clear::SQL.select.from("tests").count end - sleep 0.3 # Let the 2 spawn finish... + sleep 0.3.seconds # Let the 2 spawn finish... @@count.should eq 0 # < If one, the connection pool got wrong with the fiber. diff --git a/spec/sql/select/lock_spec.cr b/spec/sql/select/lock_spec.cr index 370f8bca6..c47427bca 100644 --- a/spec/sql/select/lock_spec.cr +++ b/spec/sql/select/lock_spec.cr @@ -19,7 +19,7 @@ module LockSpec Clear::SQL.select.from(:to_lock).pluck_col(:id).should eq [1] end - sleep(0.05) # Give hand to the other fiber. Now it should be not locked anymore? + sleep 0.05.seconds # Give hand to the other fiber. Now it should be not locked anymore? Clear::SQL.select.from(:to_lock).order_by("id", :asc).pluck_col(:id).should eq [1, 2] ensure Clear::SQL.execute("DROP TABLE to_lock") From da7ea142813ed7360b3163ce9fbc87d54d74022a Mon Sep 17 00:00:00 2001 From: Martyn Loughran Date: Thu, 2 Jan 2025 13:03:23 +0000 Subject: [PATCH 2/2] Fix parameter name warning Fixes: ``` In src/clear/expression/expression.cr:86:17 86 | def to_json(b = nil) ^ Warning: positional parameter 'b' corresponds to parameter 'x' of the overridden method Clear::Expression::Literal#to_json(x : JSON::Builder), which has a different name and may affect named argument passing ``` --- src/clear/expression/expression.cr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/clear/expression/expression.cr b/src/clear/expression/expression.cr index c9779335c..d63aca04a 100644 --- a/src/clear/expression/expression.cr +++ b/src/clear/expression/expression.cr @@ -83,7 +83,7 @@ class Clear::Expression @value end - def to_json(b = nil) + def to_json(x = nil) @value end end