matryer / moq

Interface mocking tool for go generate
http://bit.ly/meetmoq
MIT License
2k stars 127 forks source link

Moq hangs #39

Closed djui closed 4 years ago

djui commented 6 years ago

Example 1: GOROOT

$ moq $(go env GOROOT)/src/database/sql/driver Driver
^\SIGQUIT: quit
PC=0x105415b m=0 sigcode=0

goroutine 0 [idle]:
runtime.mach_semaphore_wait(0xa03, 0x0, 0xc42022c800, 0x7ffeefbff3a0, 0x101efb8, 0x1409be0, 0x7ffeefbff3b8, 0x104e9a3, 0xffffffffffffffff, 0x101c0b1, ...)
    /usr/local/Cellar/go/1.10beta1/libexec/src/runtime/sys_darwin_amd64.s:542 +0xb
runtime.semasleep1(0xffffffffffffffff, 0x101c0b1)
    /usr/local/Cellar/go/1.10beta1/libexec/src/runtime/os_darwin.go:417 +0x52
runtime.semasleep.func1()
    /usr/local/Cellar/go/1.10beta1/libexec/src/runtime/os_darwin.go:436 +0x33
runtime.semasleep(0xffffffffffffffff, 0xc420031270)
    /usr/local/Cellar/go/1.10beta1/libexec/src/runtime/os_darwin.go:435 +0x44
runtime.notesleep(0x140a228)
    /usr/local/Cellar/go/1.10beta1/libexec/src/runtime/lock_sema.go:167 +0xe9
runtime.stopm()
    /usr/local/Cellar/go/1.10beta1/libexec/src/runtime/proc.go:1947 +0xe5
runtime.findrunnable(0xc42002d900, 0x0)
    /usr/local/Cellar/go/1.10beta1/libexec/src/runtime/proc.go:2404 +0x4fa
runtime.schedule()
    /usr/local/Cellar/go/1.10beta1/libexec/src/runtime/proc.go:2530 +0x13b
runtime.park_m(0xc420001980)
    /usr/local/Cellar/go/1.10beta1/libexec/src/runtime/proc.go:2593 +0xb6
runtime.mcall(0x0)
    /usr/local/Cellar/go/1.10beta1/libexec/src/runtime/asm_amd64.s:351 +0x5b

goroutine 1 [runnable]:
syscall.Syscall(0x152, 0xc420196030, 0xc420198038, 0x0, 0xffffffffffffffff, 0x0, 0x2)
    /usr/local/Cellar/go/1.10beta1/libexec/src/syscall/asm_darwin_amd64.s:16 +0x5
syscall.Stat(0xc420196020, 0xb, 0xc420198038, 0xb, 0xc420196020)
    /usr/local/Cellar/go/1.10beta1/libexec/src/syscall/zsyscall_darwin_amd64.go:1192 +0x97
os.Stat(0xc420196020, 0xb, 0xc420196020, 0xb, 0x0, 0x0)
    /usr/local/Cellar/go/1.10beta1/libexec/src/os/stat_unix.go:32 +0x5c
github.com/matryer/moq/pkg/moq.vendorPath(0x7ffeefbff7f4, 0x1, 0xc42001a3d7, 0x3, 0xc42012b110, 0x12aa2a3, 0xe)
    /Users/uwe/dev/go/src/github.com/matryer/moq/pkg/moq/importer.go:79 +0x17b
github.com/matryer/moq/pkg/moq.gopathDir(0x7ffeefbff7f4, 0x3e, 0xc42001a3d7, 0x3, 0xc42012b1d8, 0x104b663, 0x125e8e0, 0x3aac0)
    /Users/uwe/dev/go/src/github.com/matryer/moq/pkg/moq/importer.go:49 +0x82
github.com/matryer/moq/pkg/moq.(*customImporter).fsPkg(0xc420133e30, 0xc42001a3d7, 0x3, 0x3, 0x1427640, 0x10d2d00)
    /Users/uwe/dev/go/src/github.com/matryer/moq/pkg/moq/importer.go:107 +0x73
