Fix keeping matches in the report history

This commit is contained in:
Ingo Oppermann
2023-04-17 15:03:25 +02:00
parent 76abf5474f
commit 78686c81f4
4 changed files with 48 additions and 14 deletions

View File

@@ -877,7 +877,6 @@ func (p *parser) storeReportHistory(state string) {
history := r.Value.(ReportHistoryEntry)
history.Log = nil
history.Prelude = nil
history.Matches = nil
r.Value = history
}

View File

@@ -883,23 +883,35 @@ func TestParserProgressPlayout(t *testing.T) {
}
func TestParserPatterns(t *testing.T) {
parser := New(Config{
p := New(Config{
LogHistory: 3,
Patterns: []string{
"^foobar",
"foobar$",
},
})
parser.Parse("some foobar more")
require.Empty(t, parser.Report().Matches)
p.Parse("some foobar more")
require.Empty(t, p.Report().Matches)
parser.Parse("foobar some more")
require.Equal(t, 1, len(parser.Report().Matches))
require.Equal(t, "foobar some more", parser.Report().Matches[0])
p.Parse("foobar some more")
require.Equal(t, 1, len(p.Report().Matches))
require.Equal(t, "foobar some more", p.Report().Matches[0])
parser.Parse("some more foobar")
require.Equal(t, 2, len(parser.Report().Matches))
require.Equal(t, "some more foobar", parser.Report().Matches[1])
p.Parse("some more foobar")
require.Equal(t, 2, len(p.Report().Matches))
require.Equal(t, "some more foobar", p.Report().Matches[1])
pp, ok := p.(*parser)
require.True(t, ok)
pp.storeReportHistory("something")
report := p.ReportHistory()
require.Equal(t, 1, len(report))
require.Equal(t, 2, len(report[0].Matches))
require.Equal(t, "foobar some more", report[0].Matches[0])
require.Equal(t, "some more foobar", report[0].Matches[1])
}
func TestParserPatternsError(t *testing.T) {

View File

@@ -49,6 +49,7 @@ func (report *ProcessReport) Unmarshal(l *app.Log) {
CreatedAt: h.CreatedAt.Unix(),
Prelude: h.Prelude,
Log: make([][2]string, len(h.Log)),
Matches: h.Matches,
ExitedAt: h.ExitedAt.Unix(),
ExitState: h.ExitState,
}

View File

@@ -25,10 +25,11 @@ func getDummyRestreamer(portrange net.Portranger, validatorIn, validatorOut ffmp
}
ffmpeg, err := ffmpeg.New(ffmpeg.Config{
Binary: binary,
Portrange: portrange,
ValidatorInput: validatorIn,
ValidatorOutput: validatorOut,
Binary: binary,
Portrange: portrange,
ValidatorInput: validatorIn,
ValidatorOutput: validatorOut,
LogHistoryLength: 3,
})
if err != nil {
return nil, err
@@ -404,6 +405,27 @@ func TestReloadProcess(t *testing.T) {
rs.StopProcess(process.ID)
}
func TestParseProcessPattern(t *testing.T) {
rs, err := getDummyRestreamer(nil, nil, nil, nil)
require.NoError(t, err)
process := getDummyProcess()
process.LogPatterns = []string{"libx264"}
rs.AddProcess(process)
rs.StartProcess(process.ID)
time.Sleep(3 * time.Second)
rs.StopProcess(process.ID)
log, err := rs.GetProcessLog(process.ID)
require.NoError(t, err)
require.Equal(t, 1, len(log.History))
require.Equal(t, 8, len(log.History[0].Matches))
}
func TestProbeProcess(t *testing.T) {
rs, err := getDummyRestreamer(nil, nil, nil, nil)
require.NoError(t, err)