Skip to content
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

Add webdriver test for action page #8117

Merged
merged 1 commit into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1637,11 +1637,7 @@ func TestRedisRestart(t *testing.T) {
}
app := buildbuddy_enterprise.RunWithConfig(t, buildbuddy_enterprise.DefaultAppConfig(t), buildbuddy_enterprise.NoAuthConfig, args...)

_ = testexecutor.Run(
t,
testexecutor.ExecutorRunfilePath,
[]string{"--executor.app_target=" + app.GRPCAddress()},
)
_ = testexecutor.Run(t, "--executor.app_target="+app.GRPCAddress())

ctx := context.Background()
ws := testbazel.MakeTempWorkspace(t, workspaceContents)
Expand Down
2 changes: 2 additions & 0 deletions enterprise/server/test/webdriver/invocation/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ go_web_test_suite(
shard_count = 3,
deps = [
"//enterprise/server/testutil/buildbuddy_enterprise",
"//enterprise/server/testutil/testexecutor",
"//server/testutil/testbazel",
"//server/testutil/webtester",
"//server/util/uuid",
"@com_github_stretchr_testify//assert",
"@com_github_stretchr_testify//require",
],
)
Expand Down
37 changes: 34 additions & 3 deletions enterprise/server/test/webdriver/invocation/invocation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@ package invocation_test
import (
"context"
"fmt"
"math"
"math/rand"
"strings"
"testing"
"time"

"github.com/buildbuddy-io/buildbuddy/enterprise/server/testutil/buildbuddy_enterprise"
"github.com/buildbuddy-io/buildbuddy/enterprise/server/testutil/testexecutor"
"github.com/buildbuddy-io/buildbuddy/server/testutil/testbazel"
"github.com/buildbuddy-io/buildbuddy/server/testutil/webtester"
"github.com/buildbuddy-io/buildbuddy/server/util/uuid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -229,9 +232,17 @@ func TestAuthenticatedInvocation_PersonalAPIKey_CacheEnabled(t *testing.T) {
}

func TestInvocationWithRemoteExecution(t *testing.T) {
// TODO: make this test work in dev QA, using dev executors.
buildbuddy_enterprise.MarkTestLocalOnly(t)

ctx := context.Background()
wt := webtester.New(t)
target := buildbuddy_enterprise.SetupWebTarget(t)
target := buildbuddy_enterprise.SetupWebTarget(
t,
"--remote_execution.enable_remote_exec=true",
)
// Register an executor so that we can test RBE end-to-end.
_ = testexecutor.Run(t, "--executor.app_target="+target.GRPCAddress())

workspacePath := testbazel.MakeTempWorkspace(t, map[string]string{
"WORKSPACE": "",
Expand Down Expand Up @@ -267,8 +278,28 @@ func TestInvocationWithRemoteExecution(t *testing.T) {
row := rows[0]
require.Contains(t, row.Text(), "genrule-setup.sh", "row should show command snippet")

// TODO: run an actual executor, and make sure we can click through to the
// action page and see the action
// Click through to the action page
row.Click()

// The ExecuteResponse is cached in the background after the invocation
// completes; refresh the page until the ExecuteResponse is cached.
actionResultFound := false
for i := range 8 {
textContent := wt.Find(".invocation-action-card .content").Text()
if !strings.Contains(textContent, "Action result not found") {
actionResultFound = true
break
}
time.Sleep(100 * time.Millisecond * time.Duration(math.Pow(2, float64(i))))
wt.Refresh()
}
require.True(t, actionResultFound, "Cached action result was not found")

// Verify that a few basic details are present.
textContent := wt.Find(".invocation-action-card .content").Text()
assert.Regexp(t, `Cacheable\s+Yes`, textContent, "Action details should be present")
assert.Regexp(t, `Served from cache\s+No`, textContent, "ActionResult details should be present")
assert.Regexp(t, `MilliCPU:\s+\d+`, textContent, "ExecutedActionMetadata details should be present")
}

type CacheRequestRow struct {
Expand Down
2 changes: 1 addition & 1 deletion enterprise/server/testutil/testexecutor/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ go_library(
],
importpath = "github.com/buildbuddy-io/buildbuddy/enterprise/server/testutil/testexecutor",
x_defs = {
"ExecutorRunfilePath": "$(rlocationpath //enterprise/server/cmd/executor)",
"executorRlocationpath": "$(rlocationpath //enterprise/server/cmd/executor)",
},
deps = [
"//server/testutil/testport",
Expand Down
25 changes: 10 additions & 15 deletions enterprise/server/testutil/testexecutor/testexecutor.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,22 @@ type Executor struct {
}

// set by x_defs in BUILD file
var ExecutorRunfilePath string
var executorRlocationpath string

// Run a local BuildBuddy executor for the scope of the given test case.
//
// The given command path and config file path refer to the workspace-relative runfile
// paths of the executor server binary.
func Run(t *testing.T, commandPath string, commandArgs []string) *Executor {
// Run a local BuildBuddy executor binary for the scope of the given test case.
func Run(t *testing.T, args ...string) *Executor {
e := &Executor{
httpPort: testport.FindFree(t),
monitoringPort: testport.FindFree(t),
}
args := []string{
"--app.log_level=debug",
fmt.Sprintf("--port=%d", e.httpPort),
fmt.Sprintf("--monitoring_port=%d", e.monitoringPort),
}
args = append(args, commandArgs...)

testserver.Run(t, &testserver.Opts{
BinaryRunfilePath: commandPath,
Args: args,
BinaryRunfilePath: executorRlocationpath,
Args: append(
args,
"--app.log_level=debug",
fmt.Sprintf("--port=%d", e.httpPort),
fmt.Sprintf("--monitoring_port=%d", e.monitoringPort),
),
HTTPPort: e.httpPort,
HealthCheckServerType: "prod-buildbuddy-executor",
})
Expand Down
8 changes: 7 additions & 1 deletion server/testutil/webtester/webtester.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ func New(t *testing.T) *WebTester {
// the webdriver if the screenshot fails.
assert.NoError(t, err, "failed to take end-of-test screenshot")

if t.Failed() {
if *endOfTestDelay > 0 {
t.Logf("Sleeping for %s (-webdriver_end_of_test_delay)", *endOfTestDelay)
time.Sleep(*endOfTestDelay)
}
err = driver.Quit()
Expand All @@ -129,6 +130,11 @@ func (wt *WebTester) CurrentURL() string {
return url
}

// Refresh reloads the page.
func (wt *WebTester) Refresh() {
wt.Get(wt.CurrentURL())
}

// Returns the <body> element of the current page. Exactly one body element
// must exist, otherwise the test fails.
func (wt *WebTester) FindBody() *Element {
Expand Down
Loading