aboutsummaryrefslogtreecommitdiffstats
path: root/dashboard/app/cache_test.go
blob: db4e1a809ba1244e291f03200062e590ef278488 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
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)
	}
}