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

add support for list network area and test (#381) #387

Merged
merged 12 commits into from
Oct 31, 2024

Conversation

larrytamnjong
Copy link
Contributor

No description provided.

@larrytamnjong
Copy link
Contributor Author

@marcin-krystianc

public async Task Operator_AreaList()
{
var req = await _client.Operator.AreaList();
Assert.NotNull(req.Response);
Copy link
Contributor

Choose a reason for hiding this comment

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

To make this test more exhaustive, it would be nice to create an area first and then assert that the query result is non-empty (instead of not null).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, done ✅

Copy link
Contributor

Choose a reason for hiding this comment

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

Pleas also updated the test condition, from not null to non-empty. Please inspect also a result fields if they are filled in.

Copy link
Contributor

@marcin-krystianc marcin-krystianc left a comment

Choose a reason for hiding this comment

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

The test are failing now with:

Consul.Test.OperatorTest.Operator_CreateArea: Consul.ConsulRequestException : Unexpected response, status code InternalServerError: area "d0c9af6b-363b-69b3-a1a9-50089871df13" with peer datacenter "dc2" already exists
            Assert.NotNull(response.Response);	            Assert.NotNull(response.Response);
        }	        }
        [EnterpriseOnlyFact]
        public async Task Operator_AreaList()
        {
            await _client.Operator.CreateArea(new AreaRequest { PeerDatacenter = "dc2", UseTLS = false, RetryJoin = null });

            var req = await _client.Operator.AreaList();
            Assert.NotNull(req.Response);
Member
@[marcin-krystianc](https://github.com/marcin-krystianc) marcin-krystianc 3 hours ago
To make this test more exhaustive, it would be nice to create an area first and then assert that the query result is non-empty (instead of not null).

Contributor
Author
@[larrytamnjong](https://github.com/larrytamnjong) larrytamnjong 29 minutes ago
Thanks, done ✅

Member
@[marcin-krystianc](https://github.com/marcin-krystianc) marcin-krystianc now
Pleas also updated the test condition, from not null to non-empty. Please inspect also a result fields if they are filled in.

@marcin-krystianc	Reply...
        }
    }	    }
}	}

Maybe try using a random name every time you create an area.

@larrytamnjong
Copy link
Contributor Author

The test are failing now with:

Consul.Test.OperatorTest.Operator_CreateArea: Consul.ConsulRequestException : Unexpected response, status code InternalServerError: area "d0c9af6b-363b-69b3-a1a9-50089871df13" with peer datacenter "dc2" already exists
            Assert.NotNull(response.Response);	            Assert.NotNull(response.Response);
        }	        }
        [EnterpriseOnlyFact]
        public async Task Operator_AreaList()
        {
            await _client.Operator.CreateArea(new AreaRequest { PeerDatacenter = "dc2", UseTLS = false, RetryJoin = null });

            var req = await _client.Operator.AreaList();
            Assert.NotNull(req.Response);
Member
@[marcin-krystianc](https://github.com/marcin-krystianc) marcin-krystianc 3 hours ago
To make this test more exhaustive, it would be nice to create an area first and then assert that the query result is non-empty (instead of not null).

Contributor
Author
@[larrytamnjong](https://github.com/larrytamnjong) larrytamnjong 29 minutes ago
Thanks, done ✅

Member
@[marcin-krystianc](https://github.com/marcin-krystianc) marcin-krystianc now
Pleas also updated the test condition, from not null to non-empty. Please inspect also a result fields if they are filled in.

@marcin-krystianc	Reply...
        }
    }	    }
}	}

Maybe try using a random name every time you create an area.

Thanks, @marcin-krystianc your right the error occurred because I tried adding an operator area with the name "dc2," which was already created during the "create operator area" test. I’ve fixed that issue now. Hopefully, it's okay now.

@marcin-krystianc
Copy link
Contributor

The test are failing now with:

Consul.Test.OperatorTest.Operator_CreateArea: Consul.ConsulRequestException : Unexpected response, status code InternalServerError: area "d0c9af6b-363b-69b3-a1a9-50089871df13" with peer datacenter "dc2" already exists
            Assert.NotNull(response.Response);	            Assert.NotNull(response.Response);
        }	        }
        [EnterpriseOnlyFact]
        public async Task Operator_AreaList()
        {
            await _client.Operator.CreateArea(new AreaRequest { PeerDatacenter = "dc2", UseTLS = false, RetryJoin = null });

            var req = await _client.Operator.AreaList();
            Assert.NotNull(req.Response);
Member
@[marcin-krystianc](https://github.com/marcin-krystianc) marcin-krystianc 3 hours ago
To make this test more exhaustive, it would be nice to create an area first and then assert that the query result is non-empty (instead of not null).

Contributor
Author
@[larrytamnjong](https://github.com/larrytamnjong) larrytamnjong 29 minutes ago
Thanks, done ✅

Member
@[marcin-krystianc](https://github.com/marcin-krystianc) marcin-krystianc now
Pleas also updated the test condition, from not null to non-empty. Please inspect also a result fields if they are filled in.

@marcin-krystianc	Reply...
        }
    }	    }
}	}

Maybe try using a random name every time you create an area.

Thanks, @marcin-krystianc your right the error occurred because I tried adding an operator area with the name "dc2," which was already created during the "create operator area" test. I’ve fixed that issue now. Hopefully, it's okay.

