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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1a637de7c717d650eb0c6721794afd2c4a3bbb31a3eda1b1150f8a2f3e1c5322
4
- data.tar.gz: a0a7698bba101d67c20fd390f1e745679110687643ec6849c445898b26a0d04e
3
+ metadata.gz: 9bbcc978a4adafeac2404f3ac22be354029d5c7a1f14152d75d1db61aeaaecbe
4
+ data.tar.gz: 8f19d5e20248f1ab7f6202bb43172e0b1916d430df8d136c9d78ae5cec8f12df
5
5
  SHA512:
6
- metadata.gz: 99cbde1626587ef0d3552258089dcf9a25f956ee83766f4273d8928faa769995e7150925d0ae2d9506366eed80a4347d3302c7e0f00e854ff1671e6294e78452
7
- data.tar.gz: 7aa47a8c5fd5dd2ff8a7e63fe7f203f9889a26bd7f20c94b3b126fe9cf8d52c78a5f5131d684e232b3ac37961c7c074f02531afe53c41e2904509b211441cf15
6
+ metadata.gz: 9efd7278de80bcf3599ca631cdb7dfa174bcf8ac3fa258313b01f2ba4e097d09f3eaa6f8362331e94d337696dce8643ce3fe14c88fbf0a31db5e12756c81eb63
7
+ data.tar.gz: 793f55f9df33b7489478d4029ec75e2ea831802893d88e71ea13ffe31e689ef0232a94fad5795ac1e0459ac1da585cc07e0341da04612a3d97f93b7c2832f044
@@ -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
- return to_enum(__method__, fb, params) unless block_given?
60
- qry = @fb.query(@term, @maps)
61
- Timeout.timeout(@timeout) do
62
- qry.each(fb, params, &)
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
- rescue Timeout::Error => e
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
- qry = @fb.query(@term, @maps)
70
- Timeout.timeout(@timeout) do
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
- qry = @fb.query(@term, @maps)
79
- Timeout.timeout(@timeout) do
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 "delete!() timed out after #{@timeout.seconds} (#{e.message}): #{@term}"
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
@@ -9,5 +9,5 @@
9
9
  # License:: MIT
10
10
  class Factbase
11
11
  # Current version of the gem (changed by .rultor.yml on every release)
12
- VERSION = '0.14.2' unless const_defined?(:VERSION)
12
+ VERSION = '0.14.3' unless const_defined?(:VERSION)
13
13
  end
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: factbase
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.14.2
4
+ version: 0.14.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko