diff --git a/src/server/server_concurrency_test.go b/src/server/server_concurrency_test.go index 84a8176..584288e 100644 --- a/src/server/server_concurrency_test.go +++ b/src/server/server_concurrency_test.go @@ -56,31 +56,36 @@ 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) { - clients := []*MockClient{} - for userName := range users { - client := &MockClient{errs: []error{}} - clients = append(clients, client) - wg.Add(1) - go client.uploadAndDownload(t, addr, userName, userPwd, filesCount, &wg) - } + for i := 0; i < rounds; i++ { + clients := []*MockClient{} + var wg sync.WaitGroup - wg.Wait() + for userName := range users { + client := &MockClient{errs: []error{}} + clients = append(clients, client) + wg.Add(1) + go client.uploadAndDownload(t, addr, userName, userPwd, filesCount, &wg) + } - errs := []error{} - for _, client := range clients { - if len(client.errs) > 0 { - errs = append(errs, client.errs...) + wg.Wait() + + errs := []error{} + for _, client := range clients { + if len(client.errs) > 0 { + errs = append(errs, client.errs...) + } + } + if len(errs) > 0 { + t.Fatal(joinErrs(errs)) } } - if len(errs) > 0 { - t.Fatal(joinErrs(errs)) - } + }) } diff --git a/src/server/test_helpers.go b/src/server/test_helpers.go index b5bf6ed..52e51b0 100644 --- a/src/server/test_helpers.go +++ b/src/server/test_helpers.go @@ -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 + } + } }