Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unit test for controller #250

Open
praveenkumar opened this issue Feb 3, 2023 · 10 comments
Open

Fix unit test for controller #250

praveenkumar opened this issue Feb 3, 2023 · 10 comments
Labels
lifecycle/frozen Indicates that an issue or PR should not be auto-closed due to staleness.

Comments

@praveenkumar
Copy link
Contributor

With #249 the actuator tests are failing like below and this issue is to track so we can fix it later in time. As of now priority is to update latest machine api and vendoring part.

$ make test
 go test -race -cover ./cmd/... ./pkg/cloud/...
?   	github.com/openshift/cluster-api-provider-libvirt/cmd/manager	[no test files]
E0131 15:06:10.408695   14100 actuator.go:107] Machine error: error getting machineProviderConfig from spec: no Value in ProviderConfig
E0131 15:06:10.411129   14100 actuator.go:107] Machine error: error creating libvirt client: error creating libvirt client
E0131 15:06:10.412790   14100 actuator.go:107] Machine error: error creating volume error
E0131 15:06:10.412874   14100 actuator.go:51] libvirt-actuator-testing-machine: error creating libvirt machine: error creating volume error
E0131 15:06:10.414281   14100 actuator.go:107] Machine error: error creating domain error
E0131 15:06:10.414341   14100 actuator.go:51] libvirt-actuator-testing-machine: error creating libvirt machine: error creating domain error
E0131 15:06:10.415850   14100 actuator.go:107] Machine error: error looking up libvirt machine error
E0131 15:06:10.415920   14100 actuator.go:51] libvirt-actuator-testing-machine: error creating libvirt machine: error looking up libvirt machine error
E0131 15:06:10.420175   14100 actuator.go:107] Machine error: error getting machineProviderConfig from spec: no Value in ProviderConfig
E0131 15:06:10.421666   14100 actuator.go:107] Machine error: error creating libvirt client: error creating libvirt client
E0131 15:06:10.423274   14100 actuator.go:107] Machine error: error checking for domain existence: error
E0131 15:06:10.426872   14100 actuator.go:107] Machine error: error deleting "libvirt-actuator-testing-machine" domain error
E0131 15:06:10.429808   14100 actuator.go:107] Machine error: error deleting "libvirt-actuator-testing-machine" volume error
--- FAIL: TestMachineEvents (0.03s)
    --- FAIL: TestMachineEvents/Create_machine_event_failed_(invalid_configuration) (0.00s)
        controller.go:137: missing call(s) to *mock.MockClient.Close() /go/src/github.com/openshift/cluster-api-provider-libvirt/pkg/cloud/libvirt/actuators/machine/actuator_test.go:193
        controller.go:137: missing call(s) to *mock.MockClient.GetDHCPLeasesByNetwork(is anything) /go/src/github.com/openshift/cluster-api-provider-libvirt/pkg/cloud/libvirt/actuators/machine/actuator_test.go:198
        controller.go:137: aborting test due to missing call(s)
    --- FAIL: TestMachineEvents/Create_machine_event_failed_(error_creating_libvirt_client) (0.00s)
        controller.go:137: missing call(s) to *mock.MockClient.GetDHCPLeasesByNetwork(is anything) /go/src/github.com/openshift/cluster-api-provider-libvirt/pkg/cloud/libvirt/actuators/machine/actuator_test.go:198
        controller.go:137: missing call(s) to *mock.MockClient.Close() /go/src/github.com/openshift/cluster-api-provider-libvirt/pkg/cloud/libvirt/actuators/machine/actuator_test.go:193
        controller.go:137: aborting test due to missing call(s)
    --- FAIL: TestMachineEvents/Delete_machine_event_failed_(invalid_configuration) (0.00s)
        controller.go:137: missing call(s) to *mock.MockClient.GetDHCPLeasesByNetwork(is anything) /go/src/github.com/openshift/cluster-api-provider-libvirt/pkg/cloud/libvirt/actuators/machine/actuator_test.go:198
        controller.go:137: missing call(s) to *mock.MockClient.Close() /go/src/github.com/openshift/cluster-api-provider-libvirt/pkg/cloud/libvirt/actuators/machine/actuator_test.go:193
        controller.go:137: aborting test due to missing call(s)
    --- FAIL: TestMachineEvents/Delete_machine_event_failed_(error_creating_libvirt_client) (0.00s)
        controller.go:137: missing call(s) to *mock.MockClient.Close() /go/src/github.com/openshift/cluster-api-provider-libvirt/pkg/cloud/libvirt/actuators/machine/actuator_test.go:193
        controller.go:137: missing call(s) to *mock.MockClient.GetDHCPLeasesByNetwork(is anything) /go/src/github.com/openshift/cluster-api-provider-libvirt/pkg/cloud/libvirt/actuators/machine/actuator_test.go:198
        controller.go:137: aborting test due to missing call(s)
    --- FAIL: TestMachineEvents/Delete_machine_event_failed_(error_getting_domain) (0.00s)
        controller.go:137: missing call(s) to *mock.MockClient.GetDHCPLeasesByNetwork(is anything) /go/src/github.com/openshift/cluster-api-provider-libvirt/pkg/cloud/libvirt/actuators/machine/actuator_test.go:198
        controller.go:137: aborting test due to missing call(s)
    --- FAIL: TestMachineEvents/Delete_machine_event_failed_(error_deleting_domain) (0.00s)
        controller.go:137: missing call(s) to *mock.MockClient.GetDHCPLeasesByNetwork(is anything) /go/src/github.com/openshift/cluster-api-provider-libvirt/pkg/cloud/libvirt/actuators/machine/actuator_test.go:198
        controller.go:137: aborting test due to missing call(s)
    --- FAIL: TestMachineEvents/Delete_machine_event_failed_(error_deleting_volume) (0.00s)
        controller.go:137: missing call(s) to *mock.MockClient.GetDHCPLeasesByNetwork(is anything) /go/src/github.com/openshift/cluster-api-provider-libvirt/pkg/cloud/libvirt/actuators/machine/actuator_test.go:198
        controller.go:137: aborting test due to missing call(s)
    --- FAIL: TestMachineEvents/Delete_machine_event_succeeds (0.00s)
        controller.go:137: missing call(s) to *mock.MockClient.GetDHCPLeasesByNetwork(is anything) /go/src/github.com/openshift/cluster-api-provider-libvirt/pkg/cloud/libvirt/actuators/machine/actuator_test.go:198
        controller.go:137: aborting test due to missing call(s) 
praveenkumar added a commit to praveenkumar/cluster-api-provider-libvirt that referenced this issue Feb 3, 2023
Right now after updating to new machine/v1beta and client API looks
like the actuators unit test failing with following error

```
[...]
 --- FAIL: TestMachineEvents (0.03s)
    --- FAIL: TestMachineEvents/Create_machine_event_failed_(invalid_configuration) (0.00s)
        controller.go:137: missing call(s) to *mock.MockClient.Close() /go/src/github.com/openshift/cluster-api-provider-libvirt/pkg/cloud/libvirt/actuators/machine/actuator_test.go:193
        controller.go:137: missing call(s) to *mock.MockClient.GetDHCPLeasesByNetwork(is anything) /go/src/github.com/openshift/cluster-api-provider-libvirt/pkg/cloud/libvirt/actuators/machine/actuator_test.go:198
        controller.go:137: aborting test due to missing call(s)
[...]
```

It need bit more time to figure out why it is failing and what changes
need to be done to fix it or do we need a different way for unit test.

Meanwhile this PR disable those test to make CI happy and take those api
changes in so dependent project doesn't break.

A follow up issue to track: openshift#250
@praveenkumar
Copy link
Contributor Author

I tested #251 with cluster-bot release image and it works, I will also add the nightly or ec bits which have this commit if someone wants to test it

@cfergeau
Copy link
Contributor

cfergeau commented Feb 6, 2023

It's a bug in the unit test which became apparent after upgrading go-mock to its latest version.
The test was missing:

diff --git a/pkg/cloud/libvirt/actuators/machine/actuator_test.go b/pkg/cloud/libvirt/actuators/machine/actuator_test.go
index a0ca8290..7a5771c0 100644
--- a/pkg/cloud/libvirt/actuators/machine/actuator_test.go
+++ b/pkg/cloud/libvirt/actuators/machine/actuator_test.go
@@ -213,6 +213,7 @@ func TestMachineEvents(t *testing.T) {
                        default:
                                t.Errorf("Expected %q event, got none", tc.event)
                        }
+                       mockCtrl.Finish()
                })
        }
 }

It was only seeming to succeed because Finish() was never called. When upgrading go-mock from 1.3.x to 1.6.0, we get this commit golang/mock@6d816de which automatically calls Finish() at the end of the test and makes it obvious that the test is broken.

@cfergeau
Copy link
Contributor

cfergeau commented Feb 6, 2023

diff --git a/pkg/cloud/libvirt/actuators/machine/actuator_test.go b/pkg/cloud/libvirt/actuators/machine/actuator_test.go
index fa89e42e..72502883 100644
--- a/pkg/cloud/libvirt/actuators/machine/actuator_test.go
+++ b/pkg/cloud/libvirt/actuators/machine/actuator_test.go
@@ -190,12 +190,12 @@ func TestMachineEvents(t *testing.T) {
                                },
                        }
 
-                       mockLibvirtClient.EXPECT().Close()
+                       mockLibvirtClient.EXPECT().Close().AnyTimes()
                        mockLibvirtClient.EXPECT().CreateVolume(gomock.Any()).Return(tc.createVolumeErr).AnyTimes()
                        mockLibvirtClient.EXPECT().DeleteVolume(gomock.Any()).Return(tc.deleteVolumeErr).AnyTimes()
                        mockLibvirtClient.EXPECT().CreateDomain(context.TODO(), gomock.Any()).Return(tc.createDomainErr).AnyTimes()
                        mockLibvirtClient.EXPECT().DeleteDomain(gomock.Any()).Return(tc.deleteDomainErr).AnyTimes()
-                       mockLibvirtClient.EXPECT().GetDHCPLeasesByNetwork(gomock.Any())
+                       mockLibvirtClient.EXPECT().GetDHCPLeasesByNetwork(gomock.Any()).AnyTimes()
                        mockLibvirtClient.EXPECT().LookupDomainByName(gomock.Any()).Return(tc.lookupDomainOutput, tc.lookupDomainErr).AnyTimes()
                        mockLibvirtClient.EXPECT().DomainExists(gomock.Any()).Return(tc.domainExists, tc.domainExistsErr).AnyTimes()

This allows the test to succeed but I'm unconvinced it's a great fix, this basically says "the mock interface expects all these methods to be called 0 or more times", this is not testing a lot. These expectations should probably be set per test-case rather than globally.

@openshift-bot
Copy link
Contributor

Issues go stale after 90d of inactivity.

Mark the issue as fresh by commenting /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.
Exclude this issue from closing by commenting /lifecycle frozen.

If this issue is safe to close now please do so with /close.

/lifecycle stale

@openshift-ci openshift-ci bot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label May 8, 2023
@openshift-bot
Copy link
Contributor

Stale issues rot after 30d of inactivity.

Mark the issue as fresh by commenting /remove-lifecycle rotten.
Rotten issues close after an additional 30d of inactivity.
Exclude this issue from closing by commenting /lifecycle frozen.

If this issue is safe to close now please do so with /close.

/lifecycle rotten
/remove-lifecycle stale

@openshift-ci openshift-ci bot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Jun 7, 2023
@openshift-bot
Copy link
Contributor

Rotten issues close after 30d of inactivity.

Reopen the issue by commenting /reopen.
Mark the issue as fresh by commenting /remove-lifecycle rotten.
Exclude this issue from closing again by commenting /lifecycle frozen.

/close

@openshift-ci openshift-ci bot closed this as completed Jul 8, 2023
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Jul 8, 2023

@openshift-bot: Closing this issue.

In response to this:

Rotten issues close after 30d of inactivity.

Reopen the issue by commenting /reopen.
Mark the issue as fresh by commenting /remove-lifecycle rotten.
Exclude this issue from closing again by commenting /lifecycle frozen.

/close

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@praveenkumar
Copy link
Contributor Author

/reopen

This is still not fixed.

@praveenkumar
Copy link
Contributor Author

/lifecycle frozen

@openshift-ci openshift-ci bot added lifecycle/frozen Indicates that an issue or PR should not be auto-closed due to staleness. and removed lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. labels Jul 10, 2023
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Jul 10, 2023

@praveenkumar: Reopened this issue.

In response to this:

/reopen

This is still not fixed.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@openshift-ci openshift-ci bot reopened this Jul 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lifecycle/frozen Indicates that an issue or PR should not be auto-closed due to staleness.
Projects
None yet
Development

No branches or pull requests

3 participants