You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The test case testIsTaskCurrent is testing the supervisor.isTaskCurrent() with 4 different scenarios (taskFromStorage, taskFromStorageMismatchedDataSchema,taskFromStorageMismatchedTuningConfig,taskFromStorageMismatchedPartitionsWithTaskGroup) in one single test case. In my humble opinion, it could be beneficial to separate the four scenarios into four individual test cases. Each test case will focus on one scenario.
The original test case is 156 lines, and after the refactoring, each test case will be around 30 lines.
For example, when testing the supervisor.isTaskCurrent() with taskFromStorage, the new case will only contain the supervisor and the taskFromStorage related variable/mock setup, and will have only one assert statement. Here is how the refactored test case for taskFromStorage scenario looks like:
DateTimeminMessageTime = DateTimes.nowUtc();
DateTimemaxMessageTime = DateTimes.nowUtc().plus(10000);
KinesisSupervisorsupervisor = getSupervisor(...);
KinesisIndexTasktaskFromStorage = createKinesisIndexTask("id1", ...) // omitted some parameters to save the spaceEasyMock.expect(taskStorage.getTask("id1"))
.andReturn(Optional.of(taskFromStorage))
.once();
replay();
Assert.assertTrue(supervisor.isTaskCurrent(42, "id1"));
verify();
Please see the detailed description of my proposed change below.
Proposed changes
testIsTaskCurrent case is aiming to test the isTaskCurrent function with Easymock. And the four scenarios are quite independent of each other, I suggest to :
Extract the arrangements shared across multiple scenarios into a setup function for the test case:
The arrangement from line 3886 to line 3911 can be extracted as a function named as isCurrentSupervisorSetup().
Extract the 4 test scenarios with their specific arrangements into 4 separate unit tests:
Use the isCurrentSupervisorSetup() in the 4 test cases for common setup.
Replace the EasyMock.replayAll() and EasyMock.verifyAll() functions in the original case with EasyMock.replay() and EasyMock.verify(), and put them into each of 4 test ceases.
After this refactoring, all the test scenarios will belong to one unit test case and can be evaluated in one cycle of testing.
Hope this proposal can be helpful, and if possible, I would be more than happy to try the refactoring. (If not, comments are still appreciated.)
The text was updated successfully, but these errors were encountered:
@Codegass - changes sound good to me. It will be great if you can create a PR.
Codegass
changed the title
Refactor the testDedup test case to improve the test experience
Refactor the testIsTaskCurrent test case to improve the test experience
May 6, 2022
This issue has been marked as stale due to 280 days of inactivity.
It will be closed in 4 weeks if no further activity occurs. If this issue is still
relevant, please simply write any comment. Even if closed, you can still revive the
issue at any time or discuss it on the dev@druid.apache.org list.
Thank you for your contributions.
This issue has been marked as stale due to 280 days of inactivity.
It will be closed in 4 weeks if no further activity occurs. If this issue is still
relevant, please simply write any comment. Even if closed, you can still revive the
issue at any time or discuss it on the dev@druid.apache.org list.
Thank you for your contributions.
Description & Motivation
The test case testIsTaskCurrent is testing the
supervisor.isTaskCurrent()
with 4 different scenarios (taskFromStorage
,taskFromStorageMismatchedDataSchema
,taskFromStorageMismatchedTuningConfig
,taskFromStorageMismatchedPartitionsWithTaskGroup
) in one single test case. In my humble opinion, it could be beneficial to separate the four scenarios into four individual test cases. Each test case will focus on one scenario.The original test case is 156 lines, and after the refactoring, each test case will be around 30 lines.
For example, when testing the
supervisor.isTaskCurrent()
withtaskFromStorage
, the new case will only contain thesupervisor
and thetaskFromStorage
related variable/mock setup, and will have only one assert statement. Here is how the refactored test case fortaskFromStorage
scenario looks like:Please see the detailed description of my proposed change below.
Proposed changes
testIsTaskCurrent case is aiming to test the
isTaskCurrent
function with Easymock. And the four scenarios are quite independent of each other, I suggest to :isCurrentSupervisorSetup()
.testIsTaskCurrentTaskFromStorage
unit test case with the mock setup(line 4021-4023) and isTaskCurrent assertion functions(line 4036) for the first testing scenario.testIsTaskCurrentTaskFromStorageMismatchedDataSchema
unit test case with the mock setup(line 4024-4026) and isTaskCurrent assertion functions(line 4037) for the second testing scenario.testIsTaskCurrentTaskFromStorageMismatchedTuningConfig
unit test case with the mock setup(line 4027-4029) and isTaskCurrent assertion functions(line 4038) for the third testing scenario.testIsTaskCurrentTaskFromStorageMismatchedPartitionsWithTaskGroup
unit test case with the mock setup(line 4030-4032) and isTaskCurrent assertion functions(line 4038) for the fourth testing scenario.isCurrentSupervisorSetup()
in the 4 test cases for common setup.EasyMock.replayAll()
andEasyMock.verifyAll()
functions in the original case withEasyMock.replay()
andEasyMock.verify()
, and put them into each of 4 test ceases.After this refactoring, all the test scenarios will belong to one unit test case and can be evaluated in one cycle of testing.
Hope this proposal can be helpful, and if possible, I would be more than happy to try the refactoring. (If not, comments are still appreciated.)
The text was updated successfully, but these errors were encountered: