Skip to content

Commit ddb551b

Browse files
yahondaclaude
andcommitted
Speed up threaded-cursor spec by ~1.8s
The "should safely close cursors in threaded environment" example in spec/plsql/schema_spec.rb spawns two threads that call DBMS_SESSION.sleep (or DBMS_LOCK.sleep on pre-18c) and joins them. The point of the test is that two concurrent calls on the same connection don't trip the cursor pool — the sleep durations are only there to keep both calls in flight at once. The original 1- and 2-second sleeps dominated the suite at ~2.05s out of ~10s total (~21%, the slowest example by a wide margin). Drop them to 0.1s and 0.2s, which still gives 100ms of guaranteed-overlap and a 100ms ordering gap between the two threads — far more than OS scheduling needs to keep both in flight. Verified stable across three back-to-back runs at ~0.29s each. Net effect: full suite drops from ~9.93s to ~8.08s (~19% faster); this example moves from #1 to rsim#4 in the slowest-examples profile. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 416e451 commit ddb551b

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

spec/plsql/schema_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -255,14 +255,14 @@ class TestModel < TestBaseModel
255255
it "should safely close cursors in threaded environment" do
256256
if (plsql.connection.database_version <=> [18, 0, 0, 0]) >= 0
257257
expect {
258-
t1 = Thread.new { plsql.dbms_session.sleep(1) }.tap { |t| t.abort_on_exception = true }
259-
t2 = Thread.new { plsql.dbms_session.sleep(2) }.tap { |t| t.abort_on_exception = true }
258+
t1 = Thread.new { plsql.dbms_session.sleep(0.1) }.tap { |t| t.abort_on_exception = true }
259+
t2 = Thread.new { plsql.dbms_session.sleep(0.2) }.tap { |t| t.abort_on_exception = true }
260260
[t2, t1].each { |t| t.join }
261261
}.not_to raise_error
262262
else
263263
expect {
264-
t1 = Thread.new { plsql.dbms_lock.sleep(1) }.tap { |t| t.abort_on_exception = true }
265-
t2 = Thread.new { plsql.dbms_lock.sleep(2) }.tap { |t| t.abort_on_exception = true }
264+
t1 = Thread.new { plsql.dbms_lock.sleep(0.1) }.tap { |t| t.abort_on_exception = true }
265+
t2 = Thread.new { plsql.dbms_lock.sleep(0.2) }.tap { |t| t.abort_on_exception = true }
266266
[t2, t1].each { |t| t.join }
267267
}.not_to raise_error
268268
end

0 commit comments

Comments
 (0)