Skip to content

add more tests around bits counters - #1441

Merged
nbrownus merged 3 commits into
masterfrom
bits-test
Nov 18, 2025
Merged

add more tests around bits counters#1441
nbrownus merged 3 commits into
masterfrom
bits-test

Conversation

@wadey

@wadey wadey commented Aug 4, 2025

Copy link
Copy Markdown
Member

Trying to see if the logic around "lost" packets is correct. This test should show lost packets as it misses packet 8, but the test currently fails because we don't note the lost packet.

Trying to see if the logic around "lost" packets is correct. This test
should fail as it misses packet 8
@wadey wadey added this to the v2.0.0 milestone Aug 4, 2025
@nbrownus

Copy link
Copy Markdown
Collaborator

I fixed the bug and updated the code to simplify and try to explain more betterer whats going on.

@nbrownus
nbrownus marked this pull request as ready for review November 18, 2025 04:08
Comment thread bits.go
if i > b.current && i < b.current+b.length {
// In between current and i need to be zero'd to allow those packets to come in later
for n := b.current + 1; n < i; n++ {
b.bits[n%b.length] = false

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The original issue was not tracking lost for these zeroed out counter values

@nbrownus
nbrownus marked this pull request as draft November 18, 2025 06:05
Comment thread bits.go
if b.current == i {
// If i is within the current window but below the current counter,
// Check to see if it's a duplicate
if i > b.current-b.length || i < b.length && b.current < b.length {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

this statement frightens the C programmer

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can break it back out again

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

eh I think it's find, the most I'd do is add some () around things to strongly communicate order

but golang already has sane evaluation order so we probably don't even need to do that

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'm surprised go fmt doesn't add the parentheses for you, I appreciate that prettier adds them to make evaluation order explicitly obvious.

@nbrownus
nbrownus marked this pull request as ready for review November 18, 2025 16:52

@wadey wadey left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Your fixes LGTM, need to find someone else to review though since I opened the PR with the failing test.

@jrwren jrwren left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

am I crazy to not study it too thoroughly because it seems like there are good tests in place? LGTM

Comment thread bits.go
if i > b.length && b.bits[i%b.length] == false {
// Check if the oldest bit was lost since we are shifting the window by 1 and occupying it with this counter
// The very first window can only be tracked as lost once we are on the 2nd window or greater
if b.bits[i%b.length] == false && i > b.length {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

any particular reason the left and ride side of && are swapped from what they were before? I don't know how good the Go compiler is at optimizing this, but at first glance it seems like i > b.length would be the less costly operation and would be good to do first?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Silly micro-op since i > b.length is more than likely always true. Our window size is 1024 currently, after which every packet would pass that part of the if statement.

@nbrownus
nbrownus merged commit 27ea667 into master Nov 18, 2025
9 checks passed
@nbrownus
nbrownus deleted the bits-test branch November 18, 2025 22:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants