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: executor_test: reduce test execution time#1876

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 5 commits intomainfromcj/gh-1859/autobuild-test-times
May 30, 2022

Conversation

johnstcn
Copy link
Member

@johnstcnjohnstcn commentedMay 27, 2022
edited
Loading

This PR removes 5-second wait inautobuild.executor unit tests (now approx. 1.6s on my machine):

  • Adds a write-only channel to Executor and plumbs through to unit tests
  • ModifiesrunOnce to return anexecutor.RunStats struct and write tostatsCh if not nil

Closes#1859

@johnstcnjohnstcn self-assigned thisMay 27, 2022
@johnstcnjohnstcn changed the titleCj/gh 1859/autobuild test timeschore: executor_test: reduce test execution timeMay 27, 2022
@johnstcnjohnstcnforce-pushed thecj/gh-1859/autobuild-test-times branch fromf118679 tob0260d7CompareMay 30, 2022 09:39
@johnstcnjohnstcn marked this pull request as ready for reviewMay 30, 2022 11:43
@johnstcnjohnstcn requested a review froma teamMay 30, 2022 11:44
SSHKeygenAlgorithm gitsshkey.Algorithm
APIRateLimit int
AutobuildTicker <-chan time.Time
AutobuildStatsChannel chan<- executor.RunStats
Copy link
Member

Choose a reason for hiding this comment

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

I think we could call thisAutobuildStats. The fact that it's a channel doesn't seem very important to the caller in this context.

johnstcn reacted with thumbs up emoji
Comment on lines 45 to 51
// WithStatsChannel will cause Executor to push a RunStats to ch after
// every tick.
func (e *Executor) WithStatsChannel(ch chan<- RunStats) *Executor {
e.statsCh = ch
return e
}

Copy link
Member

Choose a reason for hiding this comment

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

Should we always do this?

Copy link
Member

Choose a reason for hiding this comment

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

eg. maybe we could remove this and just make it the default behavior.

Copy link
MemberAuthor

@johnstcnjohnstcnMay 30, 2022
edited
Loading

Choose a reason for hiding this comment

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

I don't have any major use-case for consuming these outside of the unit tests, hence the toggle.
Thoughts? Just pulling those values from the channel and dumping them to an underscore seems like a bit of a waste IMO.

Copy link
Member

Choose a reason for hiding this comment

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

Fair enough. I think it's fine for now!

Comment on lines 27 to 32
// RunStats contains information about one run of Executor.
type RunStats struct {
Transitions map[uuid.UUID]database.WorkspaceTransition
Elapsed time.Duration
Error error
}
Copy link
Member

Choose a reason for hiding this comment

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

We could probably call thisStats. Sinceexecutor.Executor is the primary export of this package, it seems reasonableexecutor.Stats would attach to it.

johnstcn reacted with thumbs up emoji
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.

Just one question but otherwise LGTM!

@@ -92,6 +93,11 @@ func NewWithAPI(t *testing.T, options *Options) (*codersdk.Client, *coderd.API)
options.AutobuildTicker = ticker
t.Cleanup(func() { close(ticker) })
}
if options.AutobuildStatsChannel != nil {
t.Cleanup(func() {
close(options.AutobuildStatsChannel)
Copy link
Member

Choose a reason for hiding this comment

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

Wondering if this could result in a send on nil channel at some point? Or is theRun() function guaranteed to have exited/not tick further at this point?

Copy link
MemberAuthor

@johnstcnjohnstcnMay 30, 2022
edited
Loading

Choose a reason for hiding this comment

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

In a unit test, the ticks are sent manually. So, the only way a send could occur after the channel is closed is if you did something like the below without pulling from the stats channel.

func TestSomething(t *testing.T) {  // setup goes here blah blah  t.Cleanup(func() {     tickCh <- time.Now()  })  // stats := <- statsCh}

Additionally, calls tot.Cleanup are executed in LIFO order, so I'd suspect that you might run intogoleak complaining instead.

@johnstcnjohnstcn added this to theCommunity MVP milestoneMay 30, 2022
@johnstcnjohnstcn added apiArea: HTTP API chore 🔧 labelsMay 30, 2022
@johnstcnjohnstcn merged commite02ef6f intomainMay 30, 2022
@johnstcnjohnstcn deleted the cj/gh-1859/autobuild-test-times branchMay 30, 2022 19:23
@missknissmisskniss mentioned this pull requestJun 1, 2022
20 tasks
kylecarbs pushed a commit that referenced this pull requestJun 10, 2022
Removes 5-second wait in autobuild.executor unit tests:- Adds a write-only channel to Executor and plumbs through to unit tests- Modifies runOnce to return an executor.RunStats struct and write to statsCh if not nil
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@kylecarbskylecarbskylecarbs approved these changes

@mafredrimafredrimafredri approved these changes

Assignees

@johnstcnjohnstcn

Labels
apiArea: HTTP API
Projects
None yet
Milestone
Community MVP
Development

Successfully merging this pull request may close these issues.

chore: improve autobuild.executor unit tests
4 participants
@johnstcn@mafredri@kylecarbs@misskniss

[8]ページ先頭

©2009-2025 Movatter.jp