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

Added tests for the go/trace package #15052

Merged
merged 1 commit into from
Feb 13, 2024

Conversation

VaibhavMalik4187
Copy link
Contributor

Description

Increases the code coverage of the trace package to >42%.

Related Issue(s)

#14931

Checklist

  • "Backport to:" labels have been added if this change should be back-ported to release branches
  • If this change is to be back-ported to previous releases, a justification is included in the PR description
  • Tests were added or are not required
  • Did the new or modified tests pass consistently locally and on CI?
  • Documentation was added or is not required

Copy link
Contributor

vitess-bot bot commented Jan 27, 2024

Review Checklist

Hello reviewers! 👋 Please follow this checklist when reviewing this Pull Request.

General

  • Ensure that the Pull Request has a descriptive title.
  • Ensure there is a link to an issue (except for internal cleanup and flaky test fixes), new features should have an RFC that documents use cases and test cases.

Tests

  • Bug fixes should have at least one unit or end-to-end test, enhancement and new features should have a sufficient number of tests.

Documentation

  • Apply the release notes (needs details) label if users need to know about this change.
  • New features should be documented.
  • There should be some code comments as to why things are implemented the way they are.
  • There should be a comment at the top of each new or modified test to explain what the test does.

New flags

  • Is this flag really necessary?
  • Flag names must be clear and intuitive, use dashes (-), and have a clear help text.

If a workflow is added or modified:

  • Each item in Jobs should be named in order to mark it as required.
  • If the workflow needs to be marked as required, the maintainer team must be notified.

Backward compatibility

  • Protobuf changes should be wire-compatible.
  • Changes to _vt tables and RPCs need to be backward compatible.
  • RPC changes should be compatible with vitess-operator
  • If a flag is removed, then it should also be removed from vitess-operator and arewefastyet, if used there.
  • vtctl command output order should be stable and awk-able.

@vitess-bot vitess-bot bot added NeedsBackportReason If backport labels have been applied to a PR, a justification is required NeedsDescriptionUpdate The description is not clear or comprehensive enough, and needs work NeedsIssue A linked issue is missing for this Pull Request NeedsWebsiteDocsUpdate What it says labels Jan 27, 2024
@github-actions github-actions bot added this to the v19.0.0 milestone Jan 27, 2024
Copy link

codecov bot commented Jan 27, 2024

Codecov Report

Attention: 415 lines in your changes are missing coverage. Please review.

Comparison is base (eddb39e) 47.29% compared to head (c898b5b) 47.74%.
Report is 117 commits behind head on main.

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

Files Patch % Lines
go/vt/mysqlctl/builtinbackupengine.go 12.85% 61 Missing ⚠️
go/vt/vtgate/evalengine/cached_size.go 0.00% 41 Missing ⚠️
go/vt/vtctl/workflow/traffic_switcher.go 0.00% 25 Missing ⚠️
go/vt/vtgate/engine/delete_with_input.go 53.70% 23 Missing and 2 partials ⚠️
go/vt/mysqlctl/backupengine.go 0.00% 24 Missing ⚠️
go/vt/topo/keyspace.go 64.81% 14 Missing and 5 partials ⚠️
go/vt/vtgate/evalengine/expr_tuple_bvar.go 62.50% 14 Missing and 4 partials ⚠️
go/vt/mysqlctl/xtrabackupengine.go 0.00% 15 Missing ⚠️
go/vt/sqlparser/ast_funcs.go 42.30% 15 Missing ⚠️
go/vt/vtenv/cached_size.go 0.00% 14 Missing ⚠️
... and 42 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #15052      +/-   ##
==========================================
+ Coverage   47.29%   47.74%   +0.44%     
==========================================
  Files        1137     1155      +18     
  Lines      238684   240231    +1547     
==========================================
+ Hits       112895   114701    +1806     
+ Misses     117168   116926     -242     
+ Partials     8621     8604      -17     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@GuptaManan100 GuptaManan100 left a comment

Choose a reason for hiding this comment

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

The tests that have been added are failing when running with -race flag. We need to fix this before we can merge the PR, since the CI action unit_race will continue to fail otherwise.

@GuptaManan100 GuptaManan100 added Type: Testing Component: General Changes throughout the code base and removed NeedsDescriptionUpdate The description is not clear or comprehensive enough, and needs work NeedsWebsiteDocsUpdate What it says NeedsIssue A linked issue is missing for this Pull Request NeedsBackportReason If backport labels have been applied to a PR, a justification is required labels Jan 28, 2024
@VaibhavMalik4187 VaibhavMalik4187 force-pushed the trace-tests branch 7 times, most recently from f0dd97e to c898b5b Compare January 30, 2024 10:30
@VaibhavMalik4187
Copy link
Contributor Author

The tests that have been added are failing when running with -race flag. We need to fix this before we can merge the PR, since the CI action unit_race will continue to fail otherwise.

Fixed it.

@frouioui frouioui modified the milestones: v19.0.0, v20.0.0 Feb 6, 2024
Comment on lines 28 to 54
logger := traceLogger{}

// Redirect stderr to a buffer
rescueStderr := os.Stderr
r, w, _ := os.Pipe()
os.Stderr = w

want := "This is an error message"
logger.Error(want)

w.Close()
got, _ := io.ReadAll(r)
os.Stderr = rescueStderr

assert.Contains(t, string(got), want)

r, w, _ = os.Pipe()
os.Stderr = w

want = "This is an log message"
logger.Log(want)

w.Close()
got, _ = io.ReadAll(r)
os.Stderr = rescueStderr

assert.Contains(t, string(got), want)
Copy link
Member

Choose a reason for hiding this comment

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

Instead of having such a long function, it is better to make test cases, that will make the setup code a lot smaller, since it will be shared. Also the test is far more readable this way, since the expecatation and the parameters are listed together.

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. Thanks for the advice.

Comment on lines 33 to 36
func TestDdCloser(t *testing.T) {
dc := ddCloser{}
require.NoError(t, dc.Close())
}
Copy link
Member

Choose a reason for hiding this comment

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

This test isn't useful

logFunc := LogErrorsWhenClosing(&fakeCloser{})

// Redirect stderr to a buffer
rescueStderr := os.Stderr
Copy link
Member

Choose a reason for hiding this comment

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

Instead of setting os.Stderr back to rescueStderr, just do it once in a defer call.

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 time, I created a helper function for this task and used t.Cleanup to reset the original values.

Copy link
Member

@GuptaManan100 GuptaManan100 left a comment

Choose a reason for hiding this comment

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

LGTM now

@harshit-gangal harshit-gangal merged commit b28fd5e into vitessio:main Feb 13, 2024
100 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: General Changes throughout the code base Type: Testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants