Skip to content

Commit

Permalink
check tsic for panics on shutdown
Browse files Browse the repository at this point in the history
Signed-off-by: Kristoffer Dalby <[email protected]>
  • Loading branch information
kradalby committed Dec 9, 2024
1 parent 28b29b8 commit c3a7c40
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
12 changes: 11 additions & 1 deletion integration/scenario.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,20 @@ func (s *Scenario) ShutdownAssertNoPanics(t *testing.T) {
for userName, user := range s.users {
for _, client := range user.Clients {
log.Printf("removing client %s in user %s", client.Hostname(), userName)
err := client.Shutdown()
stdoutPath, stderrPath, err := client.Shutdown()
if err != nil {
log.Printf("failed to tear down client: %s", err)
}

if t != nil {
stdout, err := os.ReadFile(stdoutPath)
require.NoError(t, err)
assert.NotContains(t, string(stdout), "panic")

stderr, err := os.ReadFile(stderrPath)
require.NoError(t, err)
assert.NotContains(t, string(stderr), "panic")
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion integration/tailscale.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
// nolint
type TailscaleClient interface {
Hostname() string
Shutdown() error
Shutdown() (string, string, error)
Version() string
Execute(
command []string,
Expand Down
18 changes: 7 additions & 11 deletions integration/tsic/tsic.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,11 +236,8 @@ func New(
}

tailscaleOptions := &dockertest.RunOptions{
Name: hostname,
Networks: []*dockertest.Network{tsic.network},
// Cmd: []string{
// "tailscaled", "--tun=tsdev",
// },
Name: hostname,
Networks: []*dockertest.Network{tsic.network},
Entrypoint: tsic.withEntrypoint,
ExtraHosts: tsic.withExtraHosts,
Env: []string{},
Expand Down Expand Up @@ -357,8 +354,8 @@ func New(
}

// Shutdown stops and cleans up the Tailscale container.
func (t *TailscaleInContainer) Shutdown() error {
err := t.SaveLog("/tmp/control")
func (t *TailscaleInContainer) Shutdown() (string, string, error) {
stdoutPath, stderrPath, err := t.SaveLog("/tmp/control")
if err != nil {
log.Printf(
"Failed to save log from %s: %s",
Expand All @@ -367,7 +364,7 @@ func (t *TailscaleInContainer) Shutdown() error {
)
}

return t.pool.Purge(t.container)
return stdoutPath, stderrPath, t.pool.Purge(t.container)
}

// Hostname returns the hostname of the Tailscale instance.
Expand Down Expand Up @@ -1099,15 +1096,14 @@ func (t *TailscaleInContainer) WriteFile(path string, data []byte) error {

// SaveLog saves the current stdout log of the container to a path
// on the host system.
func (t *TailscaleInContainer) SaveLog(path string) error {
func (t *TailscaleInContainer) SaveLog(path string) (string, string, error) {
// TODO(kradalby): Assert if tailscale logs contains panics.
// NOTE(enoperm): `t.WriteLog | countMatchingLines`
// is probably most of what is for that,
// but I'd rather not change the behaviour here,
// as it may affect all the other tests
// I have not otherwise touched.
_, _, err := dockertestutil.SaveLog(t.pool, t.container, path)
return err
return dockertestutil.SaveLog(t.pool, t.container, path)
}

// WriteLogs writes the current stdout/stderr log of the container to
Expand Down

0 comments on commit c3a7c40

Please sign in to comment.