pgtk 0.16.3 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/pgtk/impatient.rb +4 -1
- data/lib/pgtk/version.rb +1 -1
- data/test/test_impatient.rb +13 -5
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8a1ac7d09cdc700a6fa51f239d1f14564f14f9cee56773a933e7e7d310291b1a
|
4
|
+
data.tar.gz: 8bcce91182b85e2a592cd3031048b9687b56c7be0587eda199b1c97df944f630
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '018f2c1cc65ca5b64f27609e4934f47163dcd8c4e582508e995dd332992b18f652de8fef63a9f5d86af969ce306796d2e2db0f490072933ab7a38cd91d02cfa0'
|
7
|
+
data.tar.gz: 16c2631220d3cdad2aef2132213a79c922aae79edad0d34b9b7003bd5eec62977cbf9f3febb20a99b17612e77c074e64b7305078903b76e156e27bb90bfbb69c
|
data/lib/pgtk/impatient.rb
CHANGED
@@ -59,9 +59,11 @@ class Pgtk::Impatient
|
|
59
59
|
#
|
60
60
|
# @param [Pgtk::Pool] pool The pool to decorate
|
61
61
|
# @param [Integer] timeout Timeout in seconds for each SQL query
|
62
|
-
|
62
|
+
# @param [Array<Regex>] off List of regex to exclude queries from checking
|
63
|
+
def initialize(pool, timeout, *off)
|
63
64
|
@pool = pool
|
64
65
|
@timeout = timeout
|
66
|
+
@off = off
|
65
67
|
end
|
66
68
|
|
67
69
|
# Get the version of PostgreSQL server.
|
@@ -78,6 +80,7 @@ class Pgtk::Impatient
|
|
78
80
|
# @return [Array] Result rows
|
79
81
|
# @raise [Timeout::Error] If the query takes too long
|
80
82
|
def exec(sql, *args)
|
83
|
+
return @pool.exec(sql, *args) if @off.any? { |re| re.match?(sql) }
|
81
84
|
start = Time.now
|
82
85
|
begin
|
83
86
|
Timeout.timeout(@timeout) do
|
data/lib/pgtk/version.rb
CHANGED
data/test/test_impatient.rb
CHANGED
@@ -20,7 +20,7 @@ require_relative '../lib/pgtk/impatient'
|
|
20
20
|
class TestImpatient < Pgtk::Test
|
21
21
|
def test_takes_version
|
22
22
|
fake_pool do |pool|
|
23
|
-
v = Pgtk::Impatient.new(pool).version
|
23
|
+
v = Pgtk::Impatient.new(pool, 1).version
|
24
24
|
refute_nil(v)
|
25
25
|
end
|
26
26
|
end
|
@@ -28,16 +28,24 @@ class TestImpatient < Pgtk::Test
|
|
28
28
|
def test_interrupts
|
29
29
|
fake_pool do |pool|
|
30
30
|
assert_raises(Pgtk::Impatient::TooSlow) do
|
31
|
-
Pgtk::Impatient.new(pool, 0.
|
32
|
-
'SELECT COUNT(*) FROM generate_series(1,
|
31
|
+
Pgtk::Impatient.new(pool, 0.01).exec(
|
32
|
+
'SELECT COUNT(*) FROM generate_series(1, 1000000) AS a'
|
33
33
|
)
|
34
34
|
end
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
+
def test_skips_by_regex
|
39
|
+
fake_pool do |pool|
|
40
|
+
Pgtk::Impatient.new(pool, 0.01, /^SELECT.*$/).exec(
|
41
|
+
'SELECT COUNT(*) FROM generate_series(1, 1000000) AS a'
|
42
|
+
)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
38
46
|
def test_doesnt_interrupt
|
39
47
|
fake_pool do |pool|
|
40
|
-
id = Pgtk::Impatient.new(pool).exec(
|
48
|
+
id = Pgtk::Impatient.new(pool, 1).exec(
|
41
49
|
'INSERT INTO book (title) VALUES ($1) RETURNING id',
|
42
50
|
['1984']
|
43
51
|
).first['id'].to_i
|
@@ -47,7 +55,7 @@ class TestImpatient < Pgtk::Test
|
|
47
55
|
|
48
56
|
def test_doesnt_interrupt_in_transaction
|
49
57
|
fake_pool do |pool|
|
50
|
-
Pgtk::Impatient.new(pool).transaction do |t|
|
58
|
+
Pgtk::Impatient.new(pool, 1).transaction do |t|
|
51
59
|
id = t.exec(
|
52
60
|
'INSERT INTO book (title) VALUES ($1) RETURNING id',
|
53
61
|
['1984']
|