From beb3e9abc231d6da826b657f3d29cf363b022f16 Mon Sep 17 00:00:00 2001 From: Csaba Sarkadi Date: Sat, 15 Jan 2022 16:28:26 +0100 Subject: [PATCH] integration-test: taildrop test refactor --- Dockerfile.tailscale | 2 +- integration_test.go | 92 +++++++++++++++++--------------------------- 2 files changed, 36 insertions(+), 58 deletions(-) diff --git a/Dockerfile.tailscale b/Dockerfile.tailscale index df8cdcb1..f96c6b9c 100644 --- a/Dockerfile.tailscale +++ b/Dockerfile.tailscale @@ -7,5 +7,5 @@ RUN apt-get update \ && curl -fsSL https://pkgs.tailscale.com/stable/ubuntu/focal.gpg | apt-key add - \ && curl -fsSL https://pkgs.tailscale.com/stable/ubuntu/focal.list | tee /etc/apt/sources.list.d/tailscale.list \ && apt-get update \ - && apt-get install -y tailscale=${TAILSCALE_VERSION} \ + && apt-get install -y tailscale=${TAILSCALE_VERSION} dnsutils \ && rm -rf /var/lib/apt/lists/* diff --git a/integration_test.go b/integration_test.go index c81749f5..fd280f88 100644 --- a/integration_test.go +++ b/integration_test.go @@ -604,74 +604,52 @@ func (s *IntegrationTestSuite) TestTailDrop() { for _, scales := range s.namespaces { ips, err := getIPs(scales.tailscales) assert.Nil(s.T(), err) - apiURLs, err := getAPIURLs(scales.tailscales) assert.Nil(s.T(), err) + retry := func(times int, sleepInverval time.Duration, doWork func() error) (err error) { + for attempts := 0; attempts < times; attempts++ { + err = doWork() + if err == nil { + return + } + time.Sleep(sleepInverval) + } + return + } + for hostname, tailscale := range scales.tailscales { command := []string{"touch", fmt.Sprintf("/tmp/file_from_%s", hostname)} _, err := ExecuteCommand( &tailscale, command, - []string{"GOMAXPROCS=32"}, + []string{}, ) assert.Nil(s.T(), err) - for peername, ip := range ips { + for peername, _ := range ips { + if peername == hostname { + continue + } s.T().Run(fmt.Sprintf("%s-%s", hostname, peername), func(t *testing.T) { - if peername != hostname { - // Under normal circumstances, we should be able to send a file - // using `tailscale file cp` - but not in userspace networking mode - // So curl! - peerAPI, ok := apiURLs[ip] - assert.True(t, ok) - - // TODO(juanfont): We still have some issues with the test infrastructure, so - // lets run curl multiple times until it works. - attempts := 0 - var err error - for { - command := []string{ - "curl", - "--retry-connrefused", - "--retry-delay", - "30", - "--retry", - "10", - "--connect-timeout", - "60", - "-X", - "PUT", - "--upload-file", - fmt.Sprintf("/tmp/file_from_%s", hostname), - fmt.Sprintf( - "%s/v0/put/file_from_%s", - peerAPI, - hostname, - ), - } - fmt.Printf( - "Sending file from %s (%s) to %s (%s)\n", - hostname, - ips[hostname], - peername, - ip, - ) - _, err = ExecuteCommand( - &tailscale, - command, - []string{"ALL_PROXY=socks5://localhost:1055", "GOMAXPROCS=32"}, - ) - if err == nil { - break - } else { - time.Sleep(10 * time.Second) - attempts++ - if attempts > 10 { - break - } - } - } - assert.Nil(t, err) + command := []string{ + "tailscale", "file", "cp", + fmt.Sprintf("/tmp/file_from_%s", hostname), + fmt.Sprintf("%s:", peername), } + retry(10, 1*time.Second, func() error { + fmt.Printf( + "Sending file from %s to %s\n", + hostname, + peername, + ) + _, err := ExecuteCommand( + &tailscale, + command, + []string{}, + ExecuteCommandTimeout(60*time.Second), + ) + return err + }) + assert.Nil(t, err) }) } }