Skip to content
This repository has been archived by the owner on Mar 11, 2021. It is now read-only.

Random test failures because of work item creation error (#1676) #1677

Merged
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
27d530d
Stabilize/disable tests related to if_modified_since_header (#1655)
xcoulon Oct 2, 2017
3481ff7
Random test failures because of work item creation error (#1676)
xcoulon Oct 2, 2017
79ce30a
Taking comments into account
xcoulon Oct 2, 2017
d175ffd
Merge branch 'master' into Issue1676_test_failures_duplicate_key
xcoulon Oct 3, 2017
461eeca
Refactor the `SearchByText` test
xcoulon Oct 3, 2017
b01a50c
Merge branch 'master' into Issue1676_test_failures_duplicate_key
xcoulon Oct 5, 2017
afe48ec
Addressing review comments
xcoulon Oct 6, 2017
d981209
Merge branch 'master' into Issue1676_test_failures_duplicate_key
xcoulon Oct 6, 2017
4477a20
Fix test failures (register URL pattern)
xcoulon Oct 6, 2017
1cb3ca8
Adding a test to create work items concurrently
xcoulon Oct 6, 2017
6e24feb
Merge branch 'master' into Issue1676_test_failures_duplicate_key
xcoulon Oct 9, 2017
d07b413
Refactor identities creation in test
xcoulon Oct 9, 2017
c74f9b0
Refactor TestSearch (again)
xcoulon Oct 9, 2017
15a49f8
Using constants for work item states
xcoulon Oct 9, 2017
9df5af2
Simplify tests
xcoulon Oct 10, 2017
65f499b
Merge branch 'master' into Issue1676_test_failures_duplicate_key
xcoulon Oct 10, 2017
fb7379e
More review comments
xcoulon Oct 10, 2017
21d67d8
Merge branch 'master' into Issue1676_test_failures_duplicate_key
xcoulon Oct 10, 2017
0cfb792
Create 10 work items per test
xcoulon Oct 11, 2017
6cc2e96
refactor the search tests using subtests, and fix race condition in c…
xcoulon Oct 11, 2017
239517b
Merge branch 'master' into Issue1676_test_failures_duplicate_key
xcoulon Oct 11, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions account/identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,9 @@ func (m *GormIdentityRepository) Create(ctx context.Context, model *Identity) er
}, "unable to create the identity")
return errs.WithStack(err)
}
log.Info(ctx, map[string]interface{}{
log.Debug(ctx, map[string]interface{}{
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest to just reduce the test output by setting F8_LOG_LEVEL=error instead of changing the level code-wise. Most repo create functions use log.Info. Also run tests with go test instead of go test -v

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know I can do that (F8_LOG_LEVEL=error and go test without the verbose flag), but do we really need those logs statements at the INFO level ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably not. Did you cover all "created X" log messages? Then it is fine to change to Debug if you ask me. I mostly feared mixing concerns of this PR.

"identity_id": model.ID,
}, "Identity created!")
}, "Identity created")
return nil
}

Expand Down
6 changes: 3 additions & 3 deletions controller/workitem_blackbox_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -797,12 +797,12 @@ func createOneRandomIteration(ctx context.Context, db *gorm.DB) *iteration.Itera
return &itr
}

