Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

chore(coderd/database/dbpurge): replace usage of time.* with quartz#14480

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
johnstcn merged 3 commits intomainfromcj/dbpurge-quartz
Aug 30, 2024

Conversation

johnstcn
Copy link
Member

@johnstcnjohnstcn commentedAug 29, 2024
edited
Loading

Related to#10576

This PR introduces quartz tocoderd/database/dbpurge and updates the following unit tests to make use of Quartz's functionality:

  • TestPurge
  • TestDeleteOldWorkspaceAgentLogs

Additionally, updatesDeleteOldWorkspaceAgentLogs to replace the hard-coded interval with a parameter passed into the query. This aids in testing and brings us a step towards allowing operators to configure the cutoff interval for workspace agent logs.

@johnstcnjohnstcn self-assigned thisAug 29, 2024
@johnstcnjohnstcn changed the titleCj/dbpurge quartzchore(coderd/database/dbpurge): replace usage of time.Now() with quartzAug 29, 2024
@johnstcnjohnstcn changed the titlechore(coderd/database/dbpurge): replace usage of time.Now() with quartzchore(coderd/database/dbpurge): replace usage of time.* with quartzAug 29, 2024
@johnstcnjohnstcn marked this pull request as ready for reviewAugust 29, 2024 16:06
Copy link
Member

@mafredrimafredri left a comment

Choose a reason for hiding this comment

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

LGTM

agent:=mustCreateAgentWithLogs(ctx,t,db,user,org,tmpl,tv,now.Add(-8*24*time.Hour),t.Name())
// After dbpurge completes, the ticker is reset. Trap this call.
trapReset:=clk.Trap().TickerReset()
defertrapReset.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 seems shared between all tests, how about refactoring to a helper like below, or consider only testing it in one test and assuming it applies to the rest?

t.Helper()// After dbpurge completes, the ticker is reset. Trap this call.trapReset:=clk.Trap().TickerReset()defertrapReset.Close()closer:=do(clk)// Wait for the initial nanosecond tick.clk.Advance(time.Nanosecond).MustWait(ctx)trapReset.MustWait(ctx).Release()// Wait for ticker.Reset()returncloser

Perhaps this example can even be taken further, just here as food for thought.

Copy link
MemberAuthor

@johnstcnjohnstcnAug 29, 2024
edited
Loading

Choose a reason for hiding this comment

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

I modify this test in the follow-up PR#14460 so the sharing between tests won't be an issue.

But I do like the idea of extracting this to a test helper!

mafredri reacted with thumbs up emoji
Copy link
Contributor

@dannykoppingdannykopping left a comment

Choose a reason for hiding this comment

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

LGTM

funcTestDeleteOldWorkspaceAgentStats(t*testing.T) {
db,_:=dbtestutil.NewDB(t)
logger:=slogtest.Make(t,&slogtest.Options{IgnoreErrors:true}).Leveled(slog.LevelDebug)
ctx,cancel:=context.WithTimeout(context.Background(),testutil.WaitShort)
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit:testutil.Context is a nice convenience for this:

funcContext(t*testing.T,dur time.Duration) context.Context {ctx,cancel:=context.WithTimeout(context.Background(),dur)t.Cleanup(cancel)returnctx}

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Will address in follow-up 👍

@johnstcnjohnstcn merged commita74273f intomainAug 30, 2024
27 checks passed
@johnstcnjohnstcn deleted the cj/dbpurge-quartz branchAugust 30, 2024 10:55
@github-actionsgithub-actionsbot locked and limited conversation to collaboratorsAug 30, 2024
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.

Reviewers

@mafredrimafredrimafredri approved these changes

@dannykoppingdannykoppingdannykopping approved these changes

@mtojekmtojekAwaiting requested review from mtojek

Assignees

@johnstcnjohnstcn

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

3 participants

@johnstcn@mafredri@dannykopping

[8]ページ先頭

©2009-2025 Movatter.jp