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

fix MySQL panic test #996

Merged
merged 8 commits into from
Feb 19, 2021
Merged

fix MySQL panic test #996

merged 8 commits into from
Feb 19, 2021

Conversation

vankichi
Copy link
Contributor

@vankichi vankichi commented Feb 9, 2021

Fix the panic error of MySQL unit test.

Description:

I researched the panic error during the MySQL unit test.
This error may be caused by nil pointer of the session which is one of the MySQL client struct values.
My change is following:

  • added the nil check for each function that uses session.
  • added new error type for MySQL: ErrMySQLSessionNil
  • fix the code for using session mock.

I need the authors' review.

Related Issue:

How Has This Been Tested?:

Environment:

  • Go Version: 1.15.7
  • Docker Version: 19.03.8
  • Kubernetes Version: 1.18.2
  • NGT Version: 1.13.1

Types of changes:

  • Bug fix [type/bug]
  • New feature [type/feature]
  • Add tests [type/test]
  • Security related changes [type/security]
  • Add documents [type/documentation]
  • Refactoring [type/refactoring]
  • Update dependencies [type/dependency]
  • Update benchmarks and performances [type/bench]
  • Update CI [type/ci]

Changes to Core Features:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your core changes, as applicable?
  • Have you successfully ran tests with your changes locally?

Checklist:

  • I have read the CONTRIBUTING document.
  • I have checked open Pull Requests for the similar feature or fixes?
  • I have added tests and benchmarks to cover my changes.
  • I have ensured all new and existing tests passed.
  • I have commented my code, particularly in hard-to-understand areas
  • I have updated the documentation accordingly.

@vdaas-ci
Copy link
Collaborator

vdaas-ci commented Feb 9, 2021

[CHATOPS:HELP] ChatOps commands.

  • 🙆‍♀️ /approve - approve
  • 💌 /changelog - add changelog comment
  • 🍱 /format - format codes and add licenses
  • /gen-test - generate test codes
  • 🏷️ /label - add labels
  • /rebase - rebase master
  • 🔚 2️⃣ 🔚 /label actions/e2e-deploy - run E2E deploy & integration test

