factbase 0.14.2 → 0.14.3
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/factbase/impatient.rb +22 -16
- data/lib/factbase/version.rb +1 -1
- data/test/factbase/test_impatient.rb +0 -28
- 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: 9bbcc978a4adafeac2404f3ac22be354029d5c7a1f14152d75d1db61aeaaecbe
|
4
|
+
data.tar.gz: 8f19d5e20248f1ab7f6202bb43172e0b1916d430df8d136c9d78ae5cec8f12df
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9efd7278de80bcf3599ca631cdb7dfa174bcf8ac3fa258313b01f2ba4e097d09f3eaa6f8362331e94d337696dce8643ce3fe14c88fbf0a31db5e12756c81eb63
|
7
|
+
data.tar.gz: 793f55f9df33b7489478d4029ec75e2ea831802893d88e71ea13ffe31e689ef0232a94fad5795ac1e0459ac1da585cc07e0341da04612a3d97f93b7c2832f044
|
data/lib/factbase/impatient.rb
CHANGED
@@ -20,7 +20,7 @@ class Factbase::Impatient
|
|
20
20
|
def initialize(fb, timeout: 15)
|
21
21
|
raise 'The "fb" is nil' if fb.nil?
|
22
22
|
@origin = fb
|
23
|
-
@timeout = timeout
|
23
|
+
@timeout = timeout.to_f
|
24
24
|
end
|
25
25
|
|
26
26
|
decoor(:origin)
|
@@ -56,31 +56,37 @@ class Factbase::Impatient
|
|
56
56
|
end
|
57
57
|
|
58
58
|
def each(fb = @fb, params = {}, &)
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
59
|
+
a =
|
60
|
+
impatient('each') do
|
61
|
+
@fb.query(@term, @maps).each(fb, params).to_a
|
62
|
+
end
|
63
|
+
return a unless block_given?
|
64
|
+
yielded = 0
|
65
|
+
a.each do |f|
|
66
|
+
yield f
|
67
|
+
yielded += 1
|
63
68
|
end
|
64
|
-
|
65
|
-
raise "each() timed out after #{@timeout.seconds} (#{e.message}): #{@term}"
|
69
|
+
yielded
|
66
70
|
end
|
67
71
|
|
68
72
|
def one(fb = @fb, params = {})
|
69
|
-
|
70
|
-
|
71
|
-
qry.one(fb, params)
|
73
|
+
impatient('one') do
|
74
|
+
@fb.query(@term, @maps).one(fb, params)
|
72
75
|
end
|
73
|
-
rescue Timeout::Error => e
|
74
|
-
raise "one() timed out after #{@timeout.seconds} (#{e.message}): #{@term}"
|
75
76
|
end
|
76
77
|
|
77
78
|
def delete!(fb = @fb)
|
78
|
-
|
79
|
-
|
80
|
-
qry.delete!(fb)
|
79
|
+
impatient('delete!') do
|
80
|
+
@fb.query(@term, @maps).delete!(fb)
|
81
81
|
end
|
82
|
+
end
|
83
|
+
|
84
|
+
private
|
85
|
+
|
86
|
+
def impatient(name, &)
|
87
|
+
Timeout.timeout(@timeout, &)
|
82
88
|
rescue Timeout::Error => e
|
83
|
-
raise "
|
89
|
+
raise "#{name}() timed out after #{@timeout.seconds} (#{e.message}), fb size is #{@fb.size}: #{@term}"
|
84
90
|
end
|
85
91
|
end
|
86
92
|
end
|
data/lib/factbase/version.rb
CHANGED
@@ -81,20 +81,6 @@ class TestImpatient < Factbase::Test
|
|
81
81
|
assert_equal([42], fb.query('(agg (exists bar) (first bar))').one)
|
82
82
|
end
|
83
83
|
|
84
|
-
def test_query_timeout
|
85
|
-
fb = Factbase::Impatient.new(Factbase.new, timeout: 0.1)
|
86
|
-
1000.times do
|
87
|
-
fb.insert.value = rand(1000)
|
88
|
-
end
|
89
|
-
ex =
|
90
|
-
assert_raises(StandardError) do
|
91
|
-
fb.query('(always)').each do
|
92
|
-
sleep 0.2
|
93
|
-
end
|
94
|
-
end
|
95
|
-
assert_includes(ex.message, 'timed out after')
|
96
|
-
end
|
97
|
-
|
98
84
|
def test_query_one_timeout
|
99
85
|
slow = SlowFactbase.new
|
100
86
|
10_000.times do
|
@@ -131,20 +117,6 @@ class TestImpatient < Factbase::Test
|
|
131
117
|
assert_equal(1, fb.size)
|
132
118
|
end
|
133
119
|
|
134
|
-
def test_with_txn_timeout
|
135
|
-
fb = Factbase::Impatient.new(Factbase.new, timeout: 0.1)
|
136
|
-
fb.txn do |fbt|
|
137
|
-
fbt.insert.slow = 42
|
138
|
-
ex =
|
139
|
-
assert_raises(StandardError) do
|
140
|
-
fbt.query('(always)').each do
|
141
|
-
sleep 0.2
|
142
|
-
end
|
143
|
-
end
|
144
|
-
assert_includes(ex.message, 'timed out after')
|
145
|
-
end
|
146
|
-
end
|
147
|
-
|
148
120
|
def test_returns_int
|
149
121
|
fb = Factbase.new
|
150
122
|
fb.insert
|