Skip to content

Add unit tests for registering a codec #8244

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

isaiahvita
Copy link

@isaiahvita isaiahvita commented Apr 13, 2025

The existing unit tests do not test the ability to test registering a codec via encoding.RegisterCodecV2.
This PR checks that the existing behavior thats currently implemented in the function will continue to work as it currently does.
Additionally, this brings the coverage report of encoding_v2.go from 75% to 100%.

I tested this by running the unit test and seeing it pass.

RELEASE NOTES: None

Copy link

linux-foundation-easycla bot commented Apr 13, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: isaiahvita / name: Isaiah Vita (380623c)

Copy link

codecov bot commented Apr 13, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 82.16%. Comparing base (54e7e26) to head (380623c).
Report is 11 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #8244      +/-   ##
==========================================
+ Coverage   82.05%   82.16%   +0.11%     
==========================================
  Files         412      412              
  Lines       40477    40477              
==========================================
+ Hits        33213    33258      +45     
+ Misses       5896     5854      -42     
+ Partials     1368     1365       -3     

see 20 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@purnesh42H purnesh42H self-requested a review April 15, 2025 07:26
@purnesh42H purnesh42H self-assigned this Apr 15, 2025
@purnesh42H purnesh42H added the Area: RPC Features Includes Compression, Encoding, Attributes/Metadata, Interceptors. label Apr 15, 2025
@isaiahvita isaiahvita force-pushed the isaiahvita-encoding-tests branch 2 times, most recently from df01452 to d1cc013 Compare April 16, 2025 12:56
// 1. invalid codecs (nil, empty name) should panic
// 2. same name codecs are valid, they just overwrite previous.
func TestRegisterCodec(t *testing.T) {
cases := map[string]struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

you can do something like this instead of having a map

tests := []struct {
		name          string
		origCodec  encoding.CodecV2
		newCodec  encoding.CodecV2
		wantPanic bool
	}

Copy link
Contributor

Choose a reason for hiding this comment

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

example to refer

tests := []struct {

if !reflect.DeepEqual(c.codec1, actualCodec) {
t.Errorf("[%v] Expected returned codec to be equal.\n", caseName)
}
if c.codec2 == nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

it looks like we have too many conditions in one test. may be should separate the tests into valid and invalid codec cases? For invalid, we just need one codec then.

Copy link
Author

@isaiahvita isaiahvita Apr 20, 2025

Choose a reason for hiding this comment

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

hmm im not sure i agree with that. separating into two different tests would only allow the defer to be in its own test, and then well have to duplicate the other equality conditions in both tests.

let me add some comments to make it more readable, and let me know what you think about that. if you still would like to have two separate tests, then i can change it.

Copy link
Contributor

Choose a reason for hiding this comment

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

I still think we should have separate test case for failures because there is lot of code which is not applicable to success cases. It is a good enough reason to make a separate test.

@purnesh42H purnesh42H assigned isaiahvita and unassigned purnesh42H Apr 17, 2025
@purnesh42H purnesh42H added this to the 1.73 Release milestone Apr 17, 2025
@isaiahvita isaiahvita force-pushed the isaiahvita-encoding-tests branch 2 times, most recently from 1cad815 to b87ad50 Compare April 20, 2025 22:43
return m.CodecName
}

// TestRegisterCodecV2 tests the existing behavioral assumptions made by
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// TestRegisterCodecV2 tests the existing behavioral assumptions made by
// TestRegisterCodecV2 tests verify the following behaviors of RegisterCodeV2:
- invalid codecs (nil, empty name) should panic
- if new codecs has same name as existing, existing codec is overwritten
- if codec with same name does not exist, it is registered

expectPanic bool
}{
{
name: "nil codes, panic",
Copy link
Contributor

Choose a reason for hiding this comment

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

typo: nil codecs, panics

func TestRegisterCodecV2(t *testing.T) {
tests := []struct {
name string
codec1 encoding.CodecV2
Copy link
Contributor

Choose a reason for hiding this comment

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

might be good to name codec1 and codec2 as existingCodec and newCodec or add a comment against them

@purnesh42H
Copy link
Contributor

2 more things to keep in mind for future reference

  1. Please do not force-push. Add a new commit for any change after review
  2. Please do not resolve the comments. Reviewers can resolve comments once they are addressed to expectation. You can respond to the comments stating how you have addressed them.

Copy link

github-actions bot commented May 4, 2025

This PR is labeled as requiring an update from the reporter, and no update has been received after 6 days. If no update is provided in the next 7 days, this issue will be automatically closed.

@github-actions github-actions bot added the stale label May 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: RPC Features Includes Compression, Encoding, Attributes/Metadata, Interceptors. stale Status: Requires Reporter Clarification Type: Testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants