Skip to content

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

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

Open
wants to merge 4 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 Denotes a PR that doesn't merit a release note. 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.

Copy link

codecov bot commented Apr 30, 2024

Codecov Report

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

Project coverage is 57.0801%. Comparing base (479f4be) to head (de97549).
Report is 1086 commits behind head on master.

Additional details and impacted files
@@                Coverage Diff                @@
##             master     #53007         +/-   ##
=================================================
- Coverage   72.8176%   57.0801%   -15.7375%     
=================================================
  Files          1524       1649        +125     
  Lines        435793     631414     +195621     
=================================================
+ Hits         317334     360412      +43078     
- Misses        98816     247146     +148330     
- Partials      19643      23856       +4213     
Flag Coverage Δ
integration 37.0358% <14.2857%> (?)
unit 71.7889% <71.4285%> (-0.0259%) ⬇️

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

Components Coverage Δ
dumpling 52.9656% <ø> (ø)
parser ∅ <ø> (∅)
br 52.5507% <ø> (+6.4191%) ⬆️

@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.

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 3 times, most recently from b84a362 to aea6a28 Compare May 13, 2024 10:41
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

[LGTM Timeline notifier]

Timeline:

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

@ti-chi-bot ti-chi-bot bot added the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label May 17, 2024
Copy link

ti-chi-bot bot commented Jun 28, 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 windtalker 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

@lcwangchao lcwangchao force-pushed the replaceexprtest branch 3 times, most recently from 1cff68e to 45eab99 Compare June 28, 2024 09:29
@lcwangchao
Copy link
Collaborator Author

/retest

Copy link

tiprow bot commented Jun 28, 2024

@lcwangchao: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

In response to this:

/retest

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-sigs/prow repository.

@ti-chi-bot ti-chi-bot bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 5, 2024
Copy link

ti-chi-bot bot commented Jul 5, 2024

PR needs rebase.

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.

Copy link

ti-chi-bot bot commented Nov 18, 2024

@lcwangchao: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-integration-e2e-test de97549 link true /test pull-integration-e2e-test

Full PR test history. Your PR dashboard.

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. I understand the commands that are listed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-1-more-lgtm Indicates a PR needs 1 more LGTM. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. release-note-none Denotes a PR that doesn't merit a release note. 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