@@ -50,6 +50,11 @@ var (
ErrRequiredMemberNotFilled = func(member string) error {
return Wrapf(NewErrMySQLInvalidArgumentIdentity(), "error required member not filled (member: %s)", member)
}

// ErrMySQLSessionNil represents a function to generate an error that the MySQL session is nil.
ErrMySQLSessionNil = func() error {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this case you shouldn't use functional type for error, but if you add additional information such as below it's better

	db                   string
	host                 string
	port                 int
	user                 string
	pass                 string
	name                 string
	charset              string

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@kpango so, for example, should I implement the below code instead of this?

if m.session == nil {
  return errors.Errorf("session is nil, { db: %s, host: %s, port: %d, user: %s, pass: %s, name: %s, charset: %s", m.db, m.host, m.port, m.user, m.pass, m.name, m.charset)
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
ErrMySQLSessionNil = func() error {
ErrMySQLSessionNil = func(db, host, user, name, charset string, port int) error {
return errors.Errorf("session is nil, { db: %s, host: %s, port: %d, user: %s, name: %s, charset: %s", db, host, port, user, name, charset)

Copy link
Collaborator

Choose a reason for hiding this comment

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

or you can print them on debug log.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think debug log is easy.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@kpango thx for the review, I updated the code 🙏

internal/db/rdb/mysql/mysql_test.go Outdated Show resolved Hide resolved
internal/db/rdb/mysql/mysql_test.go Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Feb 9, 2021

Codecov Report

Merging #996 (fdf9a3a) into master (4bf65f8) will increase coverage by 0.12%.
The diff coverage is 95.34%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #996      +/-   ##
==========================================
+ Coverage   14.25%   14.37%   +0.12%     
==========================================
  Files         494      494              
  Lines       28294    28336      +42     
==========================================
+ Hits         4033     4073      +40     
- Misses      24012    24013       +1     
- Partials      249      250       +1     
Impacted Files Coverage Δ
internal/errors/mysql.go 100.00% <ø> (ø)
internal/db/rdb/mysql/mysql.go 94.46% <95.34%> (+0.15%) ⬆️
internal/worker/worker.go 82.29% <0.00%> (-1.05%) ⬇️
internal/worker/queue.go 100.00% <0.00%> (+1.66%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0351002...6473f03. Read the comment docs.

@vankichi vankichi changed the title [WIP] fix MySQL panic test fix MySQL panic test Feb 15, 2021
@vankichi vankichi marked this pull request as ready for review February 15, 2021 09:51
@vankichi
Copy link
Contributor Author

/rebase
/format

@vdaas-ci
Copy link
Collaborator

[REBASE] Rebase triggered by vankichi for branch: test/internal/fix-mysql-paniced-test

@vdaas-ci vdaas-ci force-pushed the test/internal/fix-mysql-paniced-test branch from 2550884 to ac6ee4e Compare February 15, 2021 09:52
@vankichi vankichi requested review from a team, kmrmt and hlts2 and removed request for a team February 15, 2021 09:53
@vdaas-ci
Copy link
Collaborator

[FORMAT] Updating license headers and formatting go codes triggered by vankichi.

@vankichi vankichi requested review from kevindiu and removed request for kmrmt February 15, 2021 09:54
@vankichi vankichi self-assigned this Feb 15, 2021
internal/db/rdb/mysql/mysql.go Outdated Show resolved Hide resolved
internal/db/rdb/mysql/mysql.go Outdated Show resolved Hide resolved
internal/db/rdb/mysql/mysql.go Outdated Show resolved Hide resolved
internal/db/rdb/mysql/mysql.go Outdated Show resolved Hide resolved
internal/db/rdb/mysql/mysql.go Outdated Show resolved Hide resolved
internal/db/rdb/mysql/mysql.go Outdated Show resolved Hide resolved
internal/db/rdb/mysql/mysql.go Outdated Show resolved Hide resolved
internal/db/rdb/mysql/mysql.go Outdated Show resolved Hide resolved
internal/db/rdb/mysql/mysql.go Outdated Show resolved Hide resolved
internal/db/rdb/mysql/mysql.go Show resolved Hide resolved
@kevindiu
Copy link
Contributor

@kevindiu
Copy link
Contributor

please also add author review required to the PR description :)

@kevindiu
Copy link
Contributor

/rebase
/format

@vdaas-ci
Copy link
Collaborator

[REBASE] Rebase triggered by kevindiu for branch: test/internal/fix-mysql-paniced-test

@vdaas-ci vdaas-ci force-pushed the test/internal/fix-mysql-paniced-test branch from 1fe0da9 to 2e13626 Compare February 19, 2021 05:02
@vdaas-ci
Copy link
Collaborator

[FORMAT] Updating license headers and formatting go codes triggered by kevindiu.

@vankichi
Copy link
Contributor Author

/rebase

@vdaas-ci
Copy link
Collaborator

[REBASE] Rebase triggered by vankichi for branch: test/internal/fix-mysql-paniced-test

@vankichi
Copy link
Contributor Author

/rebase
/format

@vdaas-ci
Copy link
Collaborator

[REBASE] Rebase triggered by vankichi for branch: test/internal/fix-mysql-paniced-test

@vdaas-ci vdaas-ci force-pushed the test/internal/fix-mysql-paniced-test branch from a84417f to 6473f03 Compare February 19, 2021 07:32
@vdaas-ci
Copy link
Collaborator

[FORMAT] Updating license headers and formatting go codes triggered by vankichi.

Copy link
Contributor

@kevindiu kevindiu left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Collaborator

@hlts2 hlts2 left a comment

Choose a reason for hiding this comment

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

thank you 🙇
LGTM

Copy link
Collaborator

@kpango kpango left a comment

Choose a reason for hiding this comment

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

LGTM

@kpango kpango merged commit 0ce53b6 into master Feb 19, 2021
@kpango kpango deleted the test/internal/fix-mysql-paniced-test branch February 19, 2021 08:04
@vdaas-ci vdaas-ci mentioned this pull request Feb 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants