-
Notifications
You must be signed in to change notification settings - Fork 706
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: failing backend-unit-tests #4285
Conversation
Signed-off-by: SohamRatnaparkhi <[email protected]>
Signed-off-by: SohamRatnaparkhi <[email protected]>
Signed-off-by: SohamRatnaparkhi <[email protected]>
chartserviceversion YAML files. Signed-off-by: SohamRatnaparkhi <[email protected]>
Signed-off-by: SohamRatnaparkhi <[email protected]>
Signed-off-by: SohamRatnaparkhi <[email protected]>
Signed-off-by: SohamRatnaparkhi <[email protected]>
Signed-off-by: SohamRatnaparkhi <[email protected]>
There is a strange thing about the 2 failing test-cases of |
@amityt Can you check this please! |
Still failed. Can you PTAL @SohamRatnaparkhi ? |
Hi @namkyu1999
But strangely, they are passing in my local dev environment. I have attached its screenshot above. I'm currently trying to debug the reason for same. |
Signed-off-by: SohamRatnaparkhi <[email protected]>
42d5815
to
3651244
Compare
Signed-off-by: SohamRatnaparkhi <[email protected]>
Finally, all the test-cases passing! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you confirm my comments?
@@ -281,7 +281,7 @@ func TestGetChartsData(t *testing.T) { | |||
name: "success: url is valid", | |||
projectID: uuid.New().String(), | |||
repoData: model.CloningInput{ | |||
Name: uuid.New().String(), | |||
Name: "container-kill", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you change this line? IMO, It's not relevant to your PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, that's true. The issue was causing the chaos-hub tests to fail because the generated UUID was unique every time, resulting in the file being absent and triggering an error, indicating 'file not found'
succeedProjectID := "project-1" | ||
succeedName := "workflow-hub-1" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can kindoff refine the names and stuff, but we will require a defined file system to pass the tests.
Same reason as above.
@@ -694,7 +694,7 @@ func TestChaosExperimentHandler_DisableCronExperiment(t *testing.T) { | |||
given: func() { | |||
chaosExperimentService.On("ProcessExperimentUpdate", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(errors.New("error while updating")).Once() | |||
}, | |||
wantErr: true, | |||
wantErr: false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
name: "Failure: mongo error while updating the experiment details",
This test case should be failed. we need to keep wantErr: true
. IMO we need to change our test code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep that's true.
Actually the test code returns an error as when it is run individually (which is the expected result).
But when run collectively, for some weird reason, the update experiment service returns null error which fails the tc because returned error is null but it expects an error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since it is a unit test, it is correct that the test should pass when run individually.
The reason this happens is that in the case of chaos hub, we have code to download a file or check for the existence of a file, but other test code has already downloaded the file.
If you can't fix it now, I suggest commenting it out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay cool!
I'll do it.
@@ -463,7 +463,7 @@ func TestChaosExperimentHandler_UpdateChaosExperiment(t *testing.T) { | |||
|
|||
chaosExperimentService.On("ProcessExperimentUpdate", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(errors.New("experiment update failed")).Once() | |||
}, | |||
wantErr: true, | |||
wantErr: false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
name: "Update failed",
This test case should be failed. we need to keep wantErr: true. IMO we need to change our test code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep. The same reason as above, as there is some issue in the ProcessExperimentUpdate
service IG.
Currently, I am unable to solve it. Where should we update the current code?
Thank you!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tried to fix in my PR #4372, reason why tests were passing when ran individually but failing when ran all together is because of the global mocks. Some tests are setting expectations but those expectations weren't met. If we had AssertExpectations it would have highlighted the problem. As a best practice we should avoid having global mocks to avoid cases where one test leaves side-effects causing other tests to fail.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another way to debug issues why mocks aren't working as expected is by inspecting ExpectedCalls on the mock object. You can either print the ExpectedCalls before every test is run or set breakpoints using runtime.Breakpoint() and debug using dlv https://github.com/go-delve/delve
@@ -23,7 +23,7 @@ import ( | |||
"gopkg.in/yaml.v2" | |||
) | |||
|
|||
const DefaultPath = "/tmp/" | |||
const DefaultPath = "./tmp/" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain why you changed this code, please?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed. The issue stemmed from the tmp/ directory going unnoticed; the code couldn't locate it.
While one solution could be adding a tmp directory in the root, it seemed irrelevant for the rest of the code.
Consequently, I opted to update it to ./tmp, making it relative to the chaos-hub directory.
Would love to discuss on this as I am not sure how apt the solution is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wouldn't recommend changing production code that's currently working well just to make our test code pass. We don't inspect the potential side effects that could occur on that code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, that's true.
So should we close this PR and then, I'll comment out the failing test in a new PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can complete this in the current PR. I will create a new pull request to address the failing test cases(commented test cases).
Unit tests are now fixed, closing this PR. |
Proposed changes
chaos-experiments
andchaos-experiment-runs
TestGetClonePath
,TestListPredefinedWorkflowDetails
andTestGetChartsData
tmp
folder. (The tmp folder is required to pass certain test cases.). Then after adding thetmp
folder, re-added thetmp
folder to .gitignoreTypes of changes
What types of changes does your code introduce to Litmus? Put an
x
in the boxes that applyChecklist
Put an
x
in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.Dependency
nil
Special notes for your reviewer:
tmp
folder from the.gitignore
might not be the best solution because whenever the test is run locally, the chart repo will be cloned. I had commented thetmp
folder because at least one tmp folder needs to be present in choashub folder to pass the tests.tmp
to.\tmp
was required, as code was unable to find the\tmp
path/directory