agiledragon / gomonkey

gomonkey is a library to make monkey patching in unit tests easy
MIT License
1.96k stars 179 forks source link

对协程中调用的函数mock,如何之前的协程做到优雅的退出? #17

Closed chengdanhao closed 4 years ago

chengdanhao commented 4 years ago

gomonkey 是否被多协程并发用于同一个目标的打桩?如果是,则需要将之前的协程先优雅退出;

我A函数goroutine并发调用B函数,B函数中的调用proto.Unmarshal,发现对proto.Unmarshal ApplyFucn 为生效

agiledragon commented 4 years ago

如果多个协程同时对proto.Unmarshal打桩,可能造成覆盖或者瞬间的不一致性。如何将之前的协程优雅退出,可以参考context。

chengdanhao commented 4 years ago

如果多个协程同时对proto.Unmarshal打桩,可能造成覆盖或者瞬间的不一致性。如何将之前的协程优雅退出,可以参考context。

我后面使用time.Sleep方法,来让上一个协程执行完😂