Skip to content

feat(scaletest/dashboard): integrate chromedp #9927

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

Merged
merged 12 commits into from
Oct 2, 2023
Merged
Prev Previous commit
Next Next commit
log error on removing temp user data dir
  • Loading branch information
johnstcn committed Sep 29, 2023
commit cca6a0bcdb5477e4207f3fc2fc1e88b55db82267
8 changes: 6 additions & 2 deletions scaletest/dashboard/chromedp.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
"github.com/chromedp/cdproto/network"
"github.com/chromedp/chromedp"
"golang.org/x/xerrors"

"cdr.dev/slog"
)

// Action is just a function that does something.
Expand Down Expand Up @@ -150,7 +152,7 @@ func clickAndWait(ctx context.Context, clickOn, waitFor Selector) error {
// initChromeDPCtx initializes a chromedp context with the given session token cookie
//
//nolint:revive // yes, headless is a control flag
func initChromeDPCtx(ctx context.Context, u *url.URL, sessionToken string, headless bool) (context.Context, context.CancelFunc, error) {
func initChromeDPCtx(ctx context.Context, log slog.Logger, u *url.URL, sessionToken string, headless bool) (context.Context, context.CancelFunc, error) {
dir, err := os.MkdirTemp("", "scaletest-dashboard-*")
if err != nil {
return nil, nil, err
Expand All @@ -170,7 +172,9 @@ func initChromeDPCtx(ctx context.Context, u *url.URL, sessionToken string, headl
cancelFunc := func() {
cdpCancel()
allocCtxCancel()
_ = os.RemoveAll(dir)
if err := os.RemoveAll(dir); err != nil {
log.Error(ctx, "failed to remove temp user data dir", slog.F("dir", dir), slog.Error(err))
}
}

// set cookies
Expand Down
2 changes: 1 addition & 1 deletion scaletest/dashboard/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (r *Runner) Run(ctx context.Context, _ string, _ io.Writer) error {
return xerrors.Errorf("user has no organizations")
}

cdpCtx, cdpCancel, err := initChromeDPCtx(ctx, r.client.URL, r.client.SessionToken(), r.cfg.Headless)
cdpCtx, cdpCancel, err := initChromeDPCtx(ctx, r.cfg.Logger, r.client.URL, r.client.SessionToken(), r.cfg.Headless)
if err != nil {
return xerrors.Errorf("init chromedp ctx: %w", err)
}
Expand Down