File: prepared_statement_status_test.rb

package info (click to toggle)
rails 2%3A6.1.7.10%2Bdfsg-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 39,756 kB
  • sloc: ruby: 290,662; javascript: 19,241; yacc: 46; sql: 43; makefile: 32; sh: 18
file content (48 lines) | stat: -rw-r--r-- 1,303 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# frozen_string_literal: true

require "cases/helper"
require "models/course"
require "models/entrant"

module ActiveRecord
  class PreparedStatementStatusTest < ActiveRecord::TestCase
    def test_prepared_statement_status_is_thread_and_instance_specific
      course_conn = Course.connection
      entrant_conn = Entrant.connection

      inside = Concurrent::Event.new
      preventing = Concurrent::Event.new
      finished = Concurrent::Event.new

      assert_not_same course_conn, entrant_conn

      if ActiveRecord::Base.connection.prepared_statements
        t1 = Thread.new do
          course_conn.unprepared_statement do
            inside.set
            preventing.wait
            assert_not course_conn.prepared_statements
            assert entrant_conn.prepared_statements
            finished.set
          end
        end

        t2 = Thread.new do
          entrant_conn.unprepared_statement do
            inside.wait
            assert course_conn.prepared_statements
            assert_not entrant_conn.prepared_statements
            preventing.set
            finished.wait
          end
        end

        t1.join
        t2.join
      else
        assert_not course_conn.prepared_statements
        assert_not entrant_conn.prepared_statements
      end
    end
  end
end