File: dump_unix_test.go

package info (click to toggle)
gitlab-ci-multi-runner 14.10.1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 31,248 kB
  • sloc: sh: 1,694; makefile: 384; asm: 79; ruby: 68
file content (41 lines) | stat: -rw-r--r-- 1,100 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
//nolint:lll
//go:build !integration && (aix || android || darwin || dragonfly || freebsd || hurd || illumos || linux || netbsd || openbsd || solaris)
// +build !integration
// +build aix android darwin dragonfly freebsd hurd illumos linux netbsd openbsd solaris

package log

import (
	"os"
	"syscall"
	"testing"

	"github.com/sirupsen/logrus"
	"github.com/sirupsen/logrus/hooks/test"
	"github.com/stretchr/testify/assert"
	"github.com/stretchr/testify/require"
)

func TestStackDumping(t *testing.T) {
	logger, hook := test.NewNullLogger()
	logger.SetFormatter(new(logrus.TextFormatter))

	stopCh := make(chan bool)

	dumpedCh, finishedCh := watchForGoroutinesDump(logger, stopCh)
	require.NotNil(t, dumpedCh)
	require.NotNil(t, finishedCh)

	proc, err := os.FindProcess(os.Getpid())
	require.NoError(t, err)
	require.NoError(t, proc.Signal(syscall.SIGUSR1))

	<-dumpedCh
	logrusOutput, err := hook.LastEntry().String()
	require.NoError(t, err)
	assert.Contains(t, logrusOutput, "=== received SIGUSR1 ===")
	assert.Contains(t, logrusOutput, "*** goroutine dump...")

	close(stopCh)
	<-finishedCh
}