github.com/matryer/moq/pkg/moq.(*customImporter).Import(0xc420133e30, 0xc42001a3d7, 0x3, 0x0, 0x0, 0xc42012b300)
    /Users/uwe/dev/go/src/github.com/matryer/moq/pkg/moq/importer.go:39 +0xe4
go/types.(*Checker).importPackage(0xc420160000, 0xbb, 0xc42001a3d7, 0x3, 0xc420016320, 0x3e, 0x9)
    /usr/local/Cellar/go/1.10beta1/libexec/src/go/types/resolver.go:162 +0x63e
go/types.(*Checker).collectObjects(0xc420160000)
    /usr/local/Cellar/go/1.10beta1/libexec/src/go/types/resolver.go:256 +0x10de
go/types.(*Checker).checkFiles(0xc420160000, 0xc42012e630, 0x2, 0x2, 0x0, 0x0)
    /usr/local/Cellar/go/1.10beta1/libexec/src/go/types/check.go:237 +0x97
go/types.(*Checker).Files(0xc420160000, 0xc42012e630, 0x2, 0x2, 0xc420136b40, 0x1218eb7)
    /usr/local/Cellar/go/1.10beta1/libexec/src/go/types/check.go:230 +0x49
go/types.(*Config).Check(0xc42013e4c0, 0x7ffeefbff7f4, 0x3e, 0xc420020380, 0xc42012e630, 0x2, 0x2, 0x0, 0x110a23f, 0xc42012bbb8, ...)
    /usr/local/Cellar/go/1.10beta1/libexec/src/go/types/api.go:351 +0x12f
github.com/matryer/moq/pkg/moq.(*Mocker).Mock(0xc42013e480, 0x12db200, 0xc42000c018, 0xc42000e1d0, 0x1, 0x1, 0x0, 0x1006dfd)
    /Users/uwe/dev/go/src/github.com/matryer/moq/pkg/moq/moq.go:126 +0x264
main.main()
    /Users/uwe/dev/go/src/github.com/matryer/moq/main.go:51 +0x2b0

rax    0xe
rbx    0x140a0e0
rcx    0x7ffeefbff358
rdx    0x7ffeefbff3d8
rdi    0xa03
rsi    0x1
rbp    0x7ffeefbff390
rsp    0x7ffeefbff358
r8     0x0
r9     0xa
r10    0x3bb89a3a
r11    0x286
r12    0xcb2f76cfe19a
r13    0x0
r14    0x1051940
r15    0x0
rip    0x105415b
rflags 0x286
cs     0x7
fs     0x0
gs     0x0

Example 2: Symlinks

Many Go tools have a problem with running them from a symlinked directory (and also e.g. dep). These sometimes tell the user what's wrong. moq also has a problem with this condition but then instead just busy loops:

$ pwd
/Users/uwe/dev/company/pkg

$ moq -out t_mock_test.go vendor/github.com/stretchr/testify/require TestingT
# Hanging (dump forced with `Ctrl-\`)
^\SIGQUIT: quit
PC=0x105415b m=0 sigcode=0

goroutine 0 [idle]:
runtime.mach_semaphore_wait(0x1303, 0x0, 0xc420373000, 0x7ffeefbff3a0, 0x101efb8, 0x1409be0, 0x7ffeefbff3b8, 0x104e9a3, 0xffffffffffffffff, 0x101c0b1, ...)
    /usr/local/Cellar/go/1.10beta1/libexec/src/runtime/sys_darwin_amd64.s:542 +0xb
runtime.semasleep1(0xffffffffffffffff, 0x101c0b1)
    /usr/local/Cellar/go/1.10beta1/libexec/src/runtime/os_darwin.go:417 +0x52
runtime.semasleep.func1()
    /usr/local/Cellar/go/1.10beta1/libexec/src/runtime/os_darwin.go:436 +0x33
