Skip to content

Commit

Permalink
Fix sporadic test failures (#192)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nuckal777 authored Dec 5, 2024
1 parent a446c36 commit 9ba115a
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 25 deletions.
18 changes: 2 additions & 16 deletions internal/controller/bmc_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@ import (
var _ = Describe("BMC Controller", func() {
_ = SetupTest()

var endpoint *metalv1alpha1.Endpoint

BeforeEach(func(ctx SpecContext) {
It("Should successfully reconcile the a BMC resource", func(ctx SpecContext) {
By("Creating an Endpoints object")
endpoint = &metalv1alpha1.Endpoint{
endpoint := &metalv1alpha1.Endpoint{
ObjectMeta: metav1.ObjectMeta{
GenerateName: "test-",
},
Expand Down Expand Up @@ -57,15 +55,8 @@ var _ = Describe("BMC Controller", func() {
},
}
DeferCleanup(k8sClient.Delete, server)
})

It("Should successfully reconcile the a BMC resource", func(ctx SpecContext) {
By("Ensuring that the BMC resource has been created for an endpoint")
bmc := &metalv1alpha1.BMC{
ObjectMeta: metav1.ObjectMeta{
Name: endpoint.Name,
},
}
Eventually(Object(bmc)).Should(SatisfyAll(
HaveField("OwnerReferences", ContainElement(metav1.OwnerReference{
APIVersion: "metal.ironcore.dev/v1alpha1",
Expand All @@ -84,11 +75,6 @@ var _ = Describe("BMC Controller", func() {
))

By("Ensuring that the Server resource has been created")
server := &metalv1alpha1.Server{
ObjectMeta: metav1.ObjectMeta{
Name: GetServerNameFromBMCandIndex(0, bmc),
},
}
Eventually(Object(server)).Should(SatisfyAll(
HaveField("OwnerReferences", ContainElement(metav1.OwnerReference{
APIVersion: "metal.ironcore.dev/v1alpha1",
Expand Down
2 changes: 1 addition & 1 deletion internal/controller/server_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func (r *ServerReconciler) reconcile(ctx context.Context, log logr.Logger, serve
if err := r.updateServerStatus(ctx, log, server); err != nil {
return ctrl.Result{}, fmt.Errorf("failed to update server status: %w", err)
}
log.V(1).Info("Updated Server status")
log.V(1).Info("Updated Server status", "Status", server.Status.State)

if err := r.applyBiosSettings(ctx, log, server); err != nil {
return ctrl.Result{}, fmt.Errorf("failed to update server bios settings: %w", err)
Expand Down
11 changes: 4 additions & 7 deletions internal/controller/server_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,9 @@ import (
var _ = Describe("Server Controller", func() {
ns := SetupTest()

var endpoint *metalv1alpha1.Endpoint
var bmc *metalv1alpha1.BMC

It("Should initialize a Server from Endpoint", func(ctx SpecContext) {
By("Creating an Endpoint object")
endpoint = &metalv1alpha1.Endpoint{
endpoint := &metalv1alpha1.Endpoint{
ObjectMeta: metav1.ObjectMeta{
GenerateName: "test-",
},
Expand All @@ -44,7 +41,7 @@ var _ = Describe("Server Controller", func() {
DeferCleanup(k8sClient.Delete, endpoint)

By("Ensuring that the BMC resource has been created for an endpoint")
bmc = &metalv1alpha1.BMC{
bmc := &metalv1alpha1.BMC{
ObjectMeta: metav1.ObjectMeta{
Name: endpoint.Name,
},
Expand Down Expand Up @@ -273,12 +270,12 @@ var _ = Describe("Server Controller", func() {
))

By("Ensuring that the server is set back to initial due to the discovery check timing out")
Eventually(Object(server), "1000ms").Should(SatisfyAll(
Eventually(Object(server)).Should(SatisfyAll(
HaveField("Status.State", metalv1alpha1.ServerStateInitial),
))

By("Starting the probe agent")
probeAgent := probe.NewAgent(server.Spec.UUID, registryURL, 100*time.Millisecond)
probeAgent := probe.NewAgent(server.Spec.UUID, registryURL, 50*time.Millisecond)
go func() {
defer GinkgoRecover()
Expect(probeAgent.Start(ctx)).To(Succeed(), "failed to start probe agent")
Expand Down
2 changes: 1 addition & 1 deletion internal/controller/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func SetupTest() *corev1.Namespace {
ProbeOSImage: "fooOS:latest",
RegistryURL: registryURL,
RegistryResyncInterval: 50 * time.Millisecond,
ResyncInterval: 100 * time.Millisecond,
ResyncInterval: 50 * time.Millisecond,
EnforceFirstBoot: true,
BMCOptions: bmc.BMCOptions{
PowerPollingInterval: 50 * time.Millisecond,
Expand Down

0 comments on commit 9ba115a

Please sign in to comment.