test(server: add rounds for concurrency test

This commit is contained in:
hexxa 2022-08-26 20:01:33 +08:00 committed by Hexxa
parent a36ef5f98f
commit d0a8a6d43a
2 changed files with 35 additions and 18 deletions

View file

@ -56,14 +56,17 @@ func TestConcurrency(t *testing.T) {
}
adminToken := client.GetCookie(resp.Cookies(), q.TokenCookie)
userCount := 5
userCount := 2
userPwd := "1234"
users := addUsers(t, addr, userPwd, userCount, adminToken)
filesCount := 10
filesCount := 5
rounds := 2
var wg sync.WaitGroup
t.Run("Upload and download concurrently", func(t *testing.T) {
for i := 0; i < rounds; i++ {
clients := []*MockClient{}
var wg sync.WaitGroup
for userName := range users {
client := &MockClient{errs: []error{}}
clients = append(clients, client)
@ -82,5 +85,7 @@ func TestConcurrency(t *testing.T) {
if len(errs) > 0 {
t.Fatal(joinErrs(errs))
}
}
})
}

View file

@ -337,4 +337,16 @@ func (cl *MockClient) uploadAndDownload(tb testing.TB, addr, name, pwd string, f
))
return
}
// truncate all files
for i := 1; i < filesCount; i++ {
resp, _, errs = filesCl.Delete(getFilePath(name, i))
if len(errs) > 0 {
cl.errs = append(cl.errs, errs...)
return
} else if resp.StatusCode != 200 {
cl.errs = append(cl.errs, errors.New("failed to delete file"))
return
}
}
}