Corecfg tests crash with weird pthread bug when invoked with -count 1000

So on master I see this:

zyga@fyke:~/go/src/github.com/snapcore/snapd/corecfg$ go test -count 1000
...
----------------------------------------------------------------------
FAIL: corecfg_test.go:46: coreCfgSuite.TestConfigureErrorOnMissingCoreSupport

corecfg_test.go:57:
    c.Check(err, ErrorMatches, `(?m)cannot run systemctl - core-support interface seems disconnected: \[--version\] failed with exit status 1: simulate missing core-support`)
... error string = "cannot run snapctl: snapctl: error while loading shared libraries: libpthread.so.0: cannot open shared object file: No such file or directory"
... regex string = "(?m)cannot run systemctl - core-support interface seems disconnected: \\[--version\\] failed with exit status 1: simulate missing core-support"

Note the part that says libpthread.so.0 which feels like another golang exec/fork bug. That test is essentially running this:

exec.Command("systemctl", "--version")

So this is more interesting as we dig deeper:

I made https://github.com/zyga/snapd/tree/wtf/weird-bug

14:34 < zyga-ubuntu> Chipaca: inside that branch run
14:34 < zyga-ubuntu> zyga@fyke:~/go/src/github.com/snapcore/snapd/corecfg$ go test
14:34 < zyga-ubuntu> and compare that to
14:34 < zyga-ubuntu> zyga@fyke:~/go/src/github.com/snapcore/snapd/corecfg$ go test -count 1000
14:34 < zyga-ubuntu> that shows the issue

It looks like the first mock of systemctl is not really happening at that time and sometimes we run the real thing that subsequently runs snapctl. The pthread message was supposedly coming from snapctl but I don’t have a proof for this.