-
Notifications
You must be signed in to change notification settings - Fork 179
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
chore: Reuses projects in executions in some resources and rename mig tests #2007
Conversation
e89be08
to
c45b2e2
Compare
) | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
resource.Test(t, resource.TestCase{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this intentional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it is based on the lines below :) maybe I missed it in the description but I am not understanding why we are not making it parallel anymore
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My understanding is that before, each test was creating a project, so now that the different tests use the same one, the tests will fail if run in parallel
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, I changed alert_configuration and database_user test to be serial on purpose. The reason is that they are resources common to the project.
For instance one test for alert_configuration plural datasource creates 2 alerts and ask if there are two, it will fail if other tests are creating others.
alert_notification creates like 20 projects and each one takes only like 5 seconds, so now they will create only 1 project and will take 2 minutes to run all.
however tests than don't change common project elements (which are the most expensive to run like the ones using clusters) can continue working on parallel.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as an example in this PR, these resources are reusing projects and running in parallel:
cloud_backup_schedule
cloud_backup_snapshot
global_cluster_config
search_index
stream_connection
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
both alert_configuration and database_user are in "config" test group, in your link it takes 3m5s
in this PR it takes 2m42s.
Current times:
ok github.com/mongodb/terraform-provider-mongodbatlas/internal/service/databaseuser 37.419s
ok github.com/mongodb/terraform-provider-mongodbatlas/internal/service/alertconfiguration 56.755s
PR times:
ok github.com/mongodb/terraform-provider-mongodbatlas/internal/service/databaseuser 39.836s
ok github.com/mongodb/terraform-provider-mongodbatlas/internal/service/alertconfiguration 50.120s
So even in serial it takes less time now :-)
Most of time in your log is creating the project, that's why they take in the 20s.
Also notice that all packages/resources in a test group run in parallel in different processes, so serial tests in database_user are not serialized together with alert_notification, serial is only in each resource.
Neither of these two resources is in the critical path for config test group.
Anyway I'm going to try what @AgustinBettati said of only running serially the plural ds test, that should work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@marcosuma @andreaangiolillo after @AgustinBettati idea to run all in parallel except plural ds these are the new PR times 🎉
ok github.com/mongodb/terraform-provider-mongodbatlas/internal/service/databaseuser 23.636s
ok github.com/mongodb/terraform-provider-mongodbatlas/internal/service/alertconfiguration 33.800s
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok it actually did improve and your rationale seems right to me: avoiding creating the project all the times actually contributes to saving time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two follow-ups coming from this PR and conversation (not urgent, but worth a discussion):
- couldn't we also convert plural tests to be parallel by changing the expectations? (e.g. remove the "check number of alerts equal n" in favour of "check alert with 'this' and 'this' name exists)
- In n months (just random time in the future) when someone will see the code base and see some tests as running in parallel and some sequential, what do you think it could go wrong? Is there a risk that without proper clarification on the code base they might think it's an error and start investigating why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1 - yes, that is a good idea, let me think about it
2 - we already do have a mix of parallel and serial (before this PR). let me see 1 if we can do the ds plural serial so we minimize exceptions.
@@ -1,130 +1,54 @@ | |||
package acc | |||
|
|||
import ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason for not moving all these methods to the databaseuser_test
package? Seems like they are only used there
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no reason apart from trying to minimize the changes in this PR as it's getting very big. it's true that I moved checkExists and checkDestroy, I'll move all then, thx for the comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry at the end I think i'm not going to do this refactor in this PR as it's not related to the main topic of the PR and will increase changes still more
resource.ParallelTest(t, resource.TestCase{ | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { acc.PreCheckBasic(t) }, | ||
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories, | ||
CheckDestroy: checkDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: configWithThreshold(orgID, projectName, true, 1), | ||
Config: configWithThreshold(projectID, true, 1), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[q] taking this test as an example the terraform configuration is creating a single alert configuration and running a data source for that specific alert, could we preserve running this in parallel?
I would asume the only test cases that needs to be run sequentially are those that rely on asserting the plural data source, and effectively check a certain amount of resources. This also applies for database user tests that where adjusted from ParallelTest to Test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AgustinBettati great callout!!! i've changed and it worked
func TestMain(m *testing.M) { | ||
acc.SetupSharedResources() | ||
exitCode := m.Run() | ||
acc.CleanupSharedResources() | ||
os.Exit(exitCode) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
regarding where TestMain should be placed within the test package: I do not see a clear convention other than place the TestMain function wherever it makes the most sense
.
With this in mind I believe having a main_test.go
file (mentioned by @maastha) could be the most transparent option so it is clear the function impacts the entire test package. This is an example I found from the terraform repository: e2etest/main_test.go
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AgustinBettati @maastha ok, changed to their own main_test.go, also I like the idea of setup returning the cleanup function so cleanup doesn't need to be a public function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome!
@@ -14,6 +14,13 @@ import ( | |||
"go.mongodb.org/atlas-sdk/v20231115007/admin" | |||
) | |||
|
|||
func TestMain(m *testing.M) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR is really hard to review 😢 Just an FYI that people in cloud were discussing this interesting blog post The ideal PR is 50 lines long
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thx for the comment. Sorry, I know and I normally try to do small PRs. In this case I try to explain in the PR description why I chose to go for a bigger PR here.
internal/service/accesslistapikey/resource_access_list_api_key_migration_test.go
Show resolved
Hide resolved
resource.ParallelTest(t, resource.TestCase{ | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { acc.PreCheckBasic(t) }, | ||
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories, | ||
CheckDestroy: checkDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: configWithThreshold(orgID, projectName, true, 1), | ||
Config: configWithThreshold(projectID, true, 1), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
) | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
resource.Test(t, resource.TestCase{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It'd be great to show in the PR description the impact of running these tests sequentially vs in parallel: this info should be easy to get, just check the time needed to run the tests in this PR vs in the last nightly run
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as I commented to Marco the "config" test group that runs database_user and alert_notification is taking less time now than before even being in serial. anyway i'm going to follow Agustin idea of just running in serial the plural ds tests.
…oup/project or cluster
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks for the follow up adjustments
// It returns the cleanup function that must be called at the end of TestMain. | ||
func SetupSharedResources() func() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
like this approach of having the setup and cleanup coupled together to avoid any potential strange use case
I'm going to merge as I think the general idea is fine, if you have any comment about some specific area let me know and will address in a following PR. In that way we don't have to run all test groups because a change in a specific area. |
Description
Reuses projects in executions in some resources and rename mig tests.
NOTE: To minimize the use of test resources, multiple small changes across many files are done in this PR, as opposed to extend them through many PRs and having to run the test groups multiple times.
Link to any related issue(s): CLOUDP-237006
Type of change:
Required Checklist:
Further comments