runtime.semasleep(0xffffffffffffffff, 0xc42002a170)
    /usr/local/Cellar/go/1.10beta1/libexec/src/runtime/os_darwin.go:435 +0x44
runtime.notesleep(0x140a228)
    /usr/local/Cellar/go/1.10beta1/libexec/src/runtime/lock_sema.go:167 +0xe9
runtime.stopm()
    /usr/local/Cellar/go/1.10beta1/libexec/src/runtime/proc.go:1947 +0xe5
runtime.findrunnable(0xc42002b400, 0x0)
    /usr/local/Cellar/go/1.10beta1/libexec/src/runtime/proc.go:2404 +0x4fa
runtime.schedule()
    /usr/local/Cellar/go/1.10beta1/libexec/src/runtime/proc.go:2530 +0x13b
runtime.park_m(0xc420188a80)
    /usr/local/Cellar/go/1.10beta1/libexec/src/runtime/proc.go:2593 +0xb6
runtime.mcall(0x0)
    /usr/local/Cellar/go/1.10beta1/libexec/src/runtime/asm_amd64.s:351 +0x5b

goroutine 1 [runnable]:
path.(*lazybuf).string(...)
    /usr/local/Cellar/go/1.10beta1/libexec/src/path/path.go:52
path.Clean(0xc42058dce0, 0x11, 0x3, 0x12a7bb5)
    /usr/local/Cellar/go/1.10beta1/libexec/src/path/path.go:139 +0x761
path.Join(0xc4201426a0, 0x3, 0x3, 0x1, 0x0)
    /usr/local/Cellar/go/1.10beta1/libexec/src/path/path.go:158 +0xa4
github.com/matryer/moq/pkg/moq.vendorPath(0xc4201ecf50, 0x1, 0xc4201600a1, 0x8, 0xc4201427a0, 0x100fa29, 0xc42021d840)
    /Users/uwe/dev/go/src/github.com/matryer/moq/pkg/moq/importer.go:75 +0x141
github.com/matryer/moq/pkg/moq.gopathDir(0x7ffeefbff820, 0x2a, 0xc4201600a1, 0x8, 0xc420170448, 0xc420142850, 0x10d56e1, 0xc420170420)
    /Users/uwe/dev/go/src/github.com/matryer/moq/pkg/moq/importer.go:49 +0x82
github.com/matryer/moq/pkg/moq.(*customImporter).fsPkg(0xc4201546f0, 0xc4201600a1, 0x8, 0x8, 0x1427640, 0x10d2d00)
    /Users/uwe/dev/go/src/github.com/matryer/moq/pkg/moq/importer.go:107 +0x73
github.com/matryer/moq/pkg/moq.(*customImporter).Import(0xc4201546f0, 0xc4201600a1, 0x8, 0x0, 0x0, 0xc420142a00)
    /Users/uwe/dev/go/src/github.com/matryer/moq/pkg/moq/importer.go:39 +0xe4
go/types.(*Checker).importPackage(0xc42016e0e0, 0x98, 0xc4201600a1, 0x8, 0xc420178780, 0x43, 0x9)
    /usr/local/Cellar/go/1.10beta1/libexec/src/go/types/resolver.go:162 +0x63e
go/types.(*Checker).collectObjects(0xc42016e0e0)
    /usr/local/Cellar/go/1.10beta1/libexec/src/go/types/resolver.go:256 +0x10de
go/types.(*Checker).checkFiles(0xc42016e0e0, 0xc420201fc0, 0x6, 0x8, 0x0, 0x0)
    /usr/local/Cellar/go/1.10beta1/libexec/src/go/types/check.go:237 +0x97
go/types.(*Checker).Files(0xc42016e0e0, 0xc420201fc0, 0x6, 0x8, 0xc420213540, 0xc420143180)
    /usr/local/Cellar/go/1.10beta1/libexec/src/go/types/check.go:230 +0x49
go/types.(*Config).Check(0xc42021d900, 0xc4200182d1, 0x22, 0xc42015c200, 0xc420201fc0, 0x6, 0x8, 0x0, 0x0, 0xc420143288, ...)
    /usr/local/Cellar/go/1.10beta1/libexec/src/go/types/api.go:351 +0x12f
github.com/matryer/moq/pkg/moq.(*customImporter).fsPkg(0xc4201546f0, 0xc4200182d1, 0x22, 0x22, 0x1427640, 0x10d2d00)
    /Users/uwe/dev/go/src/github.com/matryer/moq/pkg/moq/importer.go:144 +0x5cd
github.com/matryer/moq/pkg/moq.(*customImporter).Import(0xc4201546f0, 0xc4200182d1, 0x22, 0x0, 0x0, 0xc420143300)
    /Users/uwe/dev/go/src/github.com/matryer/moq/pkg/moq/importer.go:39 +0xe4
go/types.(*Checker).importPackage(0xc42016e000, 0x66e, 0xc4200182d1, 0x22, 0xc420014880, 0x2a, 0x9)
    /usr/local/Cellar/go/1.10beta1/libexec/src/go/types/resolver.go:162 +0x63e
go/types.(*Checker).collectObjects(0xc42016e000)
    /usr/local/Cellar/go/1.10beta1/libexec/src/go/types/resolver.go:256 +0x10de
go/types.(*Checker).checkFiles(0xc42016e000, 0xc420154660, 0x5, 0x5, 0x0, 0x0)
    /usr/local/Cellar/go/1.10beta1/libexec/src/go/types/check.go:237 +0x97
go/types.(*Checker).Files(0xc42016e000, 0xc420154660, 0x5, 0x5, 0xc4201522d0, 0x1218eb7)
    /usr/local/Cellar/go/1.10beta1/libexec/src/go/types/check.go:230 +0x49
go/types.(*Config).Check(0xc42015c180, 0x7ffeefbff820, 0x2a, 0xc420020380, 0xc420154660, 0x5, 0x5, 0x0, 0x110a23f, 0xc420143bb8, ...)
    /usr/local/Cellar/go/1.10beta1/libexec/src/go/types/api.go:351 +0x12f
github.com/matryer/moq/pkg/moq.(*Mocker).Mock(0xc42015c140, 0x12daf60, 0xc4200c4230, 0xc42000e180, 0x1, 0x1, 0x0, 0x1006dfd)
    /Users/uwe/dev/go/src/github.com/matryer/moq/pkg/moq/moq.go:126 +0x264
main.main()
    /Users/uwe/dev/go/src/github.com/matryer/moq/main.go:51 +0x2b0

rax    0xe
rbx    0x140a0e0
rcx    0x7ffeefbff358
rdx    0x7ffeefbff3d8
rdi    0x1303
rsi    0x1
rbp    0x7ffeefbff390
rsp    0x7ffeefbff358
r8     0x0
r9     0x1409fa8
r10    0xa
r11    0x286
r12    0xb1c5323bbc08
r13    0x3
r14    0x2
r15    0x100
rip    0x105415b
rflags 0x286
cs     0x7
fs     0x0
gs     0x0

Same from actual directory:

$ pwd
/Users/uwe/dev/company/pkg

$ cd -P .

$ pwd
/Users/uwe/dev/go/src/github.com/company/pkg

$ moq -out t_mock_test.go vendor/github.com/stretchr/testify/require TestingT

$
svperfecta commented 6 years ago

@djui I'm having the first hang you mentioned. I'm not sure what the reason is, however. What specifically is wrong with GOROOT that makes this happen?

djui commented 6 years ago

@genexp We have forked the repo and done extensive modifications including the import loader. Since then I haven’t encountered that issue anymore. You might want to give the fork a try: https://github.com/betalo-sweden/moq

sudo-suhas commented 4 years ago

I tried running moq $(go env GOROOT)/src/database/sql/driver Driver and it worked correctly with the latest version of moq. Comment if you are still facing this issue.