Skip to content
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

alts: Perform full handshake in ALTS tests. #6177

Merged
merged 10 commits into from
Apr 10, 2023

Conversation

matthewstevenson88
Copy link
Contributor

@matthewstevenson88 matthewstevenson88 commented Apr 6, 2023

The ALTS tests in this repo do not perform full ALTS handshakes against a fake handshaker service. This leads to changes in this repo breaking e2e/interop tests once the change is imported internally. This PR will (hopefully) reduce the frequency with which that happens.

RELEASE NOTES: none

@matthewstevenson88 matthewstevenson88 marked this pull request as ready for review April 6, 2023 22:34

// Close closes all open connections to the handshaker service.
//
// For testing purposes only.
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems like a generic close function. Why is it expected to be used in tests only?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In practice, the connection to the handshaker service is kept open until the application is killed, so this Close function is never needed/called.

However, in the e2e test, we need to do call this Close function so that we don't get a goroutine leak.

Copy link
Contributor

Choose a reason for hiding this comment

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

Why can't you explicitly close the connection from the test?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Disclaimer: I'm not a Go expert so apologies if I'm missing something obvious. :)

The hsConnMap, which holds the connection, is not exported. So we have 2 options:

  1. Add a test-only Close API to close any connections in the map, which we call in TestFullHandshake.
  2. Call Dial to get the same connection and then manually close it. This feels hacky, because we never want users to call Dial (it should only be called by the internals of the ALTS libraries) and so I didn't want to set this precedent).

WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for the exaplaination. How about calling the method CloseForTesting or something which makes is very obvious that the method is only for testing purposes. We do that regularly in our codebase. Thanks.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure thing, done.

@matthewstevenson88
Copy link
Contributor Author

@easwars Would you be able to review from the gRPC side?

There are no functional changes in this PR, just adding another test (to hopefully reduce the cycle of "merge PR, import PR, see failure, revert PR", as happened with #6077).

@easwars easwars self-assigned this Apr 6, 2023
@easwars easwars added this to the 1.55 Release milestone Apr 6, 2023
credentials/alts/alts_test.go Show resolved Hide resolved
credentials/alts/alts_test.go Outdated Show resolved Hide resolved
credentials/alts/alts_test.go Outdated Show resolved Hide resolved
credentials/alts/alts_test.go Outdated Show resolved Hide resolved
credentials/alts/alts_test.go Outdated Show resolved Hide resolved
credentials/alts/alts_test.go Outdated Show resolved Hide resolved
credentials/alts/alts_test.go Show resolved Hide resolved

// Close closes all open connections to the handshaker service.
//
// For testing purposes only.
Copy link
Contributor

Choose a reason for hiding this comment

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

Why can't you explicitly close the connection from the test?

credentials/alts/internal/testutil/testutil.go Outdated Show resolved Hide resolved
credentials/alts/internal/testutil/testutil.go Outdated Show resolved Hide resolved
t.Fatalf("LocalTCPListener() failed: %v", err)
}
s := grpc.NewServer()
altspb.RegisterHandshakerServiceServer(s, &testutil.FakeHandshaker{})
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be altsgrpc with a separate import.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, sorry I missed this one. :)


// Close closes all open connections to the handshaker service.
//
// For testing purposes only.
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for the exaplaination. How about calling the method CloseForTesting or something which makes is very obvious that the method is only for testing purposes. We do that regularly in our codebase. Thanks.

credentials/alts/internal/testutil/testutil.go Outdated Show resolved Hide resolved
@easwars easwars removed their assignment Apr 7, 2023
@easwars
Copy link
Contributor

easwars commented Apr 7, 2023

One of the tests is failing because of a flake which we recently fixed. I've kicked off another run of the tests. If it fails again, maybe rebase your branch to master.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 8, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants