Skip to content

Commit 5149408

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 92eadd7 commit 5149408

File tree

1 file changed

+31
-19
lines changed

1 file changed

+31
-19
lines changed

src/tarantool/bank.clj

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@
2727

2828
(setup! [this test node]
2929
(locking BankClientWithLua
30-
(let [conn (cl/open node test)]
30+
(let [conn (cl/open node test)
31+
; Distribute initial balances uniformly.
32+
initial-balance-per-account (/ (:total-amount test)
33+
(count (:accounts test)))]
3134
(Thread/sleep 10000) ; wait for leader election and joining to a cluster
3235
(when (= node (first (db/primaries test)))
3336
(cl/with-conn-failure-retry conn
@@ -37,10 +40,10 @@
3740
balance INT NOT NULL)")])
3841
(doseq [a (:accounts test)]
3942
(info "Populating account")
40-
(sql/insert! conn table-name {:id a
41-
:balance (if (= a (first (:accounts test)))
42-
(:total-amount test)
43-
0)}))))
43+
(sql/insert! conn table-name
44+
{:id a
45+
:balance initial-balance-per-account}))))
46+
4447
(assoc this :conn conn :node node))))
4548

4649
(invoke! [this test op]
@@ -79,7 +82,10 @@
7982

8083
(setup! [this test node]
8184
(locking tbl-created?
82-
(let [conn (cl/open node test)]
85+
(let [conn (cl/open node test)
86+
; Distribute initial balances uniformly.
87+
initial-balance-per-account (/ (:total-amount test)
88+
(count (:accounts test)))]
8389
(Thread/sleep 10000) ; wait for leader election and joining to a cluster
8490
(when (= node (first (db/primaries test)))
8591
(when (compare-and-set! tbl-created? false true)
@@ -92,9 +98,10 @@
9298
"balance INT NOT NULL)")])
9399
(info "Populating account" a)
94100
(sql/insert! conn (str table-name a)
95-
{:id 0
96-
:account_id a
97-
:balance 10})))))
101+
{:id 0
102+
:account_id a
103+
:balance initial-balance-per-account})))))
104+
98105
(assoc this :conn conn :node node))))
99106

100107
(invoke! [this test op]
@@ -147,7 +154,10 @@
147154

148155
(setup! [this test node]
149156
(locking BankClient
150-
(let [conn (cl/open node test)]
157+
(let [conn (cl/open node test)
158+
; Distribute initial balances uniformly.
159+
initial-balance-per-account (/ (:total-amount test)
160+
(count (:accounts test)))]
151161
(Thread/sleep 10000) ; wait for leader election and joining to a cluster
152162
(when (= node (first (db/primaries test)))
153163
(cl/with-conn-failure-retry conn
@@ -157,10 +167,10 @@
157167
balance INT NOT NULL)")])
158168
(doseq [a (:accounts test)]
159169
(info "Populating account")
160-
(sql/insert! conn table-name {:id a
161-
:balance (if (= a (first (:accounts test)))
162-
(:total-amount test)
163-
0)}))))
170+
(sql/insert! conn table-name
171+
{:id a
172+
:balance initial-balance-per-account}))))
173+
164174
(assoc this :conn conn :node node))))
165175

166176
(invoke! [this test op]
@@ -209,7 +219,10 @@
209219

210220
(setup! [this test node]
211221
(locking tbl-created?
212-
(let [conn (cl/open node test)]
222+
(let [conn (cl/open node test)
223+
; Distribute initial balances uniformly.
224+
initial-balance-per-account (/ (:total-amount test)
225+
(count (:accounts test)))]
213226
(Thread/sleep 10000) ; wait for leader election and joining to a cluster
214227
(when (= node (first (db/primaries test)))
215228
(when (compare-and-set! tbl-created? false true)
@@ -221,10 +234,9 @@
221234
"balance INT NOT NULL)")])
222235
(info "Populating account" a)
223236
(sql/insert! conn (str table-name a)
224-
{:id 0
225-
:balance (if (= a (first (:accounts test)))
226-
(:total-amount test)
227-
0)})))))
237+
{:id 0
238+
:balance initial-balance-per-account})))))
239+
228240
(assoc this :conn conn :node node))))
229241

230242
(invoke! [this test op]

0 commit comments

Comments
 (0)