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

cloud: Use static reference ID in tests #3061

Merged
merged 8 commits into from
May 11, 2023
Merged

Conversation

codebien
Copy link
Contributor

@codebien codebien commented May 8, 2023

The master's version mocks the test creation for all the tests doing them dependent on the resolution logic. The current PR removes this requirement and centralizes this assertion in a single test. Instead, all the other tests use a static-injected reference ID.

It should simplify the migration to something like the following architecture that I would do in #3041:

output/cloud/output.go: has the logic for the test creation and cleaning up (common logic)

  • output/cloud/v1/output.go has the old logic for metric collect/aggregate/flush
  • output/cloud/expv2/output.go has the new logic for metric collect/aggregate/flush

Applying the current PR would be easier to eventually divide the unit tests of the test creation from the unit tests for metrics collection/aggregation/flushing logic across different components in the next PRs.

@codebien codebien requested a review from na-- May 8, 2023 15:58
@codebien codebien self-assigned this May 8, 2023
@codebien codebien requested a review from olegbespalov May 8, 2023 15:59
@@ -545,21 +488,12 @@ func TestCloudOutputRequireScriptName(t *testing.T) {

func TestCloudOutputAggregationPeriodZeroNoBlock(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

I am actually struggling to understand how this test was useful and what it checked even before your changes... 😅 It originated from #1130, but I think it got progressively mangled with subsequent refactorings 😕 With your latest changes, I am not sure it test anything meaningful beyond the fact that we can start and stop the output, which should already be covered by other tests 😕

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've applied a basic fix by doing a simple push. I think the attempt here originally was to test the if AggregationPeriod is not set branch.

This test will not be used in v2 so I haven't applied any improvement. 8eb2506

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, but AggregationPeriod is not set by default, so presumably this is already covered by a bunch of tests, that's why I thought we can just get rid of it 😅 anyway, it will go away soon, so it doesn't really matter.

Copy link
Contributor

Choose a reason for hiding this comment

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

I am joining the @na-- with missing the point of the original test and new additions that this PR is bringing to it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed 24dfc4d

Copy link
Member

@na-- na-- left a comment

Choose a reason for hiding this comment

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

LGTM in general, though I think we can probably just move a lot of the current tests to v1/ as they are. A bunch of the tests are either not very high quality or are very specific to v1/ logic, so they can just be moved together with it and they can get discarded together with the v1/ logic.

@codecov-commenter
Copy link

codecov-commenter commented May 9, 2023

Codecov Report

Merging #3061 (ce97fff) into master (9e3359b) will decrease coverage by 0.31%.
The diff coverage is 40.00%.

❗ Current head ce97fff differs from pull request most recent head c2efd34. Consider uploading reports for the commit c2efd34 to get more accurate results

@@            Coverage Diff             @@
##           master    #3061      +/-   ##
==========================================
- Coverage   77.03%   76.73%   -0.31%     
==========================================
  Files         229      229              
  Lines       17108    17110       +2     
==========================================
- Hits        13180    13129      -51     
- Misses       3085     3137      +52     
- Partials      843      844       +1     
Flag Coverage Δ
ubuntu 76.73% <40.00%> (-0.31%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
output/cloud/metrics_client.go 80.00% <25.00%> (-4.62%) ⬇️
output/cloud/output.go 69.60% <100.00%> (-15.11%) ⬇️

... and 3 files with indirect coverage changes

@codebien
Copy link
Contributor Author

codebien commented May 9, 2023

I also applied the fixes for the linter, otherwise, we must fix them when we move the tests. It should be easier to review them here.

@codebien codebien requested a review from na-- May 9, 2023 16:39
@codebien
Copy link
Contributor Author

codebien commented May 9, 2023

I also removed opts lib.Options field because it seems not used at all. Let me know if it is unexpected and needs to cover with a dedicated unit test.

cloudapi/api_test.go Outdated Show resolved Hide resolved
Remove the dynamic resolution of the test' reference ID, and replaced it
with a static injected value.
It removes the dependency from all tests of the reference ID resolution.
We will have a dedicated test for this logic making easier to control
and have refactor around the cloud output.
na--
na-- previously approved these changes May 10, 2023
Copy link
Contributor

@olegbespalov olegbespalov left a comment

Choose a reason for hiding this comment

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

Generally looks good, left a few comments 👍

output/cloud/metrics_client.go Outdated Show resolved Hide resolved
output/cloud/output_test.go Show resolved Hide resolved
@@ -545,21 +488,12 @@ func TestCloudOutputRequireScriptName(t *testing.T) {

func TestCloudOutputAggregationPeriodZeroNoBlock(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.

I am joining the @na-- with missing the point of the original test and new additions that this PR is bringing to it.

output/cloud/output_test.go Outdated Show resolved Hide resolved
output/cloud/output_test.go Outdated Show resolved Hide resolved
It is mostly a useless test: because the SUT should be already covered by
other tests and we don't want to apply a refactor because
it will be not used for the new cloud output.
Removed the lib.Options field from the cloud because it is not used.
@codebien codebien merged commit c00bfbb into master May 11, 2023
@codebien codebien deleted the cloud/refactor/tests branch May 11, 2023 07:02
@olegbespalov olegbespalov added this to the v0.45.0 milestone May 11, 2023
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