mirror of
https://github.com/tailscale/tailscale.git
synced 2025-12-03 02:21:58 +00:00
tstest/integration: build binaries only once
The existing code relied on the Go build cache to avoid needless work when obtaining the tailscale binaries. For non-obvious reasons, the binaries were getting re-linked every time, which added 600ms or so on my machine to every test. Instead, build the binaries exactly once, on demand. This reduces the time to run 'go test -count=5' from 34s to 10s on my machine. Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
This commit is contained in:
committed by
Josh Bleecher Snyder
parent
e133bb570b
commit
4691e012a9
@@ -35,7 +35,9 @@ import (
|
||||
type Harness struct {
|
||||
testerDialer proxy.Dialer
|
||||
testerDir string
|
||||
bins *integration.Binaries
|
||||
binaryDir string
|
||||
cli string
|
||||
daemon string
|
||||
pubKey string
|
||||
signer ssh.Signer
|
||||
cs *testcontrol.Server
|
||||
@@ -134,11 +136,11 @@ func newHarness(t *testing.T) *Harness {
|
||||
loginServer := fmt.Sprintf("http://%s", ln.Addr())
|
||||
t.Logf("loginServer: %s", loginServer)
|
||||
|
||||
bins := integration.BuildTestBinaries(t)
|
||||
|
||||
h := &Harness{
|
||||
pubKey: string(pubkey),
|
||||
bins: bins,
|
||||
binaryDir: integration.BinaryDir(t),
|
||||
cli: integration.TailscaleBinary(t),
|
||||
daemon: integration.TailscaledBinary(t),
|
||||
signer: signer,
|
||||
loginServerURL: loginServer,
|
||||
cs: cs,
|
||||
@@ -146,7 +148,7 @@ func newHarness(t *testing.T) *Harness {
|
||||
ipMap: ipMap,
|
||||
}
|
||||
|
||||
h.makeTestNode(t, bins, loginServer)
|
||||
h.makeTestNode(t, loginServer)
|
||||
|
||||
return h
|
||||
}
|
||||
@@ -156,7 +158,7 @@ func (h *Harness) Tailscale(t *testing.T, args ...string) []byte {
|
||||
|
||||
args = append([]string{"--socket=" + filepath.Join(h.testerDir, "sock")}, args...)
|
||||
|
||||
cmd := exec.Command(h.bins.CLI, args...)
|
||||
cmd := exec.Command(h.cli, args...)
|
||||
out, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -169,7 +171,7 @@ func (h *Harness) Tailscale(t *testing.T, args ...string) []byte {
|
||||
// enables us to make connections to and from the tailscale network being
|
||||
// tested. This mutates the Harness to allow tests to dial into the tailscale
|
||||
// network as well as control the tester's tailscaled.
|
||||
func (h *Harness) makeTestNode(t *testing.T, bins *integration.Binaries, controlURL string) {
|
||||
func (h *Harness) makeTestNode(t *testing.T, controlURL string) {
|
||||
dir := t.TempDir()
|
||||
h.testerDir = dir
|
||||
|
||||
@@ -179,7 +181,7 @@ func (h *Harness) makeTestNode(t *testing.T, bins *integration.Binaries, control
|
||||
}
|
||||
|
||||
cmd := exec.Command(
|
||||
bins.Daemon,
|
||||
h.daemon,
|
||||
"--tun=userspace-networking",
|
||||
"--state="+filepath.Join(dir, "state.json"),
|
||||
"--socket="+filepath.Join(dir, "sock"),
|
||||
@@ -222,7 +224,7 @@ outer:
|
||||
}
|
||||
}
|
||||
|
||||
run(t, dir, bins.CLI,
|
||||
run(t, dir, h.cli,
|
||||
"--socket="+filepath.Join(dir, "sock"),
|
||||
"up",
|
||||
"--login-server="+controlURL,
|
||||
|
||||
@@ -17,7 +17,6 @@ import (
|
||||
"testing"
|
||||
"text/template"
|
||||
|
||||
"tailscale.com/tstest/integration"
|
||||
"tailscale.com/types/logger"
|
||||
)
|
||||
|
||||
@@ -153,15 +152,15 @@ in {
|
||||
systemd.services.tailscaled.environment."TS_LOG_TARGET" = "{{.LogTarget}}";
|
||||
}`
|
||||
|
||||
func copyUnit(t *testing.T, bins *integration.Binaries) {
|
||||
func (h *Harness) copyUnit(t *testing.T) {
|
||||
t.Helper()
|
||||
|
||||
data, err := os.ReadFile("../../../cmd/tailscaled/tailscaled.service")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
os.MkdirAll(filepath.Join(bins.Dir, "systemd"), 0755)
|
||||
err = os.WriteFile(filepath.Join(bins.Dir, "systemd", "tailscaled.service"), data, 0666)
|
||||
os.MkdirAll(filepath.Join(h.binaryDir, "systemd"), 0755)
|
||||
err = os.WriteFile(filepath.Join(h.binaryDir, "systemd", "tailscaled.service"), data, 0666)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -172,7 +171,7 @@ func (h *Harness) makeNixOSImage(t *testing.T, d Distro, cdir string) string {
|
||||
t.Skip("https://github.com/NixOS/nixpkgs/issues/131098")
|
||||
}
|
||||
|
||||
copyUnit(t, h.bins)
|
||||
h.copyUnit(t)
|
||||
dir := t.TempDir()
|
||||
fname := filepath.Join(dir, d.Name+".nix")
|
||||
fout, err := os.Create(fname)
|
||||
@@ -185,7 +184,7 @@ func (h *Harness) makeNixOSImage(t *testing.T, d Distro, cdir string) string {
|
||||
BinPath string
|
||||
LogTarget string
|
||||
}{
|
||||
BinPath: h.bins.Dir,
|
||||
BinPath: h.binaryDir,
|
||||
LogTarget: h.loginServerURL,
|
||||
})
|
||||
if err != nil {
|
||||
|
||||
@@ -290,7 +290,6 @@ func checkCachedImageHash(t *testing.T, d Distro, cacheDir string) string {
|
||||
}
|
||||
|
||||
func (h *Harness) copyBinaries(t *testing.T, d Distro, conn *ssh.Client) {
|
||||
bins := h.bins
|
||||
if strings.HasPrefix(d.Name, "nixos") {
|
||||
return
|
||||
}
|
||||
@@ -305,8 +304,8 @@ func (h *Harness) copyBinaries(t *testing.T, d Distro, conn *ssh.Client) {
|
||||
mkdir(t, cli, "/etc/default")
|
||||
mkdir(t, cli, "/var/lib/tailscale")
|
||||
|
||||
copyFile(t, cli, bins.Daemon, "/usr/sbin/tailscaled")
|
||||
copyFile(t, cli, bins.CLI, "/usr/bin/tailscale")
|
||||
copyFile(t, cli, h.daemon, "/usr/sbin/tailscaled")
|
||||
copyFile(t, cli, h.cli, "/usr/bin/tailscale")
|
||||
|
||||
// TODO(Xe): revisit this assumption before it breaks the test.
|
||||
copyFile(t, cli, "../../../cmd/tailscaled/tailscaled.defaults", "/etc/default/tailscaled")
|
||||
|
||||
@@ -30,6 +30,7 @@ import (
|
||||
"golang.org/x/sync/semaphore"
|
||||
"inet.af/netaddr"
|
||||
"tailscale.com/tstest"
|
||||
"tailscale.com/tstest/integration"
|
||||
"tailscale.com/types/logger"
|
||||
)
|
||||
|
||||
@@ -52,6 +53,13 @@ var (
|
||||
}()
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
flag.Parse()
|
||||
v := m.Run()
|
||||
integration.CleanupBinaries()
|
||||
os.Exit(v)
|
||||
}
|
||||
|
||||
func TestDownloadImages(t *testing.T) {
|
||||
if !*runVMTests {
|
||||
t.Skip("not running integration tests (need --run-vm-tests)")
|
||||
|
||||
Reference in New Issue
Block a user