Skip to content

Commit

Permalink
a couple of tests
Browse files Browse the repository at this point in the history
  • Loading branch information
buck54321 committed Jul 4, 2022
1 parent 324af63 commit c8cfd74
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions server/auth/auth_test.go
Expand Up @@ -44,6 +44,7 @@ type ratioData struct {
oidsCancels []order.OrderID
oidsCanceled []order.OrderID
timesCanceled []int64
epochGaps []int
}

// TStorage satisfies the Storage interface
Expand Down Expand Up @@ -128,6 +129,7 @@ func (s *TStorage) ExecutedCancelsForUser(aid account.AccountID, _ int) (cancels
ID: s.ratio.oidsCancels[i],
TargetID: s.ratio.oidsCanceled[i],
MatchTime: s.ratio.timesCanceled[i],
EpochGap: s.ratio.epochGaps[i],
})
}
return cancels, nil
Expand Down Expand Up @@ -694,12 +696,15 @@ func TestConnect(t *testing.T) {
rig.storage.matches = []*db.MatchData{matchData}
defer func() { rig.storage.matches = nil }()

epochGaps := []int{1} // penalized

rig.storage.setRatioData(&ratioData{
oidsCompleted: []order.OrderID{{0x1}},
timesCompleted: []int64{1234},
oidsCancels: []order.OrderID{{0x2}},
oidsCanceled: []order.OrderID{{0x1}},
timesCanceled: []int64{1235},
epochGaps: epochGaps,
}) // 1:1 = 50%
defer rig.storage.setRatioData(&ratioData{}) // clean slate

Expand All @@ -710,6 +715,15 @@ func TestConnect(t *testing.T) {
t.Fatalf("Expected account %v to be closed on connect, got %v", user.acctID, rig.storage.closedID)
}

// Make it a free cancel.
rig.storage.closedID = account.AccountID{} // unclose the account in db
epochGaps[0] = 2
connectUser(t, user)
if rig.storage.closedID == user.acctID {
t.Fatalf("Expected account %v to NOT be closed with free cancels, but it was.", user)
}
epochGaps[0] = 1

// Try again just meeting cancel ratio.
rig.storage.closedID = account.AccountID{} // unclose the account in db
rig.mgr.cancelThresh = 0.6 // passable threshold for 1 cancel : 1 completion (0.5)
Expand All @@ -725,12 +739,22 @@ func TestConnect(t *testing.T) {
rig.storage.ratio.oidsCanceled = append(rig.storage.ratio.oidsCanceled, order.OrderID{0x3})
rig.storage.ratio.oidsCancels = append(rig.storage.ratio.oidsCancels, order.OrderID{0x4})
rig.storage.ratio.timesCanceled = append(rig.storage.ratio.timesCanceled, 12341234)
rig.storage.ratio.epochGaps = append(rig.storage.ratio.epochGaps, 1)

tryConnectUser(t, user, false)
if rig.storage.closedID != user.acctID {
t.Fatalf("Expected account %v to be closed on connect, got %v", user.acctID, rig.storage.closedID)
}

// Make one a free cancel.
rig.storage.closedID = account.AccountID{} // unclose the account in db
rig.storage.ratio.epochGaps[1] = 2
connectUser(t, user)
if rig.storage.closedID == user.acctID {
t.Fatalf("Expected account %v to NOT be closed with free cancels, but it was.", user)
}
rig.storage.ratio.epochGaps[1] = 0

// Try again just meeting cancel ratio.
rig.storage.closedID = account.AccountID{} // unclose the account in db
rig.mgr.cancelThresh = 0.7 // passable threshold for 2 cancel : 1 completion (0.6666..)
Expand All @@ -755,6 +779,7 @@ func TestConnect(t *testing.T) {
rig.storage.ratio.oidsCanceled = append(rig.storage.ratio.oidsCanceled, order.OrderID{0x4})
rig.storage.ratio.oidsCancels = append(rig.storage.ratio.oidsCancels, order.OrderID{0x5})
rig.storage.ratio.timesCanceled = append(rig.storage.ratio.timesCanceled, 12341239)
rig.storage.ratio.epochGaps = append(rig.storage.ratio.epochGaps, 1)

tryConnectUser(t, user, false)
if rig.storage.closedID == user.acctID {
Expand Down

0 comments on commit c8cfd74

Please sign in to comment.