pgtk 0.17.0 → 0.17.1
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/.github/workflows/copyrights.yml +1 -1
- data/.github/workflows/markdown-lint.yml +1 -1
- data/Gemfile.lock +4 -4
- data/README.md +20 -10
- data/lib/pgtk/impatient.rb +7 -4
- data/lib/pgtk/version.rb +1 -1
- data/resources/pom.xml +1 -1
- data/test/test_impatient.rb +12 -0
- data/test/test_pool.rb +29 -0
- 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: 72b30fd73fd65ec23cd7853399d575b696aef7db096b76e53d3448b881cbcf6c
|
4
|
+
data.tar.gz: 02f7a7c50eea3ce4b20862b6fcbb762e89de2259722dc034dd10c3a712345386
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 30707ad9cf31b00a9fca53e8c83e1197d2e6f7c3bce07856fc0f93efa5240091f31e82f99cf91940c3466e499e4cf10f46b3bf16a4476a48256ab7b120fb3f84
|
7
|
+
data.tar.gz: 0adf7b70d2921a681af1f65cd6fbc77025a96a53d678ca25f50d1c7a6c7d6173240fcd8f4475eb16383dc4d5d92868420035d64744b5660a230cca57f304b54b
|
data/Gemfile.lock
CHANGED
@@ -25,8 +25,8 @@ GEM
|
|
25
25
|
elapsed (0.0.1)
|
26
26
|
loog (> 0)
|
27
27
|
tago (> 0)
|
28
|
-
joined (0.
|
29
|
-
json (2.12.
|
28
|
+
joined (0.3.0)
|
29
|
+
json (2.12.2)
|
30
30
|
language_server-protocol (3.17.0.5)
|
31
31
|
lint_roller (1.1.0)
|
32
32
|
logger (1.7.0)
|
@@ -57,14 +57,14 @@ GEM
|
|
57
57
|
loog (> 0)
|
58
58
|
tago (> 0)
|
59
59
|
racc (1.8.1)
|
60
|
-
rack (3.1.
|
60
|
+
rack (3.1.15)
|
61
61
|
rainbow (3.1.1)
|
62
62
|
rake (13.2.1)
|
63
63
|
random-port (0.7.5)
|
64
64
|
tago (> 0)
|
65
65
|
regexp_parser (2.10.0)
|
66
66
|
rexml (3.4.1)
|
67
|
-
rubocop (1.75.
|
67
|
+
rubocop (1.75.7)
|
68
68
|
json (~> 2.3)
|
69
69
|
language_server-protocol (~> 3.17.0.2)
|
70
70
|
lint_roller (~> 1.1.0)
|
data/README.md
CHANGED
@@ -44,14 +44,19 @@ Then, add this to your
|
|
44
44
|
```ruby
|
45
45
|
require 'pgtk/pgsql_task'
|
46
46
|
Pgtk::PgsqlTask.new :pgsql do |t|
|
47
|
-
|
48
|
-
t.
|
47
|
+
# Temp directory with PostgreSQL files:
|
48
|
+
t.dir = 'target/pgsql'
|
49
|
+
# To delete the directory on every start;
|
50
|
+
t.fresh_start = true
|
49
51
|
t.user = 'test'
|
50
52
|
t.password = 'test'
|
51
53
|
t.dbname = 'test'
|
52
|
-
|
53
|
-
t.
|
54
|
-
|
54
|
+
# YAML file to be created with connection details:
|
55
|
+
t.yaml = 'target/pgsql-config.yml'
|
56
|
+
# List of contexts or empty if all:
|
57
|
+
t.contexts = '!test'
|
58
|
+
# List of PostgreSQL configuration options:
|
59
|
+
t.config = {
|
55
60
|
log_min_messages: 'ERROR',
|
56
61
|
log_filename: 'target/pg.log'
|
57
62
|
}
|
@@ -66,11 +71,16 @@ are used inside):
|
|
66
71
|
```ruby
|
67
72
|
require 'pgtk/liquibase_task'
|
68
73
|
Pgtk::LiquibaseTask.new liquibase: :pgsql do |t|
|
69
|
-
|
70
|
-
t.
|
71
|
-
|
72
|
-
t.
|
73
|
-
|
74
|
+
# Master XML file path:
|
75
|
+
t.master = 'liquibase/master.xml'
|
76
|
+
# YAML files connection details:
|
77
|
+
t.yaml = ['target/pgsql-config.yml', 'config.yml']
|
78
|
+
# Reduce the amount of log messages (TRUE by default):
|
79
|
+
t.quiet = false
|
80
|
+
# Overwriting default version of PostgreSQL server:
|
81
|
+
t.postgresql_version = '42.7.0'
|
82
|
+
# Overwriting default version of Liquibase:
|
83
|
+
t.liquibase_version = '3.2.2'
|
74
84
|
end
|
75
85
|
```
|
76
86
|
|
data/lib/pgtk/impatient.rb
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
# SPDX-FileCopyrightText: Copyright (c) 2019-2025 Yegor Bugayenko
|
4
4
|
# SPDX-License-Identifier: MIT
|
5
5
|
|
6
|
+
require 'securerandom'
|
6
7
|
require 'tago'
|
7
8
|
require 'timeout'
|
8
9
|
require_relative '../pgtk'
|
@@ -82,15 +83,17 @@ class Pgtk::Impatient
|
|
82
83
|
def exec(sql, *args)
|
83
84
|
return @pool.exec(sql, *args) if @off.any? { |re| re.match?(sql) }
|
84
85
|
start = Time.now
|
86
|
+
token = SecureRandom.uuid
|
85
87
|
begin
|
86
|
-
Timeout.timeout(@timeout) do
|
88
|
+
Timeout.timeout(@timeout, Timeout::Error, token) do
|
87
89
|
@pool.exec(sql, *args)
|
88
90
|
end
|
89
|
-
rescue Timeout::Error
|
91
|
+
rescue Timeout::Error => e
|
92
|
+
raise e unless e.message == token
|
90
93
|
raise TooSlow, [
|
91
94
|
'SQL query',
|
92
|
-
("with #{args.count}
|
93
|
-
'
|
95
|
+
("with #{args.count} argument#{'s' if args.count > 1}" unless args.empty?),
|
96
|
+
'was terminated after',
|
94
97
|
start.ago,
|
95
98
|
'of waiting'
|
96
99
|
].compact.join(' ')
|
data/lib/pgtk/version.rb
CHANGED
data/resources/pom.xml
CHANGED
data/test/test_impatient.rb
CHANGED
@@ -43,6 +43,18 @@ class TestImpatient < Pgtk::Test
|
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
|
+
def test_doesnt_shadow_larger_timeout
|
47
|
+
fake_pool do |pool|
|
48
|
+
assert_raises(Timeout::Error) do
|
49
|
+
Timeout.timeout(0.1) do
|
50
|
+
Pgtk::Impatient.new(pool, 999).exec(
|
51
|
+
'SELECT COUNT(*) FROM generate_series(1, 100000000) AS a'
|
52
|
+
)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
46
58
|
def test_doesnt_interrupt
|
47
59
|
fake_pool do |pool|
|
48
60
|
id = Pgtk::Impatient.new(pool, 1).exec(
|
data/test/test_pool.rb
CHANGED
@@ -38,6 +38,35 @@ class TestPool < Pgtk::Test
|
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
|
+
def test_logs_pgsql_errors_to_logger
|
42
|
+
buf = Loog::Buffer.new
|
43
|
+
fake_pool(log: buf) do |pool|
|
44
|
+
pool.exec(
|
45
|
+
"
|
46
|
+
CREATE FUNCTION intentional_failure() RETURNS trigger AS
|
47
|
+
'BEGIN
|
48
|
+
IF NEW.title = ''War and War'' THEN
|
49
|
+
RAISE EXCEPTION ''The title of the book is bad'';
|
50
|
+
END IF;
|
51
|
+
RETURN NEW;
|
52
|
+
END' LANGUAGE PLPGSQL
|
53
|
+
"
|
54
|
+
)
|
55
|
+
pool.exec(
|
56
|
+
"
|
57
|
+
CREATE TRIGGER check_book_title
|
58
|
+
BEFORE INSERT ON book
|
59
|
+
FOR EACH ROW EXECUTE PROCEDURE intentional_failure();
|
60
|
+
"
|
61
|
+
)
|
62
|
+
assert_raises(PG::RaiseException) do
|
63
|
+
pool.exec('INSERT INTO book (title) VALUES ($1)', ['War and War'])
|
64
|
+
end
|
65
|
+
assert_includes(buf.to_s, 'The title of the book is bad')
|
66
|
+
assert_includes(buf.to_s, 'function intentional_failure() line 3')
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
41
70
|
def test_queries_with_block
|
42
71
|
fake_pool do |pool|
|
43
72
|
pool.exec('INSERT INTO book (title) VALUES ($1)', ['1984'])
|