Skip to content

alts: Perform full handshake in ALTS tests.#6177

Merged
easwars merged 10 commits intogrpc:masterfrom
matthewstevenson88:alts-full-handshake
Apr 10, 2023
Merged

alts: Perform full handshake in ALTS tests.#6177
easwars merged 10 commits intogrpc:masterfrom
matthewstevenson88:alts-full-handshake

Conversation

@matthewstevenson88
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Comment thread credentials/alts/alts_test.go
Comment thread credentials/alts/alts_test.go Outdated
Comment thread credentials/alts/alts_test.go Outdated
Comment thread credentials/alts/alts_test.go Outdated
Comment thread credentials/alts/alts_test.go Outdated
Comment thread credentials/alts/alts_test.go Outdated
Comment thread credentials/alts/alts_test.go

// Close closes all open connections to the handshaker service.
//
// For testing purposes only.
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.

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

Comment thread credentials/alts/internal/testutil/testutil.go Outdated
Comment thread credentials/alts/internal/testutil/testutil.go Outdated
Comment thread credentials/alts/alts_test.go Outdated
t.Fatalf("LocalTCPListener() failed: %v", err)
}
s := grpc.NewServer()
altspb.RegisterHandshakerServiceServer(s, &testutil.FakeHandshaker{})
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.

This should be altsgrpc with a separate import.

Copy link
Copy Markdown
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
Copy Markdown
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.

Comment thread credentials/alts/internal/testutil/testutil.go Outdated
@easwars easwars removed their assignment Apr 7, 2023
@easwars
Copy link
Copy Markdown
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