github.com/google/syzkaller@v0.0.0-20240517125934-c0f1611a36d6/dashboard/app/commit_poll_test.go (about)

     1  // Copyright 2019 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  	"sort"
     8  	"testing"
     9  
    10  	"github.com/google/syzkaller/dashboard/dashapi"
    11  )
    12  
    13  func TestCommitPoll(t *testing.T) {
    14  	c := NewCtx(t)
    15  	defer c.Close()
    16  
    17  	build1 := testBuild(1)
    18  	c.client.UploadBuild(build1)
    19  
    20  	crash1 := testCrash(build1, 1)
    21  	c.client.ReportCrash(crash1)
    22  	rep1 := c.client.pollBug()
    23  
    24  	crash2 := testCrash(build1, 2)
    25  	c.client.ReportCrash(crash2)
    26  	rep2 := c.client.pollBug()
    27  
    28  	// No commits in commit poll.
    29  	commitPollResp, err := c.client.CommitPoll()
    30  	c.expectOK(err)
    31  	c.expectEQ(len(commitPollResp.Repos), 2)
    32  	c.expectEQ(commitPollResp.Repos[0].URL, testConfig.Namespaces["test1"].Repos[0].URL)
    33  	c.expectEQ(commitPollResp.Repos[0].Branch, testConfig.Namespaces["test1"].Repos[0].Branch)
    34  	c.expectEQ(commitPollResp.Repos[1].URL, testConfig.Namespaces["test1"].Repos[1].URL)
    35  	c.expectEQ(commitPollResp.Repos[1].Branch, testConfig.Namespaces["test1"].Repos[1].Branch)
    36  	c.expectEQ(len(commitPollResp.Commits), 0)
    37  
    38  	// Specify fixing commit for the bug.
    39  	reply, _ := c.client.ReportingUpdate(&dashapi.BugUpdate{
    40  		ID:         rep1.ID,
    41  		Status:     dashapi.BugStatusOpen,
    42  		FixCommits: []string{"foo: fix1", "foo: fix2"},
    43  	})
    44  	c.expectEQ(reply.OK, true)
    45  
    46  	// The commit should appear in commit poll.
    47  	for i := 0; i < 2; i++ {
    48  		commitPollResp, err = c.client.CommitPoll()
    49  		c.expectOK(err)
    50  		c.expectEQ(len(commitPollResp.Commits), 2)
    51  		sort.Strings(commitPollResp.Commits)
    52  		c.expectEQ(commitPollResp.Commits[0], "foo: fix1")
    53  		c.expectEQ(commitPollResp.Commits[1], "foo: fix2")
    54  	}
    55  
    56  	// Upload hash for the first commit and fixing commit for the second bug.
    57  	c.expectOK(c.client.UploadCommits([]dashapi.Commit{
    58  		{Hash: "hash1", Title: "foo: fix1"},
    59  		{Hash: "hash2", Title: "bar: fix3", BugIDs: []string{rep2.ID}},
    60  		{Hash: "hash3", Title: "some unrelated commit", BugIDs: []string{"does not exist"}},
    61  		{Hash: "hash4", Title: "another unrelated commit"},
    62  	}))
    63  
    64  	commitPollResp, err = c.client.CommitPoll()
    65  	c.expectOK(err)
    66  	c.expectEQ(len(commitPollResp.Commits), 2)
    67  	sort.Strings(commitPollResp.Commits)
    68  	c.expectEQ(commitPollResp.Commits[0], "foo: fix1")
    69  	c.expectEQ(commitPollResp.Commits[1], "foo: fix2")
    70  
    71  	// Upload hash for the second commit and a new fixing commit for the second bug.
    72  	c.expectOK(c.client.UploadCommits([]dashapi.Commit{
    73  		{Hash: "hash5", Title: "foo: fix2"},
    74  		{Title: "bar: fix4", BugIDs: []string{rep2.ID}},
    75  	}))
    76  
    77  	commitPollResp, err = c.client.CommitPoll()
    78  	c.expectOK(err)
    79  	c.expectEQ(len(commitPollResp.Commits), 1)
    80  	c.expectEQ(commitPollResp.Commits[0], "bar: fix4")
    81  
    82  	// Upload hash for the second commit and a new fixing commit for the second bug.
    83  	c.expectOK(c.client.UploadCommits([]dashapi.Commit{
    84  		{Hash: "hash1", Title: "foo: fix1"},
    85  		{Hash: "hash5", Title: "foo: fix2"},
    86  		{Hash: "hash6", Title: "bar: fix4"},
    87  	}))
    88  
    89  	commitPollResp, err = c.client.CommitPoll()
    90  	c.expectOK(err)
    91  	c.expectEQ(len(commitPollResp.Commits), 0)
    92  }