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

Updating broker tests to cover some implicit cases #38

Merged
merged 5 commits into from
Sep 20, 2023

Conversation

denisonbarbosa
Copy link
Member

@denisonbarbosa denisonbarbosa commented Sep 15, 2023

The brokers.Manager has to manage multiple sessions and brokers at once and we were not testing that. This PR adds a couple of test cases to cover those scenarios, mainly:

  • Starting a session on the correct broker;
  • Ending a session on the correct broker;
  • Creating a new manager without autodiscovery if []configuredBrokers was set;

This also updates the broker tests to use a MockBroker per test family rather than creating a MockBroker per test case. This saves memory and speed whilst also providing a more "realistic" environment in which a Broker attends multiple calls.

UDENG-1329

Copy link
Member

@didrocks didrocks left a comment

Choose a reason for hiding this comment

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

So, I think there is one missing use case we discussed during our HO live and was quickly described in the previous PR for the tests: we need a test case when 2 complete transactions are in parallel, so that we are leverage the mutexes we are using (parallel testing is using different managers, and so, we don’t trigger those potential conflicts).

Do you mind adding this test masterpiece? (2 users, different brokers selected for each one).

@denisonbarbosa
Copy link
Member Author

denisonbarbosa commented Sep 19, 2023

So, I think there is one missing use case we discussed during our HO live and was quickly described in the previous PR for the tests: we need a test case when 2 complete transactions are in parallel, so that we are leverage the mutexes we are using (parallel testing is using different managers, and so, we don’t trigger those potential conflicts).

Do you mind adding this test masterpiece? (2 users, different brokers selected for each one).

@didrocks, do we need to go through the "full stack" (i.e. start the session, get the authentication methods, select one and so on...) or just trying starting and ending a session is fine?

@didrocks
Copy link
Member

Do we need to go through the "full stack" or just trying starting and ending a session is fine?

As you wish, a full stack would be better, but the MVP is start/endsession and would be a good start already.

@denisonbarbosa
Copy link
Member Author

Do we need to go through the "full stack" or just trying starting and ending a session is fine?

As you wish, a full stack would be better, but the MVP is start/endsession and would be a good start already.

I also think that testing the start/end session through the manager is probably enough. If we are worried about the broker's ability to handle multiple calls (even though I doubt that after the PAM tests), we can maybe try using a broker per test family (on brokers_test.go) rather than one per test case. Wdyt?

@didrocks
Copy link
Member

didrocks commented Sep 19, 2023

we can maybe try using a broker per test family (on brokers_test.go) rather than one per test case. Wdyt?

Good suggestion, I think it’s valuable to have this. It doesn’t cover the other use case, but it’s valid too :)

@denisonbarbosa denisonbarbosa changed the title Test cases for dealing with multiple brokers Updating broker tests to cover some implicit cases Sep 19, 2023
Copy link
Member

@didrocks didrocks left a comment

Choose a reason for hiding this comment

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

2 small nitpicks and then we can merge!

Updating function signature to allow for creation of multiple brokers
per test case.
We were not testing some important scenarios of the brokers.Manager
(e.g. starting/ending session on the correct broker if multiple are
configured, not triggering autodiscovery when configuredBrokers != nil).

This commit adds test cases to cover those scenarios.
Before we were creating a MockBroker per test case, but this is not
necessary since the broker has sync mechanisms. Now, it's a broker per
test family, which uses less memory overall and is more useful from a
testing POV
To avoid having to harcode the expected values, it's better to extract
the session ID (and encryption key) generation "logic" to public
functions that we can use on tests.
This test purpose is to test concurrent calls to NewSession and
EndSession on the manager, using different brokers for different users.

It's very verbose on the assertions, but it's a well needed test.
Copy link
Member

@didrocks didrocks left a comment

Choose a reason for hiding this comment

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

All good now!

@denisonbarbosa denisonbarbosa merged commit 97495c0 into main Sep 20, 2023
3 checks passed
@denisonbarbosa denisonbarbosa deleted the multbrokers-manager-tests branch September 20, 2023 12:29
This pull request was closed.
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.

3 participants