@@ -166,14 +166,20 @@ func TestARSAreNotUpdated(t *testing.T) {
166
166
t .Fatalf ("Failed to wait for APIResourceSchema to be created: %v" , err )
167
167
}
168
168
169
- if err := envtestClient .Get (ctx , ctrlruntimeclient .ObjectKeyFromObject (pr ), pr ); err != nil {
170
- t .Fatalf ("Failed to fetch PublishedResource: %v" , err )
169
+ // prevent race condition of the controller first creating the ARS, then updating the PR,
170
+ // by waiting again for the status to be updated.
171
+ err = wait .PollUntilContextTimeout (ctx , 500 * time .Millisecond , 30 * time .Second , false , func (ctx context.Context ) (done bool , err error ) {
172
+ if err := envtestClient .Get (ctx , ctrlruntimeclient .ObjectKeyFromObject (pr ), pr ); err != nil {
173
+ return false , nil
174
+ }
175
+
176
+ return pr .Status .ResourceSchemaName != "" , nil
177
+ })
178
+ if err != nil {
179
+ t .Fatalf ("Failed to wait for PublishedResource status to be updated: %v" , err )
171
180
}
172
181
173
182
arsName := pr .Status .ResourceSchemaName
174
- if arsName == "" {
175
- t .Fatal ("Expected PublishedResource status to contain ARS name, but value is empty." )
176
- }
177
183
178
184
// update the CRD
179
185
t .Logf ("Updating CRD (same version, but new schema)…" )
@@ -194,17 +200,20 @@ func TestARSAreNotUpdated(t *testing.T) {
194
200
t .Fatalf ("Failed to wait for 2nd APIResourceSchema to be created: %v" , err )
195
201
}
196
202
197
- if err := envtestClient .Get (ctx , ctrlruntimeclient .ObjectKeyFromObject (pr ), pr ); err != nil {
198
- t .Fatalf ("Failed to fetch PublishedResource: %v" , err )
199
- }
203
+ // wait for the status to contain the new ARS name
204
+ err = wait .PollUntilContextTimeout (ctx , 500 * time .Millisecond , 1 * time .Minute , false , func (ctx context.Context ) (done bool , err error ) {
205
+ if err := envtestClient .Get (ctx , ctrlruntimeclient .ObjectKeyFromObject (pr ), pr ); err != nil {
206
+ return false , nil
207
+ }
200
208
201
- newARSName := pr .Status .ResourceSchemaName
202
- if newARSName == "" {
203
- t .Fatal ("Expected PublishedResource status to contain ARS name, but value is empty." )
209
+ return pr .Status .ResourceSchemaName != arsName , nil
210
+ })
211
+ if err != nil {
212
+ t .Fatalf ("Failed to wait for PublishedResource status to be updated: %v" , err )
204
213
}
205
214
206
- if newARSName == arsName {
207
- t .Fatalf ("Expected PublishedResource status to have been updated with new ARS name, but still contains %q." , arsName )
215
+ if pr . Status . ResourceSchemaName == "" {
216
+ t .Fatal ("Expected PublishedResource status to contain ARS name, but value is empty." )
208
217
}
209
218
}
210
219
0 commit comments