func createOneRandomArea(ctx context.Context, db *gorm.DB, testName string) *area.Area {
func createOneRandomArea(ctx context.Context, db *gorm.DB) *area.Area {
areaRepo := area.NewAreaRepository(db)
spaceRepo := space.NewRepository(db)

newSpace := space.Space{
Name: fmt.Sprintf("Space area %v %v", testName, uuid.NewV4()),
Name: fmt.Sprintf("Space area %v", uuid.NewV4()),
}
space, err := spaceRepo.Create(ctx, &newSpace)
if err != nil {
Expand Down Expand Up @@ -1506,7 +1506,7 @@ func (s *WorkItem2Suite) TestWI2ListByStateFilterOKModifiedUsingIfNoneMatchIfMod
}

func (s *WorkItem2Suite) setupAreaWorkItem(createWorkItem bool) (uuid.UUID, string, *app.WorkItemSingle) {
tempArea := createOneRandomArea(s.svc.Context, s.DB, "TestWI2ListByAreaFilter")
tempArea := createOneRandomArea(s.svc.Context, s.DB)
require.NotNil(s.T(), tempArea)
areaID := tempArea.ID.String()
c := minimumRequiredCreatePayload()
Expand Down
2 changes: 2 additions & 0 deletions glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions glide.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ import:
- golint
- package: github.com/fzipp/gocyclo
- package: github.com/Sirupsen/logrus
version: c078b1e43f58d563c74cebe63c85789e76ddb627
repo: https://github.com/sirupsen/logrus
vcs: git
- package: github.com/sourcegraph/syntaxhighlight
- package: github.com/jstemmer/go-junit-report
- package: github.com/sourcegraph/annotate
Expand Down
2 changes: 1 addition & 1 deletion gormsupport/cleaner/db_clean.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func DeleteCreatedEntities(db *gorm.DB) func() {
}
for i := len(entires) - 1; i >= 0; i-- {
entry := entires[i]
log.Info(nil, map[string]interface{}{
log.Debug(nil, map[string]interface{}{
"table": entry.table,
"key": entry.key,
"hook_name": hookName,
Expand Down
16 changes: 6 additions & 10 deletions search/search_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,9 @@ func getSearchQueryFromURLPattern(patternName, stringToMatch string) string {
searchQueryString = fmt.Sprintf("%s:*", searchQueryString)
if result["id"] != "" {
// Look for pattern's ID field, if exists update searchQueryString
searchQueryString = fmt.Sprintf("(%v:* | %v)", result["id"], searchQueryString)
// `*A` is used to add sme weight to the work item number in the search results.
// See https://www.postgresql.org/docs/9.6/static/textsearch-controls.html
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @xcoulon for adding this reference!

searchQueryString = fmt.Sprintf("(%v:*A | %v)", result["id"], searchQueryString)
// searchQueryString = "(" + result["id"] + ":*" + " | " + searchQueryString + ")"
}
return searchQueryString
Expand Down Expand Up @@ -239,9 +241,11 @@ func parseSearchString(ctx context.Context, rawSearchString string) (searchKeywo
}
res.workItemTypes = append(res.workItemTypes, typeID)
} else if govalidator.IsURL(part) {
log.Debug(ctx, map[string]interface{}{"url": part}, "found a URL in the query string")
part := strings.ToLower(part)
part = trimProtocolFromURLString(part)
searchQueryFromURL := getSearchQueryFromURLString(part)
log.Debug(ctx, map[string]interface{}{"url": part, "search_query": searchQueryFromURL}, "found a URL in the query string")
res.words = append(res.words, searchQueryFromURL)
} else {
part := strings.ToLower(part)
Expand Down Expand Up @@ -446,7 +450,6 @@ func (q Query) generateExpression() (criteria.Expression, error) {

// parseFilterString accepts a raw string and generates a criteria expression
func parseFilterString(ctx context.Context, rawSearchString string) (criteria.Expression, error) {

fm := map[string]interface{}{}
// Parsing/Unmarshalling JSON encoding/json
err := json.Unmarshal([]byte(rawSearchString), &fm)
Expand Down Expand Up @@ -481,7 +484,6 @@ func generateSQLSearchInfo(keywords searchKeyword) (sqlParameter string) {
// extracted this function from List() in order to close the rows object with "defer" for more readability
// workaround for https://github.com/lib/pq/issues/81
func (r *GormSearchRepository) search(ctx context.Context, sqlSearchQueryParameter string, workItemTypes []uuid.UUID, start *int, limit *int, spaceID *string) ([]workitem.WorkItemStorage, uint64, error) {
log.Info(ctx, nil, "Searching work items...")
db := r.db.Model(workitem.WorkItemStorage{}).Where("tsv @@ query")
if start != nil {
if *start < 0 {
Expand Down Expand Up @@ -573,6 +575,7 @@ func (r *GormSearchRepository) SearchFullText(ctx context.Context, rawSearchStri

sqlSearchQueryParameter := generateSQLSearchInfo(parsedSearchDict)
var rows []workitem.WorkItemStorage
log.Debug(ctx, map[string]interface{}{"search query": sqlSearchQueryParameter}, "searching for work items")
rows, count, err := r.search(ctx, sqlSearchQueryParameter, parsedSearchDict.workItemTypes, start, limit, spaceID)
if err != nil {
return nil, 0, errs.WithStack(err)
Expand Down Expand Up @@ -741,10 +744,3 @@ func (r *GormSearchRepository) Filter(ctx context.Context, rawFilterString strin
}
return res, count, nil
}

func init() {
// While registering URLs do not include protocol because it will be removed before scanning starts
// Please do not include trailing slashes because it will be removed before scanning starts
RegisterAsKnownURL("test-work-item-list-details", `(?P<domain>demo.almighty.io)(?P<path>/work-item/list/detail/)(?P<id>\d*)`)
RegisterAsKnownURL("test-work-item-board-details", `(?P<domain>demo.almighty.io)(?P<path>/work-item/board/detail/)(?P<id>\d*)`)
}
Loading