mirror of
https://github.com/kubernetes/node-problem-detector.git
synced 2026-02-26 07:43:58 +00:00
fix test issue
This commit is contained in:
@@ -168,15 +168,10 @@ func (k *kernelLogWatcher) watchLoop() {
|
||||
|
||||
// getLogReader gets a kernel log reader.
|
||||
func getLogReader(path string) (io.Reader, error) {
|
||||
reader, err := tryJournal()
|
||||
if err == nil {
|
||||
return reader, nil
|
||||
if len(path) != 0 {
|
||||
return tryLogFile(path)
|
||||
}
|
||||
reader, err = tryLogFile(path)
|
||||
if err == nil {
|
||||
return reader, nil
|
||||
}
|
||||
return nil, err
|
||||
return tryJournal()
|
||||
}
|
||||
|
||||
func tryJournal() (io.Reader, error) {
|
||||
@@ -205,6 +200,7 @@ func tryLogFile(path string) (io.Reader, error) {
|
||||
return nil, err
|
||||
}
|
||||
glog.Infof("Kernel log watcher use log file: %s", path)
|
||||
time.Sleep(1000 * time.Millisecond)
|
||||
return tail, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -100,13 +100,15 @@ func TestWatch(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer func() {
|
||||
f.Close()
|
||||
os.Remove(f.Name())
|
||||
}()
|
||||
_, err = f.Write([]byte(test.log))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
f.Close()
|
||||
|
||||
w := NewKernelLogWatcher(WatcherConfig{KernelLogPath: f.Name(), Lookback: test.lookback})
|
||||
// Set the fake clock.
|
||||
w.(*kernelLogWatcher).clock = fakeClock
|
||||
|
||||
Reference in New Issue
Block a user