File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -66,4 +66,37 @@ public function testBlockIter3(): void
6666
6767 self ::assertSame ($ iterations * 2000 , $ user ->balanceInt );
6868 }
69+
70+ public function testRollback (): void
71+ {
72+ $ atomic = app (AtomicServiceInterface::class);
73+
74+ /** @var Buyer $user */
75+ $ user = BuyerFactory::new ()->create ();
76+
77+ $ user ->deposit (1000 );
78+
79+ self ::assertSame (1000 , $ user ->balanceInt );
80+
81+ try {
82+ $ atomic ->block ($ user , function () use ($ user ) {
83+ $ user ->forceWithdraw (1000 );
84+ $ user ->forceWithdraw (1000 );
85+ $ user ->forceWithdraw (1000 );
86+ $ user ->deposit (5000 );
87+
88+ throw new \Exception ();
89+ });
90+
91+ self ::assertTrue (false ); // check
92+ } catch (\Throwable ) {
93+ }
94+
95+ self ::assertTrue ($ user ->wallet ->refreshBalance ()); // check
96+
97+ $ userFromDb = Buyer::find ($ user ->getKey ());
98+
99+ self ::assertSame (1000 , $ userFromDb ->balanceInt );
100+ self ::assertSame (1000 , $ user ->balanceInt );
101+ }
69102}
You can’t perform that action at this time.
0 commit comments