Skip to content

Conversation

@vasilevp
Copy link
Contributor

@vasilevp vasilevp commented Mar 1, 2021

No description provided.

@vasilevp vasilevp changed the title Add long-running test cases Add long-running test cases & implement slice merge for ReplicationSpecs Mar 1, 2021
@vasilevp vasilevp requested a review from antonlisovenko March 1, 2021 11:26
@vasilevp vasilevp self-assigned this Mar 1, 2021
@vasilevp vasilevp requested a review from leo-ri March 1, 2021 11:27
@vasilevp vasilevp marked this pull request as ready for review March 1, 2021 11:27
@matheusca
Copy link

Maybe this PR fixed error described here: #126

I think the problem it is, more attributes are being sent to the API during the cluster update and it is not necessary.

Copy link
Contributor

@antonlisovenko antonlisovenko left a comment

Choose a reason for hiding this comment

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

This looks great and the generic approach to slices is a good one (strong reflection 👍 )

I have some suggestions for unit and int tests - tell me what you think?

clusterMerged := mongodbatlas.Cluster{}
if err := compat.JSONCopy(&clusterMerged, cluster); err != nil {
return false, err
func cleanupCluster(cluster mongodbatlas.Cluster) mongodbatlas.Cluster {
Copy link
Contributor

Choose a reason for hiding this comment

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

[nit] can we add some comment about why we need to clean these fields?


if err := compat.JSONCopy(&clusterMerged, spec); err != nil {
return false, err
// TODO: might need to do this with other slices
Copy link
Contributor

Choose a reason for hiding this comment

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

can we file a ticket for this? Seems like we need to cover all slices with tests...


// merge common elements
for i := 0; i < minLen; i++ {
dstX := dstVal.Index(i).Addr().Interface()
Copy link
Contributor

Choose a reason for hiding this comment

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

[q] am I right that this will work only if the items of the slice are pointers as well? (looking at the tests below seems only the destination slice must have pointers?)
If so - may need to add to the method documentation

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They don't have to be pointers - I used pointers in the test case just to check that pointers work too

. "github.com/mongodb/mongodb-atlas-kubernetes/pkg/util/compat"
)

func TestJSONSliceMerge(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Great to have the unit test!
Do you think we can add the use cases:

  • when the src has smaller size than the dst?
  • the src is empty/nil
  • the dst is empty/nil

checkAtlasState()
})

By("Increasing DiskSizeGB", func() {
Copy link
Contributor

Choose a reason for hiding this comment

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

[q] do you think we need the separate test for increasing DiscSize if we have the one decreasing it? https://github.com/mongodb/mongodb-atlas-kubernetes/blob/2ba4112c78a3257973e5c01dcaeb95ad8569fcf3/test/int/cluster_test.go#L189-L188

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This one takes a lot of time due to disk provisioning, so I decided against including it in the "main" test suite

Copy link
Contributor

Choose a reason for hiding this comment

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

as discussed p2p it may make more sense to cover something different (like providerSettings.instanceSizeName or whatever) as DiscSize is already covered in the other testcase)

lastGeneration++
}

Describe("Create cluster & change ReplicationSpecs", func() {
Copy link
Contributor

@antonlisovenko antonlisovenko Mar 1, 2021

Choose a reason for hiding this comment

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

What do you think about adding another a bit more complicated use case and specifying two different regions for one replicationSpec (and some configuration for analytics/read-only nodes)?

The current use-case is nice as it covers our merging logic (take the things from Atlas and merge ours on top of the default ones) though we don't have the coverage for more complicated scenario when the user spreads their cluster over regions)

@vasilevp
Copy link
Contributor Author

vasilevp commented Mar 1, 2021

@matheusca

Maybe this PR fixed error described here: #126

I think the problem it is, more attributes are being sent to the API during the cluster update and it is not necessary.

I doubt this PR will fix the issue right away - but it's the necessary first step to support this specific use case, among many others.

@vasilevp vasilevp requested a review from antonlisovenko March 5, 2021 16:03
Copy link
Contributor

@antonlisovenko antonlisovenko left a comment

Choose a reason for hiding this comment

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

Thanks for addressing the comments and happy to have good coverage of replicationSpecs!

There's another ticket for global clusters - I think we can test them later.

Well done 👍

By("Change cluster to GEOSHARDED", func() {
createdCluster.Spec.ClusterType = "GEOSHARDED"
createdCluster.Spec.ProviderSettings.RegionName = ""
createdCluster.Spec.ReplicationSpecs = []mdbv1.ReplicationSpec{
Copy link
Contributor

Choose a reason for hiding this comment

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

[q] does this deploy 3 nodes in east_us and 0 - in west_us?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right - should I change it to 2/1 instead of 3/0?

Copy link
Contributor

Choose a reason for hiding this comment

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

yes, 2/1 looks good to me
What do you think if we add 1 readonly/analytics node to some region?

@vasilevp vasilevp merged commit 7aa9667 into main Mar 10, 2021
@vasilevp vasilevp deleted the CLOUDP-81631-complicated-tests branch March 10, 2021 15:12
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.

4 participants