Skip to content

Commit

Permalink
单元测试问题
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name committed Oct 27, 2023
1 parent f93c5b5 commit aec4d90
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/unit_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:


- name: go test
run: go test -v ./...
run: go test ./...



Expand Down
49 changes: 37 additions & 12 deletions cmd/haobase/clearing/clearing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,11 @@ func cleanOrders(t *testing.T) {
}

func TestLimitOrder(t *testing.T) {
initdb(t)
initSymbols(t)
initAssets(t)

Convey("限价单完全成交结算测试", t, func() {
initdb(t)
initSymbols(t)
initAssets(t)

sell, err := orders.NewLimitOrder(sellUser, testSymbol, trading_core.OrderSideSell, "1.00", "1")
So(err, ShouldBeNil)
Expand All @@ -107,7 +108,14 @@ func TestLimitOrder(t *testing.T) {
TradeTime: time.Now().UnixNano(),
}
clearing_trade_order(testSymbol, result.Json())
time.Sleep(5 * time.Second)

for {
if orders.GetLock(orders.ClearingLock, sell.OrderId) == 0 &&
orders.GetLock(orders.ClearingLock, buy.OrderId) == 0 {
break
}
time.Sleep(1 * time.Second)
}
//检查资产
sell_assets_target := assets.FindSymbol(sellUser, testTargetSymbol)
sell_assets_standard := assets.FindSymbol(sellUser, testBaseSymbol)
Expand Down Expand Up @@ -136,10 +144,11 @@ func TestLimitOrder(t *testing.T) {

func TestMarketCase1(t *testing.T) {

initdb(t)
initSymbols(t)
initAssets(t)

Convey("市价买指定的数量,完全成交", t, func() {
initdb(t)
initSymbols(t)
initAssets(t)

s1, err := orders.NewLimitOrder(sellUser, testSymbol, trading_core.OrderSideSell, "1.00", "1")
So(err, ShouldBeNil)
Expand Down Expand Up @@ -170,7 +179,14 @@ func TestMarketCase1(t *testing.T) {
clearing_trade_order(testSymbol, result2.Json())
clearing_trade_order(testSymbol, result1.Json())

time.Sleep(5 * time.Second)
for {
if orders.GetLock(orders.ClearingLock, s1.OrderId) == 0 &&
orders.GetLock(orders.ClearingLock, s2.OrderId) == 0 &&
orders.GetLock(orders.ClearingLock, buy.OrderId) == 0 {
break
}
time.Sleep(1 * time.Second)
}

//检查买卖双方订单状态及资产
s1 = orders.Find(testSymbol, s1.OrderId)
Expand Down Expand Up @@ -203,11 +219,11 @@ func TestMarketCase1(t *testing.T) {
}

func TestMarketCase2(t *testing.T) {
initdb(t)
initSymbols(t)
initAssets(t)

Convey("市价多单测试", t, func() {
initdb(t)
initSymbols(t)
initAssets(t)

s1, _ := orders.NewLimitOrder(sellUser, testSymbol, trading_core.OrderSideSell, "1.00", "1")
s2, _ := orders.NewLimitOrder(sellUser, testSymbol, trading_core.OrderSideSell, "2.00", "1")
Expand All @@ -227,7 +243,16 @@ func TestMarketCase2(t *testing.T) {
clearing_trade_order(testSymbol, result1.Json())
clearing_trade_order(testSymbol, result3.Json())

time.Sleep(5 * time.Second)
for {
if orders.GetLock(orders.ClearingLock, s1.OrderId) == 0 &&
orders.GetLock(orders.ClearingLock, s2.OrderId) == 0 &&
orders.GetLock(orders.ClearingLock, s3.OrderId) == 0 &&
orders.GetLock(orders.ClearingLock, s4.OrderId) == 0 &&
orders.GetLock(orders.ClearingLock, buy.OrderId) == 0 {
break
}
time.Sleep(1 * time.Second)
}

//资产
sell_assets_target := assets.FindSymbol(sellUser, testTargetSymbol)
Expand Down

0 comments on commit aec4d90

Please sign in to comment.