Adding upstream version 1.34.4.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
e393c3af3f
commit
4978089aab
4963 changed files with 677545 additions and 0 deletions
62
plugins/inputs/execd/shim/shim_posix_test.go
Normal file
62
plugins/inputs/execd/shim/shim_posix_test.go
Normal file
|
@ -0,0 +1,62 @@
|
|||
//go:build !windows
|
||||
|
||||
package shim
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"context"
|
||||
"io"
|
||||
"os"
|
||||
"syscall"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestShimUSR1SignalingWorks(t *testing.T) {
|
||||
stdinReader, stdinWriter := io.Pipe()
|
||||
stdoutReader, stdoutWriter := io.Pipe()
|
||||
|
||||
ctx, cancel := context.WithCancel(t.Context())
|
||||
defer cancel()
|
||||
metricProcessed, exited := runInputPlugin(t, 20*time.Minute, stdinReader, stdoutWriter, nil)
|
||||
|
||||
// signal USR1 to yourself.
|
||||
pid := os.Getpid()
|
||||
process, err := os.FindProcess(pid)
|
||||
require.NoError(t, err)
|
||||
|
||||
go func() {
|
||||
// On slow machines this signal can fire before the service comes up.
|
||||
// rather than depend on accurate sleep times, we'll just retry sending
|
||||
// the signal every so often until it goes through.
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return // test is done
|
||||
default:
|
||||
// test isn't done, keep going.
|
||||
if err := process.Signal(syscall.SIGUSR1); err != nil {
|
||||
t.Error(err)
|
||||
metricProcessed <- false
|
||||
return
|
||||
}
|
||||
time.Sleep(200 * time.Millisecond)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
<-metricProcessed
|
||||
cancel()
|
||||
|
||||
r := bufio.NewReader(stdoutReader)
|
||||
out, err := r.ReadString('\n')
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "measurement,tag=tag field=1i 1234000005678\n", out)
|
||||
|
||||
require.NoError(t, stdinWriter.Close())
|
||||
readUntilEmpty(r)
|
||||
|
||||
<-exited
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue