Skip to content

Commit 0f7af7c

Browse files
committed
Tests: allow retrieving events for more than one test
Signed-off-by: Marcello Barnaba <mbarnaba@meta.com>
1 parent 6ca60a5 commit 0f7af7c

13 files changed

Lines changed: 110 additions & 104 deletions

File tree

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ require (
3131
go.uber.org/atomic v1.9.0
3232
go.uber.org/zap v1.19.1
3333
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d
34+
golang.org/x/exp v0.0.0-20230515195305-f3d0a9c9a5cc
3435
gopkg.in/yaml.v2 v2.4.0
3536
gopkg.in/yaml.v3 v3.0.1
36-
golang.org/x/exp v0.0.0-20230515195305-f3d0a9c9a5cc
3737
)
3838

3939
require (

go.sum

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,6 @@ github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
153153
github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
154154
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
155155
github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
156-
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
157156
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
158157
github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
159158
github.com/google/go-safeweb v0.0.0-20211026121254-697f59a9d57f h1:yA8MLwNYjLVI8VZn7MEfiKFBx1vuuZVPuc9fcwytiz8=
@@ -419,7 +418,6 @@ golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b/go.mod h1:QqPTAvyqsEbceGzB
419418
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
420419
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
421420
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
422-
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 h1:6zppjxzCulZykYSLyVDYbneBfbaBIQPYMevg0bEwv2s=
423421
golang.org/x/mod v0.6.0 h1:b9gGHsz9/HhJ3HF5DHQytPpuwocVTChQJK3AvoLRD5I=
424422
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
425423
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
@@ -458,8 +456,6 @@ golang.org/x/net v0.0.0-20210614182718-04defd469f4e/go.mod h1:9nx3DQGgdP8bBQD5qx
458456
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
459457
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
460458
golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
461-
golang.org/x/net v0.0.0-20220722155237-a158d28d115b h1:PxfKdU9lEEDYjdIzOtC4qFWgkU2rGHdKlKowJSMN9h0=
462-
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
463459
golang.org/x/net v0.1.0 h1:hZ/3BUoy5aId7sCpA/Tc5lt8DkFgdVS2onTpJsZ/fl0=
464460
golang.org/x/net v0.1.0/go.mod h1:Cx3nUiGt4eDBEyega/BKRp+/AlGL8hYe7U9odMt2Cco=
465461
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
@@ -534,13 +530,10 @@ golang.org/x/sys v0.0.0-20210806184541-e5e7981a1069/go.mod h1:oPkhp1MJrh7nUepCBc
534530
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
535531
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
536532
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
537-
golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10 h1:WIoqL4EROvwiPdUtaip4VcDdpZ4kha7wBWZrbVKCIZg=
538-
golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
539533
golang.org/x/sys v0.1.0 h1:kunALQeHf1/185U1i0GOB/fy1IPRDDpuoOOqRReG57U=
540534
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
541535
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
542536
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
543-
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 h1:JGgROgKl9N8DuW20oFS5gxc+lE67/N3FcwmBPMe7ArY=
544537
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
545538
golang.org/x/term v0.1.0 h1:g6Z6vPFA9dYBAF7DWcH6sCcOntplXsDKcliusYijMlw=
546539
golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
@@ -551,7 +544,6 @@ golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
551544
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
552545
golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
553546
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
554-
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
555547
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
556548
golang.org/x/text v0.4.0 h1:BrVqGRd7+k1DiOgtnFvAkoQEWQvBc25ouMJM6429SFg=
557549
golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
@@ -603,10 +595,7 @@ golang.org/x/tools v0.0.0-20200825202427-b303f430e36d/go.mod h1:njjCfa9FT2d7l9Bc
603595
golang.org/x/tools v0.0.0-20200915201639-f4cefd1cb5ba/go.mod h1:z6u4i615ZeAfBE4XtMziQW1fSVJXACjjbWkB/mvPzlU=
604596
golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
605597
golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
606-
golang.org/x/tools v0.1.12 h1:VveCTK38A2rkS8ZqFY25HIDFscX5X9OoEhJd3quQmXU=
607-
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
608598
golang.org/x/tools v0.2.0 h1:G6AHpWxTMGY1KyEYoAQ5WTtIekUUvDNjan3ugu60JvE=
609-
golang.org/x/tools v0.2.0/go.mod h1:y4OqIKeOV/fWJetJ8bXPU1sEVniLMIyDAZWeHdV+NTA=
610599
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
611600
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
612601
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=

pkg/event/testevent/test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func New(header *Header, data *Data) Event {
5454
type Query struct {
5555
event.Query
5656
RunID types.RunID
57-
TestName string
57+
TestNames []string
5858
TestStepLabel string
5959
}
6060

@@ -88,7 +88,7 @@ type queryFieldJobID types.JobID
8888
type queryFieldEventNames []event.Name
8989
type queryFieldEmittedStartTime time.Time
9090
type queryFieldEmittedEndTime time.Time
91-
type queryFieldTestName string
91+
type queryFieldTestNames []string
9292
type queryFieldTestStepLabel string
9393
type queryFieldRunID types.RunID
9494

@@ -122,10 +122,10 @@ func (value queryFieldEmittedEndTime) queryFieldPointer(query *Query) interface{
122122
}
123123

124124
// QueryTestName sets the TestName field of the Query object
125-
func QueryTestName(testName string) QueryField {
126-
return queryFieldTestName(testName)
125+
func QueryTestNames(testNames []string) QueryField {
126+
return queryFieldTestNames(testNames)
127127
}
128-
func (value queryFieldTestName) queryFieldPointer(query *Query) interface{} { return &query.TestName }
128+
func (value queryFieldTestNames) queryFieldPointer(query *Query) interface{} { return &query.TestNames }
129129

130130
// QueryTestStepLabel sets the TestStepLabel field of the Query object
131131
func QueryTestStepLabel(testStepLabel string) QueryField {

pkg/runner/base_test_suite_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,16 @@ func NewMemoryStorageEngine() (*MemoryStorageEngine, error) {
3939
}, nil
4040
}
4141

42-
func (mse *MemoryStorageEngine) GetStepEvents(ctx xcontext.Context, testName string, stepLabel string) string {
43-
return common.GetTestEventsAsString(ctx, mse.Storage, testName, nil, &stepLabel)
42+
func (mse *MemoryStorageEngine) GetStepEvents(ctx xcontext.Context, testNames []string, stepLabel string) string {
43+
return common.GetTestEventsAsString(ctx, mse.Storage, testNames, nil, &stepLabel)
4444
}
4545

46-
func (mse *MemoryStorageEngine) GetTargetEvents(ctx xcontext.Context, testName string, targetID string) string {
47-
return common.GetTestEventsAsString(ctx, mse.Storage, testName, &targetID, nil)
46+
func (mse *MemoryStorageEngine) GetTargetEvents(ctx xcontext.Context, testNames []string, targetID string) string {
47+
return common.GetTestEventsAsString(ctx, mse.Storage, testNames, &targetID, nil)
4848
}
4949

50-
func (mse *MemoryStorageEngine) GetTestEvents(ctx xcontext.Context, testName string) string {
51-
return common.GetTestEventsAsString(ctx, mse.Storage, testName, nil, nil)
50+
func (mse *MemoryStorageEngine) GetTestEvents(ctx xcontext.Context, testNames []string) string {
51+
return common.GetTestEventsAsString(ctx, mse.Storage, testNames, nil, nil)
5252
}
5353

5454
type BaseTestSuite struct {

pkg/runner/job_runner_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ func (s *JobRunnerSuite) TestSimpleJobStartFinish() {
115115
{[1 1 SimpleTest 0 test_step_label][Target{ID: "T1"} TargetIn]}
116116
{[1 1 SimpleTest 0 test_step_label][Target{ID: "T1"} TargetOut]}
117117
{[1 1 SimpleTest 0 ][Target{ID: "T1"} TargetReleased]}
118-
`, s.MemoryStorage.GetTargetEvents(ctx, testName, "T1"))
118+
`, s.MemoryStorage.GetTargetEvents(ctx, []string{testName}, "T1"))
119119
}
120120

121121
func (s *JobRunnerSuite) TestJobWithCleanupStepsStartToFinish() {
@@ -189,7 +189,7 @@ func (s *JobRunnerSuite) TestJobWithCleanupStepsStartToFinish() {
189189
{[1 1 SimpleTest 0 test_cleanup_step][Target{ID: "T1"} TargetIn]}
190190
{[1 1 SimpleTest 0 test_cleanup_step][Target{ID: "T1"} TargetOut]}
191191
{[1 1 SimpleTest 0 ][Target{ID: "T1"} TargetReleased]}
192-
`, s.MemoryStorage.GetTargetEvents(ctx, testName, "T1"))
192+
`, s.MemoryStorage.GetTargetEvents(ctx, []string{testName}, "T1"))
193193
}
194194

195195
func (s *JobRunnerSuite) TestJobWithTestRetry() {
@@ -244,7 +244,7 @@ func (s *JobRunnerSuite) TestJobWithTestRetry() {
244244
Tests: []*test.Test{
245245
{
246246
Name: testName,
247-
CleanupName: testName,
247+
CleanupName: fmt.Sprintf("%s:CLEANUP", testName),
248248
RetryParameters: test.RetryParameters{
249249
NumRetries: 1,
250250
RetryInterval: xjson.Duration(time.Millisecond), // make a small interval to test waiting branch
@@ -283,8 +283,8 @@ func (s *JobRunnerSuite) TestJobWithTestRetry() {
283283
{[1 1 SimpleTest 0 echo1_step_label][Target{ID: "T1"} TargetOut]}
284284
{[1 1 SimpleTest 0 test_step_label][Target{ID: "T1"} TargetIn]}
285285
{[1 1 SimpleTest 0 test_step_label][Target{ID: "T1"} TargetErr &"{\"Error\":\"some error\"}"]}
286-
{[1 1 SimpleTest 0 test_cleanup_step][Target{ID: "T1"} TargetIn]}
287-
{[1 1 SimpleTest 0 test_cleanup_step][Target{ID: "T1"} TargetOut]}
286+
{[1 1 SimpleTest:CLEANUP 0 test_cleanup_step][Target{ID: "T1"} TargetIn]}
287+
{[1 1 SimpleTest:CLEANUP 0 test_cleanup_step][Target{ID: "T1"} TargetOut]}
288288
{[1 1 SimpleTest 0 ][Target{ID: "T1"} TargetReleased]}
289289
{[1 1 SimpleTest 1 ][Target{ID: "T1"} TargetAcquired]}
290290
{[1 1 SimpleTest 1 echo1_step_label][Target{ID: "T1"} TargetIn]}
@@ -293,10 +293,10 @@ func (s *JobRunnerSuite) TestJobWithTestRetry() {
293293
{[1 1 SimpleTest 1 test_step_label][Target{ID: "T1"} TargetOut]}
294294
{[1 1 SimpleTest 1 echo2_step_label][Target{ID: "T1"} TargetIn]}
295295
{[1 1 SimpleTest 1 echo2_step_label][Target{ID: "T1"} TargetOut]}
296-
{[1 1 SimpleTest 1 test_cleanup_step][Target{ID: "T1"} TargetIn]}
297-
{[1 1 SimpleTest 1 test_cleanup_step][Target{ID: "T1"} TargetOut]}
296+
{[1 1 SimpleTest:CLEANUP 1 test_cleanup_step][Target{ID: "T1"} TargetIn]}
297+
{[1 1 SimpleTest:CLEANUP 1 test_cleanup_step][Target{ID: "T1"} TargetOut]}
298298
{[1 1 SimpleTest 1 ][Target{ID: "T1"} TargetReleased]}
299-
`, s.MemoryStorage.GetTargetEvents(ctx, testName, "T1"))
299+
`, s.MemoryStorage.GetTargetEvents(ctx, []string{testName, fmt.Sprintf("%s:CLEANUP", testName)}, "T1"))
300300

301301
require.Len(s.T(), reporter.runStatuses, 1)
302302
require.Len(s.T(), reporter.runStatuses[0].TestStatuses, 1)
@@ -401,7 +401,7 @@ func (s *JobRunnerSuite) TestJobRetryOnFailedAcquire() {
401401
{[1 1 SimpleTest 1 test_cleanup_step_2][Target{ID: "T1"} TargetIn]}
402402
{[1 1 SimpleTest 1 test_cleanup_step_2][Target{ID: "T1"} TargetOut]}
403403
{[1 1 SimpleTest 1 ][Target{ID: "T1"} TargetReleased]}
404-
`, s.MemoryStorage.GetTestEvents(ctx, testName))
404+
`, s.MemoryStorage.GetTestEvents(ctx, []string{testName}))
405405

406406
require.Len(s.T(), reporter.runStatuses, 1)
407407
require.Len(s.T(), reporter.runStatuses[0].TestStatuses, 1)
@@ -482,7 +482,7 @@ func (s *JobRunnerSuite) TestAcquireFailed() {
482482
require.Equal(s.T(), `
483483
{[1 1 SimpleTest 0 ][(*Target)(nil) TargetAcquireErr &"{\"Error\":\"some error\"}"]}
484484
{[1 1 SimpleTest 1 ][(*Target)(nil) TargetAcquireErr &"{\"Error\":\"some error\"}"]}
485-
`, s.MemoryStorage.GetTestEvents(ctx, testName))
485+
`, s.MemoryStorage.GetTestEvents(ctx, []string{testName}))
486486

487487
require.Len(s.T(), reporter.runStatuses, 1)
488488
require.Len(s.T(), reporter.runStatuses[0].TestStatuses, 1)

pkg/runner/job_status.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func (jr *JobRunner) buildTestStepStatus(ctx xcontext.Context, coordinates job.T
8181
testEvents, err := jr.testEvManager.Fetch(ctx,
8282
testevent.QueryJobID(coordinates.JobID),
8383
testevent.QueryRunID(coordinates.RunID),
84-
testevent.QueryTestName(coordinates.TestName),
84+
testevent.QueryTestNames([]string{coordinates.TestName}),
8585
testevent.QueryTestStepLabel(coordinates.TestStepLabel),
8686
)
8787
if err != nil {
@@ -168,7 +168,7 @@ func (jr *JobRunner) buildTestStatus(ctx xcontext.Context, coordinates job.TestC
168168
targetAcquiredEvents, err := jr.testEvManager.Fetch(ctx,
169169
testevent.QueryJobID(coordinates.JobID),
170170
testevent.QueryRunID(coordinates.RunID),
171-
testevent.QueryTestName(coordinates.TestName),
171+
testevent.QueryTestNames([]string{coordinates.TestName}),
172172
testevent.QueryEventNames([]event.Name{target.EventTargetAcquired, target.EventTargetAcquireErr}),
173173
)
174174
if err != nil {

0 commit comments

Comments
 (0)