-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
add go linter - "unused" #11235
Merged
Merged
add go linter - "unused" #11235
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
693791b
add go linter - "unused"
snissn 92864f4
use _ to name unused but needed padding variable
snissn fc3ddca
remove unused code
snissn 435d156
add queue test to appease unused linter
snissn 3df176a
remove unused code in test
snissn ec91b4f
remove unused func
snissn e29f2ba
remove unused struct identified by linter
snissn 2147e3e
remove unused variable
snissn dd11eb9
remove unused code
snissn 8c7ed96
remove unused file
snissn c2b20a0
remove unused struct
snissn 85121b4
remove unused function
snissn 08f8313
remove unused observe peers function in raft
snissn 35a9039
remove unused declareFaults function
snissn d9ae2ad
annotate nolint:unused on needed methods
snissn 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 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 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 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 was deleted.
Oops, something went wrong.
This file contains 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 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 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,61 @@ | ||
package ratelimit | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestQueue(t *testing.T) { | ||
const size = 3 | ||
q := &queue{buf: make([]int64, size)} | ||
|
||
if q.len() != 0 { | ||
t.Fatalf("q.len() = %d, expect 0", q.len()) | ||
} | ||
|
||
if q.cap() != size { | ||
t.Fatalf("q.cap() = %d, expect %d", q.cap(), size) | ||
} | ||
|
||
for i := int64(0); i < int64(size); i++ { | ||
err := q.push(i) | ||
if err != nil { | ||
t.Fatalf("cannot push element %d", i) | ||
} | ||
} | ||
|
||
if q.len() != size { | ||
t.Fatalf("q.len() = %d, expect %d", q.len(), size) | ||
} | ||
|
||
err := q.push(int64(size)) | ||
if err != ErrRateLimitExceeded { | ||
t.Fatalf("pushing element beyond capacity should have failed with err: %s, got %s", ErrRateLimitExceeded, err) | ||
} | ||
|
||
if q.front() != 0 { | ||
t.Fatalf("q.front() = %d, expect 0", q.front()) | ||
} | ||
|
||
if q.back() != int64(size-1) { | ||
t.Fatalf("q.back() = %d, expect %d", q.back(), size-1) | ||
} | ||
|
||
popVal := q.pop() | ||
if popVal != 0 { | ||
t.Fatalf("q.pop() = %d, expect 0", popVal) | ||
} | ||
|
||
if q.len() != size-1 { | ||
t.Fatalf("q.len() = %d, expect %d", q.len(), size-1) | ||
} | ||
|
||
// Testing truncation. | ||
threshold := int64(1) | ||
q.truncate(threshold) | ||
if q.len() != 1 { | ||
t.Fatalf("q.len() after truncate = %d, expect 1", q.len()) | ||
} | ||
if q.front() != 2 { | ||
t.Fatalf("q.front() after truncate = %d, expect 2", q.front()) | ||
} | ||
} |
This file contains 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 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 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 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 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 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 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 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 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 |
---|---|---|
|
@@ -32,6 +32,8 @@ import ( | |
) | ||
|
||
// recordPoStFailure records a failure in the journal. | ||
// | ||
//nolint:unused | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. are these false positives? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, they're called over an API. |
||
func (s *WindowPoStScheduler) recordPoStFailure(err error, ts *types.TipSet, deadline *dline.Info) { | ||
s.journal.RecordEvent(s.evtTypes[evtTypeWdPoStScheduler], func() interface{} { | ||
c := evtCommon{Error: err} | ||
|
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.
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.
No objection to this test, obviously, but I'm surprised it was needed to make the queue lok "used" -- it should already look used because of its use in rate limiting.
Do you understand why this was the case?
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.
Yes! I sort of understand, for some reason pop is unused:
it's pretty common to write a little datastructure library, write out a bunch of api/funcs for it, and then not use a few when you have your final implementation. I think there's some combination of peeking and truncating that happens in ./chain/sub/ratelimit/window.go instead of
pop
, but i haven't done a thorough dive into it. Given my expectation of this pattern of building a general tool and then just using some of it, the test made more sense than deleting pop in case in future we wanted to reorganize this code. also just a simple parallel example, might make sense to write a queue library that lets you take out values from the top or bottom, but so far only use one of themThere 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.
Got it, thanks for the explanation! Makes total sense.