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

expression: replace mock.Context with StaticExprContext in tests #53007

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

lcwangchao
Copy link
Collaborator

@lcwangchao lcwangchao commented Apr 30, 2024

What problem does this PR solve?

Issue Number: close #53006

Problem Summary:

After we introduced some static implements for EvalContext and ExprContext. It's better to replace mock.Context with StaticExprContext for the following reasons:

  • reduce the dependencies of expression
  • make the test easier to maintain without relying on a hug context

What changed and how does it work?

  • mock.NewContext is replaced with mockStmtExprCtx
  • createContext is replaced with mockStmtTruncateAsWarningExprCtx

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No need to test
    • I checked and no code files have been changed.

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

Please refer to Release Notes Language Style Guide to write a quality release note.

None

@ti-chi-bot ti-chi-bot bot added release-note-none size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Apr 30, 2024
Copy link

tiprow bot commented Apr 30, 2024

Hi @lcwangchao. Thanks for your PR.

PRs from untrusted users cannot be marked as trusted with /ok-to-test in this repo meaning untrusted PR authors can never trigger tests themselves. Collaborators can still trigger tests on the PR using /test all.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

pkg/expression/helper.go Outdated Show resolved Hide resolved
Copy link

codecov bot commented Apr 30, 2024

Codecov Report

Attention: Patch coverage is 80.00000% with 2 lines in your changes are missing coverage. Please review.

Project coverage is 74.5399%. Comparing base (4fe70da) to head (aea6a28).
Report is 38 commits behind head on master.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #53007        +/-   ##
================================================
+ Coverage   72.4796%   74.5399%   +2.0603%     
================================================
  Files          1493       1493                
  Lines        429362     429402        +40     
================================================
+ Hits         311200     320076      +8876     
+ Misses        98931      89419      -9512     
- Partials      19231      19907       +676     
Flag Coverage Δ
integration 49.2460% <40.0000%> (?)
unit 71.2597% <80.0000%> (-0.1192%) ⬇️

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

Components Coverage Δ
dumpling 53.9957% <ø> (ø)
parser ∅ <ø> (∅)
br 50.4684% <ø> (+9.0282%) ⬆️

@lcwangchao
Copy link
Collaborator Author

/retest

Comment on lines -75 to +76
if tp == mysql.TypeTimestamp || tp == mysql.TypeDatetime || tp == mysql.TypeDate {
err = value.ConvertTimeZone(time.Local, ctx.Location())
if err != nil {
return value, err
}
if err = value.ConvertTimeZone(defaultTime.Location(), ctx.Location()); err != nil {
return value, err
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is the only file that has some logic change:

  1. remove tp == mysql.TypeTimestamp || tp == mysql.TypeDatetime || tp == mysql.TypeDate because it seems useless. I check all the places that call getTimeCurrentTimeStamp. The tp is always time type. Only converting timezone for time types is also meaningless, so I removed it.

  2. Change the first argument of ConvertTimeZone from time.Local to defaultTime.Location() because this the practical meaning for this line. Because defaultTime is always in local time zone if it is get from session, it is also right for previous code. But the StaticEvalContext returns a current time with the same zone of the context, it's better to make a change.

PTAL @AilinKid

Copy link
Contributor

Choose a reason for hiding this comment

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

here lgtm

Copy link
Member

Choose a reason for hiding this comment

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

How about add a intest.Assert here?

(It's also fine to not add it, because IMO it's intuitive to call getTimeCurrentTimeStamp with time type.

pkg/expression/evaluator_test.go Outdated Show resolved Hide resolved
Comment on lines -75 to +76
if tp == mysql.TypeTimestamp || tp == mysql.TypeDatetime || tp == mysql.TypeDate {
err = value.ConvertTimeZone(time.Local, ctx.Location())
if err != nil {
return value, err
}
if err = value.ConvertTimeZone(defaultTime.Location(), ctx.Location()); err != nil {
return value, err
Copy link
Contributor

Choose a reason for hiding this comment

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

here lgtm

@lcwangchao lcwangchao force-pushed the replaceexprtest branch 2 times, most recently from 7d077f7 to b84a362 Compare May 8, 2024 12:02
Copy link
Member

@YangKeao YangKeao left a comment

Choose a reason for hiding this comment

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

Rest LGTM

Comment on lines -75 to +76
if tp == mysql.TypeTimestamp || tp == mysql.TypeDatetime || tp == mysql.TypeDate {
err = value.ConvertTimeZone(time.Local, ctx.Location())
if err != nil {
return value, err
}
if err = value.ConvertTimeZone(defaultTime.Location(), ctx.Location()); err != nil {
return value, err
Copy link
Member

Choose a reason for hiding this comment

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

How about add a intest.Assert here?

(It's also fine to not add it, because IMO it's intuitive to call getTimeCurrentTimeStamp with time type.

Copy link

ti-chi-bot bot commented May 17, 2024

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: YangKeao
Once this PR has been reviewed and has the lgtm label, please assign xuhuaiyu for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Copy link

ti-chi-bot bot commented May 17, 2024

[LGTM Timeline notifier]

Timeline:

  • 2024-05-17 05:35:39.678529107 +0000 UTC m=+1804293.435664850: ☑️ agreed by YangKeao.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-1-more-lgtm release-note-none size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

replace mock context in expression with StaticExprContext
3 participants