Skip to content

Commit

Permalink
Fix test to not sleep
Browse files Browse the repository at this point in the history
  • Loading branch information
zix99 committed Jun 12, 2022
1 parent 0b91037 commit f72dc76
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pkg/extractor/batchers/fileBatcher.go
Expand Up @@ -33,7 +33,6 @@ func OpenFilesToChan(filenames <-chan string, gunzip bool, concurrency int, batc
wg.Done()
out.stopFileReading(goFilename)
}()
out.startFileReading(goFilename)

var file io.ReadCloser
file, err := openFileToReader(goFilename, gunzip)
Expand All @@ -44,6 +43,7 @@ func OpenFilesToChan(filenames <-chan string, gunzip bool, concurrency int, batc
}
defer file.Close()

out.startFileReading(goFilename)
out.syncReaderToBatcher(goFilename, file, batchSize)
}(filename)
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/extractor/batchers/tailBatcher.go
Expand Up @@ -21,7 +21,6 @@ func TailFilesToChan(filenames <-chan string, batchSize int, reopen, poll, tail
out.stopFileReading(filename)
}()

out.startFileReading(filename)
r, err := followreader.New(filename, reopen, poll)
if err != nil {
logger.Print("Unable to open file: ", err)
Expand All @@ -35,6 +34,8 @@ func TailFilesToChan(filenames <-chan string, batchSize int, reopen, poll, tail
}
}

out.startFileReading(filename)

out.syncReaderToBatcherWithTimeFlush(filename, r, batchSize, AutoFlushTimeout)
}(filename)
}
Expand Down
6 changes: 5 additions & 1 deletion pkg/extractor/batchers/tailBatcher_test.go
Expand Up @@ -40,7 +40,9 @@ func TestBatchFollowTailFile(t *testing.T) {

batcher := TailFilesToChan(filenames, 1, false, false, true)

time.Sleep(300 * time.Millisecond) // Uhg hack cause auto-flushing
for len(batcher.activeFiles) == 0 {
time.Sleep(time.Millisecond) // Semi-hack: Wait for the go-routine reader to start and the source to be drained
}

// And write some more data
const testLines = 5
Expand All @@ -58,4 +60,6 @@ func TestBatchFollowTailFile(t *testing.T) {
assert.Len(t, batch.Batch, 1)
}
}

assert.Len(t, batcher.BatchChan(), 0)
}

0 comments on commit f72dc76

Please sign in to comment.