File: async_spec_helper.rb

package info (click to toggle)
ruby-sequel 5.63.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 10,408 kB
  • sloc: ruby: 113,747; makefile: 3
file content (32 lines) | stat: -rw-r--r-- 721 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
class Minitest::Spec
  if ENV['SEQUEL_ASYNC_THREAD_POOL'] || ENV['SEQUEL_ASYNC_THREAD_POOL_PREEMPT'] || ENV['SEQUEL_EAGER_ASYNC']
    use_async = true
    if ENV['SEQUEL_ASYNC_THREAD_POOL_PREEMPT']
      ::DB.opts[:preempt_async_thread] = true
    end
    ::DB.opts[:num_async_threads] = 12
    ::DB.extension :async_thread_pool

    if ENV['SEQUEL_EAGER_ASYNC']
      Sequel::Model.plugin :concurrent_eager_loading, :always=>true
    end
  end

  if use_async && DB.pool.pool_type == :threaded && (!DB.opts[:max_connections] || DB.opts[:max_connections] >= 4)
    def async?
      true
    end

    def wait
      yield.tap{}
    end
  else
    def async?
      false
    end

    def wait
      yield
    end
  end
end