aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAleksandr Nogikh <nogikh@google.com>2022-12-09 11:49:44 +0100
committerAleksandr Nogikh <wp32pw@gmail.com>2022-12-09 13:55:42 +0100
commit67be1ae742603edad9c97d30b6ed69f9bbe2ffa8 (patch)
treea1c42a22e9a0ff8f63dfd39fd4502cfc867ec316
parenta098c49a0e460e4ec2f2d3f601e499b2bd455d2f (diff)
dashboard: speed up the TestPurgeOldCrashes test()`
This test is skipped during short testing, but during the full testing it takes most of the time. At the same time, for testing purposes it's actually irrelevant whether we keep 40 or 20 crashes, so we're just wasting time. Make maxCrashes() mockable and set it to 20 during testing. This makes full testing 1.5x faster and also gives a small speed improvement for -short testing.
-rw-r--r--dashboard/app/api.go11
-rw-r--r--dashboard/app/app_test.go11
-rw-r--r--dashboard/app/entities.go1
-rw-r--r--dashboard/app/jobs.go4
-rw-r--r--dashboard/app/main.go2
-rw-r--r--dashboard/app/util_test.go5
6 files changed, 22 insertions, 12 deletions
diff --git a/dashboard/app/api.go b/dashboard/app/api.go
index 834a7c5a0..0785a7773 100644
--- a/dashboard/app/api.go
+++ b/dashboard/app/api.go
@@ -84,6 +84,11 @@ func timeSince(c context.Context, t time.Time) time.Duration {
return timeNow(c).Sub(t)
}
+var maxCrashes = func() int {
+ const maxCrashesPerBug = 40
+ return maxCrashesPerBug
+}
+
func handleJSON(fn JSONHandler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
c := appengine.NewContext(r)
@@ -732,7 +737,7 @@ func reportCrash(c context.Context, build *Build, req *dashapi.Crash) (*Bug, err
reproLevel = ReproLevelSyz
}
save := reproLevel != ReproLevelNone ||
- bug.NumCrashes < maxCrashes ||
+ bug.NumCrashes < int64(maxCrashes()) ||
now.Sub(bug.LastSavedCrash) > time.Hour ||
bug.NumCrashes%20 == 0 ||
!stringInList(bug.MergedTitles, req.Title)
@@ -856,7 +861,7 @@ func saveCrash(c context.Context, ns string, req *dashapi.Crash, bug *Bug, bugKe
func purgeOldCrashes(c context.Context, bug *Bug, bugKey *db.Key) {
const purgeEvery = 10
- if bug.NumCrashes <= 2*maxCrashes || (bug.NumCrashes-1)%purgeEvery != 0 {
+ if bug.NumCrashes <= int64(2*maxCrashes()) || (bug.NumCrashes-1)%purgeEvery != 0 {
return
}
var crashes []*Crash
@@ -900,7 +905,7 @@ func purgeOldCrashes(c context.Context, bug *Bug, bugKey *db.Key) {
if crash.ReproSyz != 0 || crash.ReproC != 0 {
count = &reproCount
}
- if *count < maxCrashes {
+ if *count < maxCrashes() {
*count++
continue
}
diff --git a/dashboard/app/app_test.go b/dashboard/app/app_test.go
index a67506e5b..26924ef47 100644
--- a/dashboard/app/app_test.go
+++ b/dashboard/app/app_test.go
@@ -596,7 +596,7 @@ func TestPurgeOldCrashes(t *testing.T) {
c.client.pollBug()
// Now report lots of bugs with/without repros. Some of the older ones should be purged.
- const totalReported = 3 * maxCrashes
+ var totalReported = 3 * maxCrashes()
for i := 0; i < totalReported; i++ {
c.advanceTime(2 * time.Hour) // This ensures that crashes are saved.
crash.ReproSyz = nil
@@ -625,10 +625,10 @@ func TestPurgeOldCrashes(t *testing.T) {
}
}
c.t.Logf("got reported=%v, norepro=%v, repro=%v, maxCrashes=%v",
- reported, norepro, repro, maxCrashes)
+ reported, norepro, repro, maxCrashes())
if reported != 3 ||
- norepro < maxCrashes || norepro > maxCrashes+10 ||
- repro < maxCrashes || repro > maxCrashes+10 {
+ norepro < maxCrashes() || norepro > maxCrashes()+10 ||
+ repro < maxCrashes() || repro > maxCrashes()+10 {
c.t.Fatalf("bad purged crashes")
}
// Then, check that latest crashes were preserved.
@@ -673,7 +673,8 @@ func TestPurgeOldCrashes(t *testing.T) {
c.expectEQ(reply.OK, true)
// Trigger more purge events.
- for i := 0; i < maxCrashes; i++ {
+ var moreIterations = maxCrashes()
+ for i := 0; i < moreIterations; i++ {
c.advanceTime(2 * time.Hour) // This ensures that crashes are saved.
crash.ReproSyz = nil
crash.ReproC = nil
diff --git a/dashboard/app/entities.go b/dashboard/app/entities.go
index a27c3f75c..96f179223 100644
--- a/dashboard/app/entities.go
+++ b/dashboard/app/entities.go
@@ -21,7 +21,6 @@ const (
maxTextLen = 200
MaxStringLen = 1024
- maxCrashes = 40
maxBugHistoryDays = 365 * 5
)
diff --git a/dashboard/app/jobs.go b/dashboard/app/jobs.go
index d2320e837..3d3db2e70 100644
--- a/dashboard/app/jobs.go
+++ b/dashboard/app/jobs.go
@@ -299,7 +299,7 @@ func handleRetestForBug(c context.Context, now time.Time, bug *Bug, bugKey *db.K
// for which we were already given fixing commits.
return nil
}
- crashes, crashKeys, err := queryCrashesForBug(c, bugKey, maxCrashes)
+ crashes, crashKeys, err := queryCrashesForBug(c, bugKey, maxCrashes())
if err != nil {
return err
}
@@ -420,7 +420,7 @@ func shouldBisectBug(bug *Bug, managers map[string]bool) bool {
func bisectCrashForBug(c context.Context, bug *Bug, bugKey *db.Key, managers map[string]bool, jobType JobType) (
*Crash, *db.Key, error) {
- crashes, crashKeys, err := queryCrashesForBug(c, bugKey, maxCrashes)
+ crashes, crashKeys, err := queryCrashesForBug(c, bugKey, maxCrashes())
if err != nil {
return nil, nil, err
}
diff --git a/dashboard/app/main.go b/dashboard/app/main.go
index 3787ec644..fb39a9fe1 100644
--- a/dashboard/app/main.go
+++ b/dashboard/app/main.go
@@ -1000,7 +1000,7 @@ func updateBugBadness(c context.Context, bug *uiBug) {
func loadCrashesForBug(c context.Context, bug *Bug) ([]*uiCrash, template.HTML, error) {
bugKey := bug.key(c)
// We can have more than maxCrashes crashes, if we have lots of reproducers.
- crashes, _, err := queryCrashesForBug(c, bugKey, 2*maxCrashes+200)
+ crashes, _, err := queryCrashesForBug(c, bugKey, 2*maxCrashes()+200)
if err != nil || len(crashes) == 0 {
return nil, "", err
}
diff --git a/dashboard/app/util_test.go b/dashboard/app/util_test.go
index 8a86918be..80f70aee9 100644
--- a/dashboard/app/util_test.go
+++ b/dashboard/app/util_test.go
@@ -525,6 +525,11 @@ func initMocks() {
getRequestContext(c).emailSink <- msg
return nil
}
+ maxCrashes = func() int {
+ // dev_appserver is very slow, so let's make tests smaller.
+ const maxCrashesDuringTest = 20
+ return maxCrashesDuringTest
+ }
}
// Machinery to associate mocked time with requests.