-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
test: add property based tests to DataBus #140
Comments
This is an interesting question. I try to complete this task. Here I will talk about my explore journey. About Property Based TestingWhen I was in college, I encountered the technology of Property Based Testing. The teacher who teaches the C language course will leave a But this is just a technology, we also need to apply this technology to the current project. About DatabusThe task requires the enhanced test of DataBus, so what is DataBus? This problem is very important, because we need to test according to the specific situation of the business, we need to understand the role of DataBus in the entire project architecture. After research on the source code, I will directly conclude here. What happens when I click the plus button in the figure below? It will send the data format in the figure below by WebSocket to the backend-server, We can see a CMD field to mark our movement just now. In this case, there is a place in the backend-server of the system to accept this packet. We can find it here by tracking the code. apitable/packages/room-server/src/grpc/controllers/grpc.controller.ts Lines 106 to 126 in 1971945
If we follow all the way, we will find that the code of the client's instruction processing is finally saved to the code of the database: apitable/packages/room-server/src/database/ot/services/datasheet.ot.service.ts Lines 1229 to 1291 in 1971945
In this code call stack, there is no DataBus. Where is the role of DataBus? We open the API pop -up window above and find the column of the add record. We can see here to indicate that we requested an interface from the backend-server The code in response to this interface is here: apitable/packages/room-server/src/fusion/fusion.api.controller.ts Lines 261 to 285 in 1971945
If we continue from here, we can find the code to execute the command here: apitable/packages/core/src/databus/datasheet.ts Lines 97 to 114 in 1971945
Seeing this bold assumption, earlier, without API calls, the instructions of various operations and collaborations on the table in How to complete the task?In fact, there are two main tasks. For the first task, the apitable/packages/core/src/commands/index.ts Lines 172 to 222 in 1971945
It seems that it is difficult for us to automatically generate commands by In this case, we need to write a test script about For the second task, just test the It is also necessary to pay attention to the asynchronous and concurrency in the test process, which will cause difficulty in verifying the self -increase. I will try to submit a PR later. If I understand errors in some places, please help me point out and be grateful. |
Submit a pull request for this project. <!-- If you have an Issue that related to this Pull Request, you can copy this Issue's description --> # Why? <!-- > Related to which issue? > Why we need this pull request? > What is the user story for this pull request? --> For the issue #140 Use `fast-check.js` to simply test the two commands of DataBus to test whether the test quality of DataBus can be improved. # What? <!-- > Can you describe this feature in detail? > Who can benefit from it? --> I modified the `SaveOps` logic of `MockDataLoadersaver`. At the same time, a test script is added. If the test code is valid, we can expand the test of `DataBus` on the basis of this. To explain, the old [pull request](#454) was closed because I accidentally deleted the code branch, so now I created a new pull request. Co-authored-by: Kelly Chan <kelly@apitable.com>
I have an idea for this project.
Why?
Property based testing is a testing technique that makes sure the inherent properties of the tested object always hold. Currently there are little guarantee that objects in DataBus satisfy their inherent properties, so property based testing can be added to improve the robustness of DataBus.
What?
Add property based tests to DataBus that test the following properties:
doCommand
operation,revision
of aDatasheet
is always increased by one.id
,name
, andtype
field of theDatasheet
are not changed.Datasheet
through thedoCommand
operation,Datasheet
and allView
s is always increased by one.How?
The simple way is to conceive some example data and add them to
jest
tests. Even better, you can usefast-check
to generate random tests.The text was updated successfully, but these errors were encountered: