Skip to content

Commit 5205214

Browse files
committed
syz-cluster: fix stats display for non finished sessions
We could not generate the stats page when there were findings for a not yet finished session. Fix it and adjust the tests.
1 parent 1804e95 commit 5205214

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

syz-cluster/pkg/db/stats_repo.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func (repo *StatsRepository) FindingsPerWeek(ctx context.Context) (
4646
TIMESTAMP_TRUNC(Sessions.FinishedAt, WEEK) as Date,
4747
COUNT(*) as Count
4848
FROM Findings
49-
JOIN Sessions ON Sessions.ID = Findings.SessionID
49+
JOIN Sessions ON Sessions.ID = Findings.SessionID AND Sessions.FinishedAt IS NOT NULL
5050
GROUP BY Date
5151
ORDER BY Date`,
5252
})

syz-cluster/pkg/db/stats_repo_test.go

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,26 @@ func TestStatsSQLs(t *testing.T) {
1515
// That already brings a lot of value.
1616
client, ctx := NewTransientDB(t)
1717

18-
// Add some data to test field decoding as well.
18+
checkStats := func() {
19+
statsRepo := NewStatsRepository(client)
20+
_, err := statsRepo.ProcessedSeriesPerWeek(ctx)
21+
assert.NoError(t, err)
22+
_, err = statsRepo.FindingsPerWeek(ctx)
23+
assert.NoError(t, err)
24+
_, err = statsRepo.SessionStatusPerWeek(ctx)
25+
assert.NoError(t, err)
26+
_, err = statsRepo.DelayPerWeek(ctx)
27+
assert.NoError(t, err)
28+
}
29+
1930
dtd := &dummyTestData{t, ctx, client}
2031
session := dtd.dummySession(dtd.dummySeries())
32+
checkStats()
2133
dtd.startSession(session)
34+
dtd.addSessionTest(session, "test")
35+
checkStats()
36+
dtd.addFinding(session, "test", "test")
37+
checkStats()
2238
dtd.finishSession(session)
23-
24-
statsRepo := NewStatsRepository(client)
25-
_, err := statsRepo.ProcessedSeriesPerWeek(ctx)
26-
assert.NoError(t, err)
27-
_, err = statsRepo.FindingsPerWeek(ctx)
28-
assert.NoError(t, err)
29-
_, err = statsRepo.SessionStatusPerWeek(ctx)
30-
assert.NoError(t, err)
31-
_, err = statsRepo.DelayPerWeek(ctx)
32-
assert.NoError(t, err)
39+
checkStats()
3340
}

0 commit comments

Comments
 (0)