Skip to content

Commit 9e9a66f

Browse files
committed
roachtest: refactor createPostRequest to include necessary params
This change refactors createPostRequest in two ways: - It adds two new time.Time parameters, setting up work for populating the testeng Grafana link. - Error handling by invoking t.Fatalf has been replaced with returning an `error`.
1 parent 73f51aa commit 9e9a66f

File tree

2 files changed

+26
-14
lines changed

2 files changed

+26
-14
lines changed

pkg/cmd/roachtest/github.go

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"context"
1515
"fmt"
1616
"os"
17+
"time"
1718

1819
"github.com/cockroachdb/cockroach/pkg/cmd/internal/issues"
1920
"github.com/cockroachdb/cockroach/pkg/cmd/roachtest/registry"
@@ -98,14 +99,18 @@ func (g *githubIssues) shouldPost(t test.Test) (bool, string) {
9899
}
99100

100101
func (g *githubIssues) createPostRequest(
101-
t test.Test, firstFailure failure, message string,
102-
) issues.PostRequest {
102+
testName string,
103+
start time.Time,
104+
end time.Time,
105+
spec *registry.TestSpec,
106+
firstFailure failure,
107+
message string,
108+
) (issues.PostRequest, error) {
103109
var mention []string
104110
var projColID int
105111

106-
spec := t.Spec().(*registry.TestSpec)
107112
issueOwner := spec.Owner
108-
issueName := t.Name()
113+
issueName := testName
109114

110115
messagePrefix := ""
111116
var infraFlake bool
@@ -114,15 +119,15 @@ func (g *githubIssues) createPostRequest(
114119
case failureContainsError(firstFailure, errClusterProvisioningFailed):
115120
issueOwner = registry.OwnerDevInf
116121
issueName = "cluster_creation"
117-
messagePrefix = fmt.Sprintf("test %s was skipped due to ", t.Name())
122+
messagePrefix = fmt.Sprintf("test %s was skipped due to ", testName)
118123
infraFlake = true
119124
case failureContainsError(firstFailure, rperrors.ErrSSH255):
120125
issueOwner = registry.OwnerTestEng
121126
issueName = "ssh_problem"
122-
messagePrefix = fmt.Sprintf("test %s failed due to ", t.Name())
127+
messagePrefix = fmt.Sprintf("test %s failed due to ", testName)
123128
infraFlake = true
124129
case failureContainsError(firstFailure, errDuringPostAssertions):
125-
messagePrefix = fmt.Sprintf("test %s failed during post test assertions (see test-post-assertions.log) due to ", t.Name())
130+
messagePrefix = fmt.Sprintf("test %s failed during post test assertions (see test-post-assertions.log) due to ", testName)
126131
}
127132

128133
// Issues posted from roachtest are identifiable as such, and they are also release blockers
@@ -134,7 +139,7 @@ func (g *githubIssues) createPostRequest(
134139

135140
teams, err := g.teamLoader()
136141
if err != nil {
137-
t.Fatalf("could not load teams: %v", err)
142+
return issues.PostRequest{}, err
138143
}
139144

140145
if sl, ok := teams.GetAliasesForPurpose(ownerToAlias(issueOwner), team.PurposeRoachtest); ok {
@@ -152,7 +157,7 @@ func (g *githubIssues) createPostRequest(
152157
branch = "<unknown branch>"
153158
}
154159

155-
artifacts := fmt.Sprintf("/%s", t.Name())
160+
artifacts := fmt.Sprintf("/%s", testName)
156161

157162
clusterParams := map[string]string{
158163
roachtestPrefix("cloud"): spec.Cluster.Cloud,
@@ -202,7 +207,7 @@ func (g *githubIssues) createPostRequest(
202207
"https://cockroachlabs.atlassian.net/l/c/SSSBr8c7",
203208
)(renderer)
204209
},
205-
}
210+
}, nil
206211
}
207212

208213
func (g *githubIssues) MaybePost(t *testImpl, l *logger.Logger, message string) error {
@@ -212,10 +217,15 @@ func (g *githubIssues) MaybePost(t *testImpl, l *logger.Logger, message string)
212217
return nil
213218
}
214219

220+
postRequest, err := g.createPostRequest(t.Name(), t.start, t.end, t.spec, t.firstFailure(), message)
221+
if err != nil {
222+
return err
223+
}
224+
215225
return g.issuePoster(
216226
context.Background(),
217227
l,
218228
issues.UnitTestFormatter,
219-
g.createPostRequest(t, t.firstFailure(), message),
229+
postRequest,
220230
)
221231
}

pkg/cmd/roachtest/github_test.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,10 +200,12 @@ func TestCreatePostRequest(t *testing.T) {
200200
}
201201

202202
if c.loadTeamsFailed {
203-
// Assert that if TEAMS.yaml cannot be loaded then function panics.
204-
assert.Panics(t, func() { github.createPostRequest(ti, c.failure, "message") })
203+
// Assert that if TEAMS.yaml cannot be loaded then function errors.
204+
_, err := github.createPostRequest("github_test", ti.start, ti.end, testSpec, c.failure, "message")
205+
assert.Error(t, err, "Expected an error in createPostRequest when loading teams fails, but got nil")
205206
} else {
206-
req := github.createPostRequest(ti, c.failure, "message")
207+
req, err := github.createPostRequest("github_test", ti.start, ti.end, testSpec, c.failure, "message")
208+
assert.NoError(t, err, "Expected no error in createPostRequest")
207209

208210
if c.expectedParams != nil {
209211
require.Equal(t, c.expectedParams, req.ExtraParams)

0 commit comments

Comments
 (0)