chore: update slow file rotation tests (#10857)

This commit is contained in:
Joshua Powers 2022-03-24 10:56:25 -07:00 committed by GitHub
parent e4b9924625
commit 36d0b0ff7a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 4 deletions

View File

@ -28,14 +28,14 @@ func TestFileWriter_NoRotation(t *testing.T) {
func TestFileWriter_TimeRotation(t *testing.T) {
tempDir, err := os.MkdirTemp("", "RotationTime")
require.NoError(t, err)
interval, _ := time.ParseDuration("1s")
interval, _ := time.ParseDuration("10ms")
writer, err := NewFileWriter(filepath.Join(tempDir, "test"), interval, 0, -1)
require.NoError(t, err)
defer func() { writer.Close(); os.RemoveAll(tempDir) }()
_, err = writer.Write([]byte("Hello World"))
require.NoError(t, err)
time.Sleep(1 * time.Second)
time.Sleep(interval)
_, err = writer.Write([]byte("Hello World 2"))
require.NoError(t, err)
files, _ := os.ReadDir(tempDir)
@ -45,10 +45,10 @@ func TestFileWriter_TimeRotation(t *testing.T) {
func TestFileWriter_ReopenTimeRotation(t *testing.T) {
tempDir, err := os.MkdirTemp("", "RotationTime")
require.NoError(t, err)
interval, _ := time.ParseDuration("1s")
interval, _ := time.ParseDuration("10ms")
filePath := filepath.Join(tempDir, "test.log")
err = os.WriteFile(filePath, []byte("Hello World"), 0644)
time.Sleep(1 * time.Second)
time.Sleep(interval)
assert.NoError(t, err)
writer, err := NewFileWriter(filepath.Join(tempDir, "test.log"), interval, 0, -1)
require.NoError(t, err)
@ -92,6 +92,10 @@ func TestFileWriter_ReopenSizeRotation(t *testing.T) {
}
func TestFileWriter_DeleteArchives(t *testing.T) {
if testing.Short() {
t.Skip("Skipping long test in short mode")
}
tempDir, err := os.MkdirTemp("", "RotationDeleteArchives")
require.NoError(t, err)
maxSize := int64(5)