Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
qdm12 committed Nov 2, 2021
1 parent becec9e commit 1a39207
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 7 deletions.
6 changes: 4 additions & 2 deletions lib/utils/pull_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var (
)

var (
titleRegexp = regexp.MustCompile(`^[A-Za-z]+\([A-Za-z/]+\):.+[A-Za-z]+$`)
titleRegexp = regexp.MustCompile(`^[A-Za-z-_ ]+\([-_/A-Za-z ]+\):.+[A-Za-z]+\.{0,1}$`)
commentRegexp = regexp.MustCompile(`<!--(.|\n)*?-->`)
)

Expand Down Expand Up @@ -48,7 +48,9 @@ func CheckPRDescription(title, body string) error {

index := strings.Index(body, textToFind)
if index == -1 {
return fmt.Errorf("%w: %q", ErrBodySectionNotFound, textToFind)
body = strings.ReplaceAll(body, "\n", "\\n")
body = strings.ReplaceAll(body, "\r", "\\r")
return fmt.Errorf("%w: %q in body: %s", ErrBodySectionNotFound, textToFind, body)
} else if i > 0 && index < previousIndex {
return fmt.Errorf("%w: section %q cannot be before section %q",
ErrBodySectionMisplaced, requiredSection, previousSection)
Expand Down
59 changes: 54 additions & 5 deletions lib/utils/pull_request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,20 @@ func Test_CheckPRDescription(t *testing.T) {
err error
}{
"all empty": {
err: errors.New("title pattern is not valid: for regular expression ^[A-Za-z]+\\([A-Za-z/]+\\):.+[A-Za-z]+$: ''"),
err: errors.New("title pattern is not valid: for regular expression ^[A-Za-z-_ ]+\\([-_/A-Za-z ]+\\):.+[A-Za-z]+\\.{0,1}$: ''"),
},
"invalid title": {
title: "category: something",
err: errors.New("title pattern is not valid: for regular expression ^[A-Za-z]+\\([A-Za-z/]+\\):.+[A-Za-z]+$: 'category: something'"),
err: errors.New("title pattern is not valid: for regular expression ^[A-Za-z-_ ]+\\([-_/A-Za-z ]+\\):.+[A-Za-z]+\\.{0,1}$: 'category: something'"),
},
"empty body only": {
title: "category(subcategory): something",
err: errors.New("body section not found: \"## Changes\\n\""),
err: errors.New("body section not found: \"## Changes\\n\" in body: "),
},
"invalid body": {
title: "category(subcategory): something",
body: "##Changes ## Tests ## Issues ## Primary Reviewer",
err: errors.New("body section not found: \"## Changes\\n\""),
body: "##Change\n## Tests ## Issues ## Primary Reviewer",
err: errors.New("body section not found: \"## Changes\\n\" in body: ##Change\n## Tests ## Issues ## Primary Reviewer"),
},
"misplaced section": {
title: "category(subcategory): something",
Expand Down Expand Up @@ -75,6 +75,55 @@ supported format for automatically closing issues (ie, closes #123, fixes #123)
-->
- @noot for demo:12
`,
},
"valid example 2": {
title: `fix(dot/state): fix deadlock, fixes bootstrap syncing`,
body: `## Changes
<!--
Please provide a brief but specific list of changes made, describe the changes
in functionality rather than the changes in code.
-->
- deadlock was caused as ` + "`" + `GetBlockByHash()` + "`" + ` calls ` + "`" + `RLock()` + "`" + `, ` + "`" + `GetBlockByHash()` + "`" + ` calls ` + "`" + `GetBlockBody()` + "`" + ` which previously also called ` + "`" + `RLock()` + "`" + `. this was ok when there were no calls to the write lock ` + "`" + `Lock()` + "`" + ` simultaneously. however the deadlock scenario occurred when one goroutine was calling ` + "`" + `GetBlockBody()` + "`" + ` (with 1 read-lock obtained) and another called ` + "`" + `SetFinalisedHash()` + "`" + ` (thus obtaining the write-lock). as a read-lock can no longer be obtained if 1. write-lock was obtained (even if it was freed) and 2. another read-lock was already obtained, this caused a deadlock
- I ended up just removing the lock in ` + "`" + `GetBlockBody()` + "`" + ` to prevent multiple read-locks from being obtained. if anyone has a better method let me know :D
## Tests
<!--
Details on how to run tests relevant to the changes within this pull request.
-->
` + "```" + `
make gossamer
./bin/gossamer --chain polkadot
` + "```" + `
node can sync (up until it hits max memory :p) no more stalling/deadlocks
## Issues
<!--
Please link any issues that this pull request is related to and use the GitHub
supported format for automatically closing issues (ie, closes #123, fixes #123)
-->
- related to #1479
## Primary Reviewer
<!--
Please indicate one of the code owners that are required to review prior to merging changes (e.g. @noot)
-->
- @EclesioMeloJunior
`,
},
}
Expand Down

0 comments on commit 1a39207

Please sign in to comment.