-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Experiment (NOT FOR MERGING): Add test to stress insert ... select for Issue #7959
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
Closed
guillep2k
wants to merge
17
commits into
go-gitea:master
from
guillep2k:issue-idx-insert-select-stress
Closed
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
a1b93a2
Replace insert by insert.where to calculate issue.index atomically
guillep2k 3ae8be2
Remove unnecessary read-back of the index value
guillep2k d59f4bf
Checkout latest xorm code to include https://github.com/go-xorm/xorm/…
guillep2k 741d920
Apply make vendor
guillep2k 8473a96
Remove dead code
guillep2k d910d27
Add test to stress insert ... select for Issue
guillep2k 6544f0b
Correct for lint
guillep2k a689b0e
Correct doer user for the test
guillep2k 4326e9e
Merge branch 'master' of github.com:go-gitea/gitea into issue-idx-ins…
guillep2k dc63bd4
Reinsert reading-back of `Issue`.`Index`
guillep2k 87b38a3
Correct lint
guillep2k 704f6bf
Refactor code for proper testing in all engines
guillep2k b69d719
Pass fmt
guillep2k 2a6b37d
Pass lint
guillep2k f635995
Rename file name
guillep2k 182905c
Add transaction support
guillep2k 84d1fc7
Merge branch 'master' into issue-idx-insert-select-stress
guillep2k File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Copyright 2019 The Gitea Authors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package integrations | ||
|
||
import ( | ||
"testing" | ||
|
||
"code.gitea.io/gitea/models" | ||
) | ||
|
||
func TestIssueNoDupIndex(t *testing.T) { | ||
prepareTestEnv(t) | ||
|
||
models.TestIssueNoDupIndex(t) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
// Copyright 2019 The Gitea Authors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package models | ||
|
||
import ( | ||
"fmt" | ||
"sync" | ||
"sync/atomic" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
// TestIssueNoDupIndex Performs a stress test of the INSERT ... SELECT function of database for inserting issues | ||
func TestIssueNoDupIndex(t *testing.T) { | ||
assert.NoError(t, PrepareTestDatabase()) | ||
|
||
const initialIssueFill = 1000 // issues inserted prior to stress test | ||
const maxTestDuration = 60 // seconds | ||
const threadCount = 8 // max simultaneous threads | ||
const useTransactions = true // true: wrap attempts with BEGIN TRANSACTION/COMMIT | ||
|
||
var err error | ||
repo := AssertExistsAndLoadBean(t, &Repository{ID: 3}).(*Repository) | ||
doer := AssertExistsAndLoadBean(t, &User{ID: repo.OwnerID}).(*User) | ||
|
||
// Pre-load | ||
for i := 1; i < initialIssueFill; i++ { | ||
issue := &Issue{ | ||
RepoID: repo.ID, | ||
PosterID: repo.OwnerID, | ||
Index: int64(i + 5000), // Avoid clashing with other tests | ||
Title: fmt.Sprintf("NoDup initial %d", i), | ||
} | ||
_, err = x.Insert(issue) | ||
assert.NoError(t, err) | ||
} | ||
|
||
fmt.Printf("TestIssueNoDupIndex(): %d rows created\n", initialIssueFill) | ||
|
||
until := time.Now().Add(time.Second * maxTestDuration) | ||
|
||
var hasErrors int32 | ||
var wg sync.WaitGroup | ||
|
||
f := func(thread int) { | ||
defer wg.Done() | ||
sess := x.NewSession() | ||
defer sess.Close() | ||
i := 1 | ||
for { | ||
if time.Now().After(until) || atomic.LoadInt32(&hasErrors) != 0 { | ||
return | ||
} | ||
issue := &Issue{ | ||
guillep2k marked this conversation as resolved.
Show resolved
Hide resolved
|
||
RepoID: repo.ID, | ||
PosterID: repo.OwnerID, | ||
Title: fmt.Sprintf("NoDup stress %d, %d", thread, i), | ||
OriginalAuthor: "TestIssueNoDupIndex()", | ||
Priority: thread, // For statistics | ||
} | ||
if useTransactions { | ||
if err = sess.Begin(); err != nil { | ||
break | ||
} | ||
} | ||
if err = newIssue(sess, doer, NewIssueOptions{ | ||
Repo: repo, | ||
Issue: issue, | ||
}); err != nil { | ||
break | ||
} | ||
if useTransactions { | ||
if err = sess.Commit(); err != nil { | ||
break | ||
} | ||
} | ||
i++ | ||
} | ||
if useTransactions { | ||
_ = sess.Rollback() | ||
} | ||
atomic.StoreInt32(&hasErrors, 1) | ||
t.Logf("newIssue(): %+v", err) | ||
} | ||
|
||
for i := 1; i <= threadCount; i++ { | ||
go f(i) | ||
wg.Add(1) | ||
} | ||
|
||
fmt.Printf("TestIssueNoDupIndex(): %d threads created\n", threadCount) | ||
|
||
wg.Wait() | ||
|
||
for i := 1; i <= threadCount; i++ { | ||
total, err := x.Table("issue"). | ||
Where("original_author = ?", "TestIssueNoDupIndex()"). | ||
And("priority = ?", i). | ||
Count() | ||
assert.NoError(t, err, "Failed counting generated issues count") | ||
fmt.Printf("TestIssueNoDupIndex(): rows created in thread #%d: %d\n", i, total) | ||
} | ||
|
||
assert.Equal(t, int32(0), hasErrors, "Synchronization errors detected.") | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.