-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
WIP: Add a concurrent test for issue creation #7950
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,10 +5,13 @@ | |
package integrations | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net/http" | ||
"path" | ||
"strconv" | ||
"strings" | ||
"sync" | ||
"testing" | ||
|
||
"code.gitea.io/gitea/models" | ||
|
@@ -184,3 +187,34 @@ func TestIssueCommentClose(t *testing.T) { | |
val := htmlDoc.doc.Find(".comment-list .comments .comment .render-content p").First().Text() | ||
assert.Equal(t, "Description", val) | ||
} | ||
|
||
func TestNewIssueConcurrent(t *testing.T) { | ||
|
||
prepareTestEnv(t) | ||
session := loginUser(t, "user2") | ||
|
||
f := func(ctx context.Context, cancel context.CancelFunc, wg *sync.WaitGroup) { | ||
defer wg.Done() | ||
|
||
select { | ||
case <-ctx.Done(): | ||
return | ||
default: | ||
} | ||
testNewIssue(t, session, "user2", "repo1", fmt.Sprintf("Title"), "Description") | ||
if t.Failed() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think a great deal of times this function will fail for reasons unrelated to a duplicate key (which is what this test is for) and give false negatives. It's important to check the error and verify it is actually a duplicate key; other errors should be ignored. Gitea will be built in all kinds of environments, e.g. small Raspberry Pi boards. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's true. But I am afraid that there are some other undiscovered bugs, so an integration test might be helpful to an extent if it can reveal them. |
||
cancel() | ||
return | ||
} | ||
} | ||
|
||
wg := &sync.WaitGroup{} | ||
ctx, cancel := context.WithCancel(context.Background()) | ||
defer cancel() | ||
|
||
for i := 0; i < 1000; i++ { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note: launching 1,000 threads will not result in 1,000 simultaneous calls to the database, as the database can have a reduced connection pool. I believe that there are defaults in golang for the number of simultaneous threads too. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That makes sense. Noted. |
||
wg.Add(1) | ||
go f(ctx, cancel, wg) | ||
} | ||
wg.Wait() | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are stressing the database here (what you need) but also stressing other layers, like the http client & server, the computer resources, etc. I think it would be preferrable if you'd call the models/issue.go methods instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. I'll try to figure out how to do that.