|
5 | 5 | package models
|
6 | 6 |
|
7 | 7 | import (
|
| 8 | + "fmt" |
8 | 9 | "sort"
|
| 10 | + "sync" |
9 | 11 | "testing"
|
10 | 12 | "time"
|
11 | 13 |
|
@@ -417,3 +419,43 @@ func TestIssue_ResolveMentions(t *testing.T) {
|
417 | 419 | // Private repo, whole team
|
418 | 420 | testSuccess("user17", "big_test_private_4", "user15", []string{"user17/owners"}, []int64{18})
|
419 | 421 | }
|
| 422 | + |
| 423 | +func TestCorrectIssueStats(t *testing.T) { |
| 424 | + assert.NoError(t, PrepareTestDatabase()) |
| 425 | + |
| 426 | + // Because the condition is to have chunked database look-ups, |
| 427 | + // We have to more issues than `maxQueryParameters`, we will insert. |
| 428 | + // maxQueryParameters + 10 issues into the testDatabase. |
| 429 | + // Each new issues will have a constant description "Bugs are nasty" |
| 430 | + // Which will be used later on. |
| 431 | + |
| 432 | + issueAmount := maxQueryParameters + 10 |
| 433 | + |
| 434 | + var wg sync.WaitGroup |
| 435 | + for i := 0; i < issueAmount; i++ { |
| 436 | + wg.Add(1) |
| 437 | + go func(i int) { |
| 438 | + testInsertIssue(t, fmt.Sprintf("Issue %d", i+1), "Bugs are nasty", 0) |
| 439 | + wg.Done() |
| 440 | + }(i) |
| 441 | + } |
| 442 | + wg.Wait() |
| 443 | + |
| 444 | + // Now we will get all issueID's that match the "Bugs are nasty" query. |
| 445 | + total, ids, err := SearchIssueIDsByKeyword("Bugs are nasty", []int64{1}, issueAmount, 0) |
| 446 | + |
| 447 | + // Just to be sure. |
| 448 | + assert.NoError(t, err) |
| 449 | + assert.EqualValues(t, issueAmount, total) |
| 450 | + |
| 451 | + // Now we will call the GetIssueStats with these IDs and if working, |
| 452 | + // get the correct stats back. |
| 453 | + issueStats, err := GetIssueStats(&IssueStatsOptions{ |
| 454 | + RepoID: 1, |
| 455 | + IssueIDs: ids, |
| 456 | + }) |
| 457 | + |
| 458 | + // Now check the values. |
| 459 | + assert.NoError(t, err) |
| 460 | + assert.EqualValues(t, issueStats.OpenCount, issueAmount) |
| 461 | +} |
0 commit comments