github.com/google/syzkaller@v0.0.0-20240517125934-c0f1611a36d6/dashboard/app/cache_test.go (about) 1 // Copyright 2023 syzkaller project authors. All rights reserved. 2 // Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file. 3 4 package main 5 6 import ( 7 "testing" 8 9 "github.com/google/syzkaller/dashboard/dashapi" 10 "github.com/stretchr/testify/assert" 11 ) 12 13 func TestCachedBugGroups(t *testing.T) { 14 c := NewCtx(t) 15 defer c.Close() 16 17 client := c.makeClient(clientPublic, keyPublic, true) 18 build := testBuild(1) 19 client.UploadBuild(build) 20 21 // Bug at the first (AccessUser) stage of reporting. 22 crash := testCrash(build, 1) 23 crash.Title = "user-visible bug" 24 client.ReportCrash(crash) 25 client.pollBug() 26 27 // Bug at the second (AccessPublic) stage. 28 crash2 := testCrash(build, 2) 29 crash2.Title = "public-visible bug" 30 client.ReportCrash(crash2) 31 client.updateBug(client.pollBug().ID, dashapi.BugStatusUpstream, "") 32 client.pollBug() 33 34 // Add a build in a separate namespace (to check it's not mixed in). 35 client2 := c.makeClient(clientPublicEmail2, keyPublicEmail2, true) 36 build2 := testBuild(2) 37 client2.UploadBuild(build2) 38 client2.ReportCrash(testCrash(build2, 1)) 39 client2.pollEmailBug() 40 41 // Output before caching. 42 before := map[AccessLevel][]*uiBugGroup{} 43 for _, accessLevel := range []AccessLevel{AccessPublic, AccessUser} { 44 orig, err := fetchNamespaceBugs(c.ctx, accessLevel, "access-public", nil) 45 if err != nil { 46 t.Fatal(err) 47 } 48 assert.NotNil(t, orig) 49 before[accessLevel] = orig 50 } 51 52 // Update cache. 53 _, err := c.AuthGET(AccessAdmin, "/cron/minute_cache_update") 54 c.expectOK(err) 55 56 // Now query the groups from cache. 57 for _, accessLevel := range []AccessLevel{AccessPublic, AccessUser} { 58 cached, err := CachedBugGroups(c.ctx, "access-public", accessLevel) 59 if err != nil { 60 t.Fatal(err) 61 } 62 assert.Equal(t, before[accessLevel], cached) 63 // Ensure that the web dashboard page loads after cache is set. 64 _, err = c.AuthGET(accessLevel, "/access-public") 65 c.expectOK(err) 66 } 67 } 68 69 // Ensure we can serve pages with empty cache. 70 func TestBugListWithoutCache(t *testing.T) { 71 c := NewCtx(t) 72 defer c.Close() 73 74 assert.True(t, getNsConfig(c.ctx, "access-public").CacheUIPages) 75 for _, accessLevel := range []AccessLevel{AccessPublic, AccessUser, AccessAdmin} { 76 _, err := c.AuthGET(accessLevel, "/access-public") 77 c.expectOK(err) 78 } 79 }