chore: executor_test: reduce test execution time (#1876)

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
This commit is contained in:
Cian Johnston
2022-05-30 20:23:36 +01:00
committed by GitHub
parent ae4b2d88cd
commit e02ef6f228
3 changed files with 181 additions and 128 deletions

View File

@ -64,6 +64,7 @@ type Options struct {
SSHKeygenAlgorithm gitsshkey.Algorithm
APIRateLimit int
AutobuildTicker <-chan time.Time
AutobuildStats chan<- executor.Stats
// IncludeProvisionerD when true means to start an in-memory provisionerD
IncludeProvisionerD bool
@ -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.AutobuildStats != nil {
t.Cleanup(func() {
close(options.AutobuildStats)
})
}
// This can be hotswapped for a live database instance.
db := databasefake.New()
@ -122,7 +128,7 @@ func NewWithAPI(t *testing.T, options *Options) (*codersdk.Client, *coderd.API)
db,
slogtest.Make(t, nil).Named("autobuild.executor").Leveled(slog.LevelDebug),
options.AutobuildTicker,
)
).WithStatsChannel(options.AutobuildStats)
lifecycleExecutor.Run()
srv := httptest.NewUnstartedServer(nil)