Skip to content

Commit c9761c5

Browse files
committed
bank*: distribute initial balances uniformly
Before this commit the initial distribution was the following: first account has `total-amount` balances, other 9 ones have zero balance. From time to time is appears that there are no attempts to transfer from the first account. It means that all transfers are marked as failed and the history analysis reports fail. Even when there are some successful transfers, there are many attempts to transfer from an account with zero balance: those transfers are useless in terms of tarantool testing. This commit changes the initial distribution to the uniform one and resolves the problems, which are described above. See the linked issue for details. Aside of the problematic bank-lua I changed other banking tests in the same way to unify the approach. How each test is changed: * bank-lua: [100 0 0 0 0 0 0 0 0 0] -> [10 10 10 10 10 10 10 10 10 10]. * bank-multitable-lua: the test already distributes initial balances uniformly, but hardcodes balance value. Now it is deduced from the `total-amount` parameter. * bank: same as bank-lua. * bank-multitable: same as bank-lua. 'bank' and 'bank-multitable' fixes are blind, because they're disabled. See #83. 'bank-lua' and 'bank-multitable-lua' are passed in a manual run. 'bank-lua' gives 2-3 failed transfers of ~40 ones. Before it was like 5-15 *successful* ones of 30-40. (I have no representative statistics, just looked over several runs in CI, but the numbers looks expected.) Fixes #94
1 parent 78b0dc1 commit c9761c5

File tree

1 file changed

+42
-19
lines changed

1 file changed

+42
-19
lines changed

src/tarantool/bank.clj

+42-19
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
[db :as db]]))
1818

1919
(def table-name "accounts")
20+
(def err-unable-to-distribute-balances (str
21+
"Unable to distribute initial balances uniformly "
22+
"for given total-amount and accounts"))
2023

2124
(defrecord BankClientWithLua [conn]
2225
client/Client
@@ -27,7 +30,12 @@
2730

2831
(setup! [this test node]
2932
(locking BankClientWithLua
30-
(let [conn (cl/open node test)]
33+
(let [conn (cl/open node test)
34+
; Distribute initial balances uniformly.
35+
initial-balance-per-account (/ (:total-amount test)
36+
(count (:accounts test)))]
37+
assert((integer? initial-balance-per-account)
38+
err-unable-to-distribute-balances)
3139
(Thread/sleep 10000) ; wait for leader election and joining to a cluster
3240
(when (= node (first (db/primaries test)))
3341
(cl/with-conn-failure-retry conn
@@ -37,10 +45,10 @@
3745
balance INT NOT NULL)")])
3846
(doseq [a (:accounts test)]
3947
(info "Populating account")
40-
(sql/insert! conn table-name {:id a
41-
:balance (if (= a (first (:accounts test)))
42-
(:total-amount test)
43-
0)}))))
48+
(sql/insert! conn table-name
49+
{:id a
50+
:balance initial-balance-per-account}))))
51+
4452
(assoc this :conn conn :node node))))
4553

4654
(invoke! [this test op]
@@ -79,7 +87,12 @@
7987

8088
(setup! [this test node]
8189
(locking tbl-created?
82-
(let [conn (cl/open node test)]
90+
(let [conn (cl/open node test)
91+
; Distribute initial balances uniformly.
92+
initial-balance-per-account (/ (:total-amount test)
93+
(count (:accounts test)))]
94+
assert((integer? initial-balance-per-account)
95+
err-unable-to-distribute-balances)
8396
(Thread/sleep 10000) ; wait for leader election and joining to a cluster
8497
(when (= node (first (db/primaries test)))
8598
(when (compare-and-set! tbl-created? false true)
@@ -92,9 +105,10 @@
92105
"balance INT NOT NULL)")])
93106
(info "Populating account" a)
94107
(sql/insert! conn (str table-name a)
95-
{:id 0
96-
:account_id a
97-
:balance 10})))))
108+
{:id 0
109+
:account_id a
110+
:balance initial-balance-per-account})))))
111+
98112
(assoc this :conn conn :node node))))
99113

100114
(invoke! [this test op]
@@ -147,7 +161,12 @@
147161

148162
(setup! [this test node]
149163
(locking BankClient
150-
(let [conn (cl/open node test)]
164+
(let [conn (cl/open node test)
165+
; Distribute initial balances uniformly.
166+
initial-balance-per-account (/ (:total-amount test)
167+
(count (:accounts test)))]
168+
assert((integer? initial-balance-per-account)
169+
err-unable-to-distribute-balances)
151170
(Thread/sleep 10000) ; wait for leader election and joining to a cluster
152171
(when (= node (first (db/primaries test)))
153172
(cl/with-conn-failure-retry conn
@@ -157,10 +176,10 @@
157176
balance INT NOT NULL)")])
158177
(doseq [a (:accounts test)]
159178
(info "Populating account")
160-
(sql/insert! conn table-name {:id a
161-
:balance (if (= a (first (:accounts test)))
162-
(:total-amount test)
163-
0)}))))
179+
(sql/insert! conn table-name
180+
{:id a
181+
:balance initial-balance-per-account}))))
182+
164183
(assoc this :conn conn :node node))))
165184

166185
(invoke! [this test op]
@@ -209,7 +228,12 @@
209228

210229
(setup! [this test node]
211230
(locking tbl-created?
212-
(let [conn (cl/open node test)]
231+
(let [conn (cl/open node test)
232+
; Distribute initial balances uniformly.
233+
initial-balance-per-account (/ (:total-amount test)
234+
(count (:accounts test)))]
235+
assert((integer? initial-balance-per-account)
236+
err-unable-to-distribute-balances)
213237
(Thread/sleep 10000) ; wait for leader election and joining to a cluster
214238
(when (= node (first (db/primaries test)))
215239
(when (compare-and-set! tbl-created? false true)
@@ -221,10 +245,9 @@
221245
"balance INT NOT NULL)")])
222246
(info "Populating account" a)
223247
(sql/insert! conn (str table-name a)
224-
{:id 0
225-
:balance (if (= a (first (:accounts test)))
226-
(:total-amount test)
227-
0)})))))
248+
{:id 0
249+
:balance initial-balance-per-account})))))
250+
228251
(assoc this :conn conn :node node))))
229252

230253
(invoke! [this test op]

0 commit comments

Comments
 (0)