Using fixed name is not ideal, I guess it is impossible to run that test twice in a row? The test should be implemented in a way, that makes it possible to run it multiple times without any issue.

@larrytamnjong
Copy link
Contributor Author

The test are failing now with:

Consul.Test.OperatorTest.Operator_CreateArea: Consul.ConsulRequestException : Unexpected response, status code InternalServerError: area "d0c9af6b-363b-69b3-a1a9-50089871df13" with peer datacenter "dc2" already exists
            Assert.NotNull(response.Response);	            Assert.NotNull(response.Response);
        }	        }
        [EnterpriseOnlyFact]
        public async Task Operator_AreaList()
        {
            await _client.Operator.CreateArea(new AreaRequest { PeerDatacenter = "dc2", UseTLS = false, RetryJoin = null });

            var req = await _client.Operator.AreaList();
            Assert.NotNull(req.Response);
Member
@[marcin-krystianc](https://github.com/marcin-krystianc) marcin-krystianc 3 hours ago
To make this test more exhaustive, it would be nice to create an area first and then assert that the query result is non-empty (instead of not null).

Contributor
Author
@[larrytamnjong](https://github.com/larrytamnjong) larrytamnjong 29 minutes ago
Thanks, done ✅

Member
@[marcin-krystianc](https://github.com/marcin-krystianc) marcin-krystianc now
Pleas also updated the test condition, from not null to non-empty. Please inspect also a result fields if they are filled in.

@marcin-krystianc	Reply...
        }
    }	    }
}	}

Maybe try using a random name every time you create an area.

Thanks, @marcin-krystianc your right the error occurred because I tried adding an operator area with the name "dc2," which was already created during the "create operator area" test. I’ve fixed that issue now. Hopefully, it's okay.

Using fixed name is not ideal, I guess it is impossible to run that test twice in a row? The test should be implemented in a way, that makes it possible to run it multiple times without any issue.

Thanks, @marcin-krystianc, and apologies for the back-and-forth. I’ve added a method to generate a random dc name for each test run. The tests are still in queue. Let me know if this approach works or if there's anything else you'd like me to adjust.

internal static string GeneratePeerDatacenterName()
{
int randomNumber = Random.Next(100, 1000);
return $"ran-dc-{randomNumber}";
Copy link
Contributor

Choose a reason for hiding this comment

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

Single random number might be not enough to prevent from conflicts/duplicates. We've already a method KVTest.GenerateTestKeyName() which is being used in many places in tests already. It generates 16 character long random string. Please use it instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@marcin-krystianc thanks, you can take another look now.

Consul.Test/OperatorTest.cs Outdated Show resolved Hide resolved
await _client.Operator.CreateArea(new AreaRequest { PeerDatacenter = peerDataCenter, UseTLS = false, RetryJoin = null });

var req = await _client.Operator.AreaList();
Assert.NotEmpty(req.Response);
Copy link
Contributor

Choose a reason for hiding this comment

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

Just one more thing, can we test if the fields in the response are not null?
So far we know that we can create and list areas, but it would be great if we assert that the values returned by the list operation correspond to the values used in the create operation.

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you also try filling the RetryJoin field and then validating the content of it when returned?

Consul/Interfaces/IOperatorEndpoint.cs Show resolved Hide resolved

var req = await _client.Operator.AreaList();
Assert.NotEmpty(req.Response);
Assert.Equal(area.PeerDatacenter, req.Response.First().PeerDatacenter);
Copy link
Contributor

Choose a reason for hiding this comment

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

There can be multiple items in the result list, so the first one is not necessarily the one we are looking for. You need to look for the right one, e.g.:

var result = req.Response.Single(x => x.PeerDatacenter == area.peerDataCenter);
Assert.Equal(area.UseTLS, result.UseTLS);
Assert.Equal(area.RetryJoin, result.RetryJoin);  

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@marcin-krystianc I'm not sure if testing RetryJoin is sufficient with this approach Assert.Equal(area.RetryJoin, result.RetryJoin);
or if it would be better to test each element individually in the array, like this: for (int i = 0; i < retryJoinAddresses.Length; i++) { Assert.Equal(retryJoinAddresses[i], createdArea.RetryJoin[i]); }

Copy link
Contributor

Choose a reason for hiding this comment

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

@marcin-krystianc I'm not sure if testing RetryJoin is sufficient with this approach Assert.Equal(area.RetryJoin, result.RetryJoin); or if it would be better to test each element individually in the array, like this: for (int i = 0; i < retryJoinAddresses.Length; i++) { Assert.Equal(retryJoinAddresses[i], createdArea.RetryJoin[i]); }

There is an overload for IEnumerable:

    public static void Equal<T>(
      IEnumerable<T> expected,
      IEnumerable<T> actual,
      IEqualityComparer<T> comparer)

so I guess it will do the right thing.
You can try to define manually two lists and see how it reacts to different item order in both lists.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

image
Tests 1 and 3 are passing, but test 2 is failing so its ok. I have pushed the changes please let me know if there's anything else to change.

Copy link
Contributor

@marcin-krystianc marcin-krystianc left a comment

Choose a reason for hiding this comment

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

It's perfect now 👍

@marcin-krystianc marcin-krystianc merged commit 18ba35f into G-Research:master Oct 31, 2024
243 checks passed
@larrytamnjong larrytamnjong deleted the list-network-areas branch October 31, 2024 11:27
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