Skip to content

reimplement nextBackoffInterval tests to cover functional requirements#5161

Merged
ast2023 merged 2 commits intomainfrom
sasha/OSS-361
Nov 30, 2023
Merged

reimplement nextBackoffInterval tests to cover functional requirements#5161
ast2023 merged 2 commits intomainfrom
sasha/OSS-361

Conversation

@ast2023
Copy link
Contributor

@ast2023 ast2023 commented Nov 28, 2023

What changed?

Reimplemented unit-tests for nextBackoffInterval

Why?

original tests descirption and functionality did not match, it what hard to say what it was testing. This is the best readability approach I could think of today. I tried table based approach, but I think it was less readable because call to the function under test was hidden.

How did you test it?

run tests

Potential risks

some edge cases were not covered by tests

Is hotfix candidate?

No

@ast2023 ast2023 requested a review from a team as a code owner November 28, 2023 02:18
})
}

func doNotCare[T any](x T) T { return x }
Copy link
Contributor

Choose a reason for hiding this comment

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

At first I was a bit confused; but I really like this! If we were using a property-based testing tool, this could be a randomly generated value.

Copy link
Contributor

@alexshtin alexshtin Nov 30, 2023

Choose a reason for hiding this comment

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

func (tv *TestVars) Any() string {

Copy link
Contributor

Choose a reason for hiding this comment

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

It shouldn't be in functional tests package but in some common test helpers package.

Copy link
Contributor

Choose a reason for hiding this comment

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

And it needs to have Any for every type. I am going to improve that testvars package and will use it here too. One day.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately, I can't use Any(). There are some invariants that should hold for the values which I marked with doNotCare. At the same time, I want the reader to easily distinguish between values which can be changed without causing the test fail and the values which are important to the test success. Hope this makes sense.

Copy link
Contributor

@tdeebswihart tdeebswihart left a comment

Choose a reason for hiding this comment

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

I vastly prefer how you structured these tests, thank you! I'm a big fan of test names that state the property being checked

}

func Test_NextRetry(t *testing.T) {
a := assert.New(t)
Copy link
Contributor

Choose a reason for hiding this comment

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

This was bad approach!

@ast2023 ast2023 enabled auto-merge (squash) November 30, 2023 01:33
@ast2023 ast2023 merged commit bbb5b2d into main Nov 30, 2023
@ast2023 ast2023 deleted the sasha/OSS-361 branch November 30, 2023 03:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants