Skip to content

Commit

Permalink
Use SC selenium relay when starting SC. (#271)
Browse files Browse the repository at this point in the history
Remove usage of deprecated repository rules.
  • Loading branch information
DrMarcII authored Jul 11, 2018
1 parent 9200b9e commit fc506e3
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 5 deletions.
2 changes: 2 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#
workspace(name = "io_bazel_rules_webtesting")

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

# NOTE: URLs are mirrored by an asynchronous review process. They must
# be greppable for that to happen. It's OK to submit broken mirror
# URLs, so long as they're correctly formatted. Bazel's downloader
Expand Down
1 change: 1 addition & 0 deletions go/wtl/environment/sauce/sauce.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ func NewEnv(m *metadata.Metadata, d diagnostics.Diagnostics) (environment.Env, e
}

connect = c
address = c.Address
}

base, err := environment.NewBase(name, m, d)
Expand Down
1 change: 1 addition & 0 deletions go/wtl/service/sauce/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@ go_library(
deps = [
"//go/errors:go_default_library",
"//go/metadata:go_default_library",
"//go/portpicker:go_default_library",
],
)
26 changes: 23 additions & 3 deletions go/wtl/service/sauce/connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,33 @@ package sauce
import (
"bufio"
"context"
"fmt"
"os/exec"
"strconv"
"strings"
"sync"

"github.com/bazelbuild/rules_webtesting/go/errors"
"github.com/bazelbuild/rules_webtesting/go/metadata"
"github.com/bazelbuild/rules_webtesting/go/portpicker"
)

const (
compName = "Sauce Connect Service"
scNamedFile = "SAUCE_CONNECT"
)

// Connect is a service that manages Sauce Connect.
type Connect struct {
// Address is the address that the Sauce Connect Selenium relay is running on.
Address string

cmd *exec.Cmd

mu sync.Mutex
ready bool
err error
port int
}

// New creates a new service that manages Sauce Connect.
Expand All @@ -46,13 +54,23 @@ func New(m *metadata.Metadata, username, accessKey, tunnelID string) (*Connect,
return nil, errors.New(compName, err)
}

port, err := portpicker.PickUnusedPort()
if err != nil {
return nil, errors.New(compName, err)
}

cmd := exec.Command(
scPath,
"--user", username,
"--api-key", accessKey,
"--tunnel-identifier", tunnelID)

return &Connect{cmd: cmd}, nil
"--tunnel-identifier", tunnelID,
"--se-port", strconv.Itoa(port))

return &Connect{
cmd: cmd,
port: port,
Address: fmt.Sprintf("http://%s:%s@localhost:%d/wd/hub/", username, accessKey, port),
}, nil
}

// Start starts Sauce Connect and waits for it to be ready for use.
Expand Down Expand Up @@ -121,6 +139,8 @@ func (c *Connect) monitor() {
c.ready = false
c.err = err
}

portpicker.RecycleUnusedPort(c.port)
}

func (c *Connect) Name() string {
Expand Down
5 changes: 3 additions & 2 deletions web/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
load("//web/internal:java_import_external.bzl", "java_import_external")
load("//web/internal:platform_http_file.bzl", "platform_http_file")
load("@bazel_gazelle//:deps.bzl", "go_repository")
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

# NOTE: URLs are mirrored by an asynchronous review process. They must
# be greppable for that to happen. It's OK to submit broken mirror
Expand Down Expand Up @@ -142,7 +143,7 @@ def browser_repositories(firefox = False, chromium = False, sauce = False):
com_saucelabs_sauce_connect()

def bazel_skylib():
native.http_archive(
http_archive(
name = "bazel_skylib",
sha256 = "d7cffbed034d1203858ca19ff2e88d241781f45652a4c719ed48eedc74bc82a9",
strip_prefix = "bazel-skylib-0.3.1",
Expand Down Expand Up @@ -498,7 +499,7 @@ def org_mozilla_geckodriver():
)

def org_seleniumhq_py():
native.new_http_archive(
http_archive(
name = "org_seleniumhq_py",
build_file = str(Label("//build_files:org_seleniumhq_py.BUILD")),
sha256 = "5841fb30c3965866220c34d16de8e3d091e2833fcac385160a63db0c3522a297",
Expand Down

0 comments on commit fc506e3

Please sign in to comment.