diff options
| author | Aleksandr Nogikh <nogikh@google.com> | 2023-10-17 14:52:17 +0200 |
|---|---|---|
| committer | Aleksandr Nogikh <nogikh@google.com> | 2023-10-23 12:07:54 +0000 |
| commit | af8d2e46418eefb127e9fa9309a63fa60ef7fc66 (patch) | |
| tree | 142d18038b84a3507742c94d84488d45c29d20e2 /dashboard/app/cache_test.go | |
| parent | 6346f51eb10624fc17701d3a24d9f35c902b29a1 (diff) | |
dashboard: optionally cache displayed bug groups
For upstream Linux namespace, it sometimes takes up to 5-10 seconds to
load the main page. That is too much and the reason for this is
datastore not being intended for frequent querying of thousands of
entities from the database.
Let's take a step forward and at least cache the bugs we display on the
main page. Once in a minute, query them for all access levels, compress
and save to the memcached.
Only do it for non-filtered bugs, because otherwise it works fast
enough.
As the next step we could also take care of terminal pages.
Diffstat (limited to 'dashboard/app/cache_test.go')
| -rw-r--r-- | dashboard/app/cache_test.go | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/dashboard/app/cache_test.go b/dashboard/app/cache_test.go new file mode 100644 index 000000000..db4e1a809 --- /dev/null +++ b/dashboard/app/cache_test.go @@ -0,0 +1,79 @@ +// Copyright 2023 syzkaller project authors. All rights reserved. +// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file. + +package main + +import ( + "testing" + + "github.com/google/syzkaller/dashboard/dashapi" + "github.com/stretchr/testify/assert" +) + +func TestCachedBugGroups(t *testing.T) { + c := NewCtx(t) + defer c.Close() + + client := c.makeClient(clientPublic, keyPublic, true) + build := testBuild(1) + client.UploadBuild(build) + + // Bug at the first (AccessUser) stage of reporting. + crash := testCrash(build, 1) + crash.Title = "user-visible bug" + client.ReportCrash(crash) + client.pollBug() + + // Bug at the second (AccessPublic) stage. + crash2 := testCrash(build, 2) + crash2.Title = "public-visible bug" + client.ReportCrash(crash2) + client.updateBug(client.pollBug().ID, dashapi.BugStatusUpstream, "") + client.pollBug() + + // Add a build in a separate namespace (to check it's not mixed in). + client2 := c.makeClient(clientPublicEmail2, keyPublicEmail2, true) + build2 := testBuild(2) + client2.UploadBuild(build2) + client2.ReportCrash(testCrash(build2, 1)) + client2.pollEmailBug() + + // Output before caching. + before := map[AccessLevel][]*uiBugGroup{} + for _, accessLevel := range []AccessLevel{AccessPublic, AccessUser} { + orig, err := fetchNamespaceBugs(c.ctx, accessLevel, "access-public", nil) + if err != nil { + t.Fatal(err) + } + assert.NotNil(t, orig) + before[accessLevel] = orig + } + + // Update cache. + _, err := c.AuthGET(AccessAdmin, "/cron/minute_cache_update") + c.expectOK(err) + + // Now query the groups from cache. + for _, accessLevel := range []AccessLevel{AccessPublic, AccessUser} { + cached, err := CachedBugGroups(c.ctx, "access-public", accessLevel) + if err != nil { + t.Fatal(err) + } + assert.Equal(t, before[accessLevel], cached) + // Ensure that the web dashboard page loads after cache is set. + _, err = c.AuthGET(accessLevel, "/access-public") + c.expectOK(err) + } +} + +// Ensure we can serve pages with empty cache. +func TestBugListWithoutCache(t *testing.T) { + c := NewCtx(t) + defer c.Close() + + assert.True(t, getNsConfig(c.ctx, "access-public").CacheUIPages) + for _, accessLevel := range []AccessLevel{AccessPublic, AccessUser, AccessAdmin} { + _, err := c.AuthGET(accessLevel, "/access-public") + c.expectOK(err) + } +} |
