@@ -31,7 +31,7 @@ func TestDownloadTaskLogs(t *testing.T) {
31
31
testCases := []struct {
32
32
treePath string
33
33
fileContent string
34
- outcome * mockTaskOutcome
34
+ outcome [] * mockTaskOutcome
35
35
zstdEnabled bool
36
36
}{
37
37
{
@@ -46,21 +46,44 @@ jobs:
46
46
runs-on: ubuntu-latest
47
47
steps:
48
48
- run: echo job1 with zstd enabled
49
+ job2:
50
+ runs-on: ubuntu-latest
51
+ steps:
52
+ - run: echo job2 with zstd enabled
49
53
` ,
50
- outcome : & mockTaskOutcome {
51
- result : runnerv1 .Result_RESULT_SUCCESS ,
52
- logRows : []* runnerv1.LogRow {
53
- {
54
- Time : timestamppb .New (now .Add (1 * time .Second )),
55
- Content : " \U0001F433 docker create image" ,
56
- },
57
- {
58
- Time : timestamppb .New (now .Add (2 * time .Second )),
59
- Content : "job1 zstd enabled" ,
54
+ outcome : []* mockTaskOutcome {
55
+ {
56
+ result : runnerv1 .Result_RESULT_SUCCESS ,
57
+ logRows : []* runnerv1.LogRow {
58
+ {
59
+ Time : timestamppb .New (now .Add (1 * time .Second )),
60
+ Content : " \U0001F433 docker create image" ,
61
+ },
62
+ {
63
+ Time : timestamppb .New (now .Add (2 * time .Second )),
64
+ Content : "job1 zstd enabled" ,
65
+ },
66
+ {
67
+ Time : timestamppb .New (now .Add (3 * time .Second )),
68
+ Content : "\U0001F3C1 Job succeeded" ,
69
+ },
60
70
},
61
- {
62
- Time : timestamppb .New (now .Add (3 * time .Second )),
63
- Content : "\U0001F3C1 Job succeeded" ,
71
+ },
72
+ {
73
+ result : runnerv1 .Result_RESULT_SUCCESS ,
74
+ logRows : []* runnerv1.LogRow {
75
+ {
76
+ Time : timestamppb .New (now .Add (1 * time .Second )),
77
+ Content : " \U0001F433 docker create image" ,
78
+ },
79
+ {
80
+ Time : timestamppb .New (now .Add (2 * time .Second )),
81
+ Content : "job2 zstd enabled" ,
82
+ },
83
+ {
84
+ Time : timestamppb .New (now .Add (3 * time .Second )),
85
+ Content : "\U0001F3C1 Job succeeded" ,
86
+ },
64
87
},
65
88
},
66
89
},
@@ -78,21 +101,44 @@ jobs:
78
101
runs-on: ubuntu-latest
79
102
steps:
80
103
- run: echo job1 with zstd disabled
104
+ job2:
105
+ runs-on: ubuntu-latest
106
+ steps:
107
+ - run: echo job2 with zstd disabled
81
108
` ,
82
- outcome : & mockTaskOutcome {
83
- result : runnerv1 .Result_RESULT_SUCCESS ,
84
- logRows : []* runnerv1.LogRow {
85
- {
86
- Time : timestamppb .New (now .Add (4 * time .Second )),
87
- Content : " \U0001F433 docker create image" ,
109
+ outcome : []* mockTaskOutcome {
110
+ {
111
+ result : runnerv1 .Result_RESULT_SUCCESS ,
112
+ logRows : []* runnerv1.LogRow {
113
+ {
114
+ Time : timestamppb .New (now .Add (4 * time .Second )),
115
+ Content : " \U0001F433 docker create image" ,
116
+ },
117
+ {
118
+ Time : timestamppb .New (now .Add (5 * time .Second )),
119
+ Content : "job1 zstd disabled" ,
120
+ },
121
+ {
122
+ Time : timestamppb .New (now .Add (6 * time .Second )),
123
+ Content : "\U0001F3C1 Job succeeded" ,
124
+ },
88
125
},
89
- {
90
- Time : timestamppb .New (now .Add (5 * time .Second )),
91
- Content : "job1 zstd disabled" ,
92
- },
93
- {
94
- Time : timestamppb .New (now .Add (6 * time .Second )),
95
- Content : "\U0001F3C1 Job succeeded" ,
126
+ },
127
+ {
128
+ result : runnerv1 .Result_RESULT_SUCCESS ,
129
+ logRows : []* runnerv1.LogRow {
130
+ {
131
+ Time : timestamppb .New (now .Add (4 * time .Second )),
132
+ Content : " \U0001F433 docker create image" ,
133
+ },
134
+ {
135
+ Time : timestamppb .New (now .Add (5 * time .Second )),
136
+ Content : "job2 zstd disabled" ,
137
+ },
138
+ {
139
+ Time : timestamppb .New (now .Add (6 * time .Second )),
140
+ Content : "\U0001F3C1 Job succeeded" ,
141
+ },
96
142
},
97
143
},
98
144
},
@@ -124,54 +170,55 @@ jobs:
124
170
opts := getWorkflowCreateFileOptions (user2 , repo .DefaultBranch , fmt .Sprintf ("create %s" , tc .treePath ), tc .fileContent )
125
171
createWorkflowFile (t , token , user2 .Name , repo .Name , tc .treePath , opts )
126
172
127
- // fetch and execute task
128
- task := runner .fetchTask (t )
129
- runner .execTask (t , task , tc .outcome )
173
+ // fetch and execute tasks
174
+ for jobIndex , outcome := range tc .outcome {
175
+ task := runner .fetchTask (t )
176
+ runner .execTask (t , task , outcome )
130
177
131
- // check whether the log file exists
132
- logFileName := fmt .Sprintf ("%s/%02x/%d.log" , repo .FullName (), task .Id % 256 , task .Id )
133
- if setting .Actions .LogCompression .IsZstd () {
134
- logFileName += ".zst"
135
- }
136
- _ , err := storage .Actions .Stat (logFileName )
137
- assert .NoError (t , err )
178
+ // check whether the log file exists
179
+ logFileName := fmt .Sprintf ("%s/%02x/%d.log" , repo .FullName (), task .Id % 256 , task .Id )
180
+ if setting .Actions .LogCompression .IsZstd () {
181
+ logFileName += ".zst"
182
+ }
183
+ _ , err := storage .Actions .Stat (logFileName )
184
+ assert .NoError (t , err )
138
185
139
- // download task logs and check content
140
- runIndex := task .Context .GetFields ()["run_number" ].GetStringValue ()
141
- req := NewRequest (t , "GET" , fmt .Sprintf ("/%s/%s/actions/runs/%s/jobs/0 /logs" , user2 .Name , repo .Name , runIndex )).
142
- AddTokenAuth (token )
143
- resp := MakeRequest (t , req , http .StatusOK )
144
- logTextLines := strings .Split (strings .TrimSpace (resp .Body .String ()), "\n " )
145
- assert .Len (t , logTextLines , len (tc . outcome .logRows ))
146
- for idx , lr := range tc . outcome .logRows {
147
- assert .Equal (
148
- t ,
149
- fmt .Sprintf ("%s %s" , lr .Time .AsTime ().Format ("2006-01-02T15:04:05.0000000Z07:00" ), lr .Content ),
150
- logTextLines [idx ],
151
- )
152
- }
186
+ // download task logs and check content
187
+ runIndex := task .Context .GetFields ()["run_number" ].GetStringValue ()
188
+ req := NewRequest (t , "GET" , fmt .Sprintf ("/%s/%s/actions/runs/%s/jobs/%d /logs" , user2 .Name , repo .Name , runIndex , jobIndex )).
189
+ AddTokenAuth (token )
190
+ resp := MakeRequest (t , req , http .StatusOK )
191
+ logTextLines := strings .Split (strings .TrimSpace (resp .Body .String ()), "\n " )
192
+ assert .Len (t , logTextLines , len (outcome .logRows ))
193
+ for idx , lr := range outcome .logRows {
194
+ assert .Equal (
195
+ t ,
196
+ fmt .Sprintf ("%s %s" , lr .Time .AsTime ().Format ("2006-01-02T15:04:05.0000000Z07:00" ), lr .Content ),
197
+ logTextLines [idx ],
198
+ )
199
+ }
153
200
154
- runID , _ := strconv .ParseInt (task .Context .GetFields ()["run_id" ].GetStringValue (), 10 , 64 )
201
+ runID , _ := strconv .ParseInt (task .Context .GetFields ()["run_id" ].GetStringValue (), 10 , 64 )
155
202
156
- jobs , err := actions_model .GetRunJobsByRunID (t .Context (), runID )
157
- assert .NoError (t , err )
158
- assert .Len (t , jobs , 1 )
159
- jobID := jobs [0 ].ID
203
+ jobs , err := actions_model .GetRunJobsByRunID (t .Context (), runID )
204
+ assert .NoError (t , err )
205
+ assert .Len (t , jobs , len ( tc . outcome ) )
206
+ jobID := jobs [jobIndex ].ID
160
207
161
- // download task logs from API and check content
162
- req = NewRequest (t , "GET" , fmt .Sprintf ("/api/v1/repos/%s/%s/actions/jobs/%d/logs" , user2 .Name , repo .Name , jobID )).
163
- AddTokenAuth (token )
164
- resp = MakeRequest (t , req , http .StatusOK )
165
- logTextLines = strings .Split (strings .TrimSpace (resp .Body .String ()), "\n " )
166
- assert .Len (t , logTextLines , len (tc .outcome .logRows ))
167
- for idx , lr := range tc .outcome .logRows {
168
- assert .Equal (
169
- t ,
170
- fmt .Sprintf ("%s %s" , lr .Time .AsTime ().Format ("2006-01-02T15:04:05.0000000Z07:00" ), lr .Content ),
171
- logTextLines [idx ],
172
- )
208
+ // download task logs from API and check content
209
+ req = NewRequest (t , "GET" , fmt .Sprintf ("/api/v1/repos/%s/%s/actions/jobs/%d/logs" , user2 .Name , repo .Name , jobID )).
210
+ AddTokenAuth (token )
211
+ resp = MakeRequest (t , req , http .StatusOK )
212
+ logTextLines = strings .Split (strings .TrimSpace (resp .Body .String ()), "\n " )
213
+ assert .Len (t , logTextLines , len (outcome .logRows ))
214
+ for idx , lr := range outcome .logRows {
215
+ assert .Equal (
216
+ t ,
217
+ fmt .Sprintf ("%s %s" , lr .Time .AsTime ().Format ("2006-01-02T15:04:05.0000000Z07:00" ), lr .Content ),
218
+ logTextLines [idx ],
219
+ )
220
+ }
173
221
}
174
-
175
222
resetFunc ()
176
223
})
177
224
}
0 commit comments