Make Boxes When Your Business Needs Them

Have you ever wanted to make boxes when needed in the office? Are you tired of seeing piles of boxes around the office just waiting to be used? You can solve this issue by utilizing package design…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




The Task of the 5th Week at Summer Internship Nodeflux

My 5th Week is the worst experience so far. This week I got many tasks, almost all of them is easy to solve, the hardest part is to create Retry Function for failed request, also creating the unit test for it.

So, this task is already given from week 4, but at that time I still can not solve them. The problem is mocking the transport layer of Grpc for unit test because when you create a unit test you not allowed to use the real transport layer. The unit test is a part of code, you need to create it when you are coding. So, on my 4th week, I research how to mock the transport Grpc, and none of the solutions is worked. I tried hard to complete this task on week 4. Research — Code — Research — Code — Dead — LOL.

After I through the suffer on week 4th, the suffer brought back to week 5th. Because this task is on my responsibility I have to finish it, but I haven’t found the solution yet till week 4th end. I skip the story about other tasks that I completed in week 5.

The first time I continue the unit test task is on Monday. On this day, I tried to research again about how the transport layer mocked, I found a library on PyPi pytest, the library name is pytest-grpc. I read it again and again but still, I can not get what is this library does and how it works. Even if I tried it I think it won’t work. Then, on Thursday, Because of my doubts, I tried old things that are mocking the object that created or not yet created. My first try is I create mock from an object that not yet created, so I mock it from the module level. Mocking the module that is generated by the Grpc proto is not allowed for method mocking, because the behavior of this module is different as a usual class on python package. The package of generated code Grpc is a unique one. This day is just a trial error in the mocking method from the python module.

On Friday, I try the second one of my mocking action. I try to mock method — method from an object that already created. I tried many times to find the right combination, I mock the first layer of the transport, also I try to mock the method of object credential, object grpc channel (secure channel or the insecure one), also try to mock the ImageAnalyticStub. After the long trial and error process on this day, I found the way to mock the transport layer until it can return the right value.

First, you have to mock the stub object from the module level. So any channel passed to the stub, the stub will work well. Then after this process, you need to mock the method that you want to be able to return your custom value. But it’s can not be done in module level because the module itself doesn’t have the method, the method will create when the object created. So mocking can be done on the object level. After you mock the stub, you have to create the stub object, then use the mocker to mock that object’s method that you wanted. So, this task completed that way.

Happy to end the 5th week by founding the way to mock grpc transport layer.

Add a comment

Related posts:

6 Retail Brands Using Augmented Reality Really Well

We all shop online and sometimes we don’t always get what we expect! Have you ever bought a couch that ended up being WAY too big or just not quite look right in your space? Imagine how many returns…

Bio and Resume

My Name is Aaron price and I’m currently attending Utah Valley University and majoring in Web Development. I’m searching for a company that will assist me in gaining and building experience with Web…

2020 National Youth Leadership Forum on National Security

Peter Starr of Ohio excelled in high school and college as a student and athlete, playing football, basketball, golf, and tennis. While in college, Ohio’s Peter Starr, a criminal justice major…