-
-
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
Conversation
dc23539
to
6d888d2
Compare
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.
Can you rebase your changes on my PR? Something like:
git fetch origin pull/7944/head:a-branch-name-of-your-liking
This way Gitea's drone can test it with the code that in theory should not fail.
return | ||
default: | ||
} | ||
testNewIssue(t, session, "user2", "repo1", fmt.Sprintf("Title"), "Description") |
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.
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 comment
The 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.
Also, this might extend the test times beyond the alloted values in the drone (something to be dealt with).
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.
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.
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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
That makes sense. Noted.
I thought that it could minimize the probability of false negative.
I'll revisit my presumptions considering there is a limited number of connections.
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.
Good idea for PR. I would suggest to reduce the number of call for the integration test and do more intensive test in a unit tests.
@guillep2k have you try to cherry pick this PR over your PR to validate ? |
Have you had any progress with this? Are you still getting random errors from the databases? I'm thinking that rather than starting with an empty table, this test would be much more efficient if |
@guillep2k @sapk I am also considering if the parallel subtests of the |
I think it's important to bypass the HTTP API for this. Otherwise the chain is too long and any one link can fail, not only the potential dup key problem. Also, it's difficult to stress a database unless you're dealing with it in the most direct way possible. Having that level of concurrency is unrealistic. There will never be 1,000 threads running at the same time. The database connections are pooled and therefore most clients will be waiting in queue, which does not serve the purpose. In your tests you're hitting:
I'm no golang expert, but I do have experience with this kind of scenario. I'd restructure this test in the following way:
With 4 or 8 threads, chances of simultaneous insert are probably the same as with 1,000, but it's less likely to fail for other causes. At least that's what I think. |
OK, I couldn't help myself. Please check #7959. |
In favor of #7959 |
Related to #7887, #7944