-3

I am using the testify package for the unit testing in golang. My code contains mocking. while running the test it is getting passed for sometimes and showing error The code you are testing needs to make 1 more call(s) for sometimes, I am unable to figure out the reason why is this happening:

enter image description here

I went through this https://github.com/stretchr/testify/issues/31 but did get what is the problem and how it can be solved?

4

1 回答 1

0

I read about the goroutine scheduling and come to know that if you are writing the test for the go functions(goroutines) then sometimes they may be called (the case when the test will pass and) and sometimes they may not be called.(the case when the test will fail). To recover from this one should use Gosched() in the test file where we are calling the goroutine. This happens because go uses cooperative scheduling for the scheduling for the goroutines, which is different from preemptive and non-preemptive. If anyone wants to more about it follow this. https://github.com/golang/go/issues/11462

于 2017-12-07T13:22:33.377 回答