Skip to content
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

gomonkey 中有异步携程时,mock的方法会失效 #158

Open
zhangbin116 opened this issue Jan 16, 2024 · 3 comments
Open

gomonkey 中有异步携程时,mock的方法会失效 #158

zhangbin116 opened this issue Jan 16, 2024 · 3 comments

Comments

@zhangbin116
Copy link

func methodA(){

...
go methodB()
....
}

gomonkey.ApplyFunctionReturn(methodB) linux环境下,不生效

@someview
Copy link

我也遇到这个问题. 环境: win11, amd64, go1.22, gomonkey v2.11.0

type A struct { ants.Pool}
func(a *A)methodA(){  
    s.Pool.Submit(func(){ a.methodB() })
 }
func(a *A)methodB(){}

在测试时,发现applyPrivateMethod无法生效, 不过applyMethod是生效的。 对于gomonkey的原理完全不了解, 是否可以帮忙看看呢。

@xhd2015
Copy link

xhd2015 commented Apr 26, 2024

我也遇到这个问题. 环境: win11, amd64, go1.22

type A struct { ants.Pool}
func(a *A)methodA(){  
    s.Pool.Submit(func(){ a.methodB() })
 }
func(a *A)methodB(){}

在测试时,发现applyPrivateMethod无法生效。 对于gomonkey的原理完全不了解, 是否可以帮忙看看呢。

Gomonkey的mock并发不安全,可以尝试一下xgo,对比可以参考这里:#157 (comment)

@someview
Copy link

我也遇到这个问题. 环境: win11, amd64, go1.22

type A struct { ants.Pool}
func(a *A)methodA(){  
    s.Pool.Submit(func(){ a.methodB() })
 }
func(a *A)methodB(){}

在测试时,发现applyPrivateMethod无法生效。 对于gomonkey的原理完全不了解, 是否可以帮忙看看呢。

Gomonkey的mock并发不安全,可以尝试一下xgo,对比可以参考这里:#157 (comment)

有时间瞅瞅,不过测试的过程中没有并发的情况,gomonkey也不支持

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants