mirror of
https://github.com/fleetdm/fleet
synced 2026-05-24 01:18:42 +00:00
Remove flaky log rotation test (#385)
This test has been flaky for years and it's time for it to go.
This commit is contained in:
parent
0483cc7aaa
commit
f9312df174
1 changed files with 0 additions and 53 deletions
|
|
@ -1,53 +0,0 @@
|
|||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/go-kit/kit/log"
|
||||
"github.com/fleetdm/fleet/server/logging"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
// TestRotateLoggerSIGHUP verifies that the osqueryd logfile is rotated by
|
||||
// sending a SIGHUP signal.
|
||||
func TestRotateLoggerSIGHUP(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
filePrefix := "kolide-log-rotate-test"
|
||||
f, err := ioutil.TempFile("/tmp", filePrefix)
|
||||
require.Nil(t, err)
|
||||
defer os.Remove(f.Name())
|
||||
|
||||
logFile, err := logging.NewFilesystemLogWriter(f.Name(), log.NewNopLogger(), true, false)
|
||||
require.Nil(t, err)
|
||||
|
||||
// write a log line
|
||||
logFile.Write(ctx, []json.RawMessage{json.RawMessage("msg1")})
|
||||
|
||||
sig := make(chan os.Signal, 1)
|
||||
signal.Notify(sig, syscall.SIGHUP)
|
||||
defer signal.Reset(syscall.SIGHUP)
|
||||
|
||||
// send SIGHUP to the process
|
||||
err = syscall.Kill(syscall.Getpid(), syscall.SIGHUP)
|
||||
require.Nil(t, err)
|
||||
|
||||
// wait for the SIGHUP signal, otherwise the test exits before the
|
||||
// log is rotated.
|
||||
<-sig
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
|
||||
// write a new log line and verify that the original file includes
|
||||
// the new log line but not any of the old ones.
|
||||
logFile.Write(ctx, []json.RawMessage{json.RawMessage("msg2")})
|
||||
logMsg, err := ioutil.ReadFile(f.Name())
|
||||
require.Nil(t, err)
|
||||
|
||||
require.Equal(t, "msg2\n", string(logMsg))
|
||||
}
|
||||
Loading…
Reference in a new issue