Skip to content

Commit 1b5b995

Browse files
committed
make apiresourceschema e2e tests more stable
On-behalf-of: @SAP [email protected]
1 parent 28ecd45 commit 1b5b995

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

test/e2e/apiresourceschema/apiresourceschema_test.go

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -166,14 +166,20 @@ func TestARSAreNotUpdated(t *testing.T) {
166166
t.Fatalf("Failed to wait for APIResourceSchema to be created: %v", err)
167167
}
168168

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)
171180
}
172181

173182
arsName := pr.Status.ResourceSchemaName
174-
if arsName == "" {
175-
t.Fatal("Expected PublishedResource status to contain ARS name, but value is empty.")
176-
}
177183

178184
// update the CRD
179185
t.Logf("Updating CRD (same version, but new schema)…")
@@ -194,17 +200,20 @@ func TestARSAreNotUpdated(t *testing.T) {
194200
t.Fatalf("Failed to wait for 2nd APIResourceSchema to be created: %v", err)
195201
}
196202

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+
}
200208

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)
204213
}
205214

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.")
208217
}
209218
}
210219

0 commit comments

Comments
 (0)